Make it the default browser

202 views
Skip to first unread message

Thiemo Melhorn

unread,
Jan 27, 2023, 12:52:33 AMJan 27
to DroidScript
How to change the default browser by button? Because I want my web browser to have this feature too and that everything is displayed in my browser.

Jumar

unread,
Jan 27, 2023, 3:19:51 AMJan 27
to DroidScript
Hi Thiemo

Browsing online, I found this as part of Manifest.xml file to enable your app to be recognized as a Browser by the Android system and can be set on `Default Browser` in your phone's settings.

<intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.BROWSABLE" />
     <data android:scheme="http" />
     <data android:scheme="https" />
</intent-filter>

If you can convert it into json to be added on the `build.json` file of your DS app, maybe it can solve your query.

Regards
Jumar

PS. I don't really sure if the manifest statements is correct because I just search it online.

Thiemo Melhorn

unread,
Jan 27, 2023, 4:58:17 AMJan 27
to DroidScript
2023_01_27_10.55.57.jpg

Right2TheV0id

unread,
Jan 27, 2023, 10:54:00 AMJan 27
to DroidScript
This is not how build.json works.
You can find informations about this file in the official doc: https://symdstools.github.io/Docs/docs/intro/07FileStructure.htm

Le vendredi 27 janvier 2023 à 10:58:17 UTC+1, Thiemo Melhorn a écrit :
2023_01_27_10.55.57.jpg

Alan Hendry

unread,
Jan 28, 2023, 3:06:37 PMJan 28
to DroidScript
Hi,
build.json has to be in JSON format,
This is an example, I think the path pattern means that when the app has been built (APK or AAB) and installed then when the user opens PNG or jpg  files then the user can choose to use this app to open it.

{
    "manifest":
    {
        "minSdkVersion": 23,
        "targetSdkVersion": 28,
        "debuggable": false,
        "removePermissions": "WRITE\_EXTERNAL\_STORAGE",
        "homeScreen": false,
        "noPermsAction": "default",
        "pathPattern": ".*\.png,.*\.jpg"
    },
    "autoPermissions": true
}

Regards, ah

Thiemo Melhorn

unread,
Jan 29, 2023, 2:28:23 AMJan 29
to DroidScript
The same error appears again.

Thiemo Melhorn

unread,
Jan 29, 2023, 2:43:01 AMJan 29
to DroidScript
However, once I run the APK, it works without any problems.

Thiemo Melhorn

unread,
Jan 29, 2023, 9:18:36 AMJan 29
to DroidScript
Is the browser now displayed as the default web browser with Alan's code?

Alan Hendry

unread,
Jan 29, 2023, 12:58:38 PMJan 29
to DroidScript

HI,
On second thought this technique means that when the user tries to open a .htm file 
then the user would be given the choice of opening the file with this app 
(the json would need to be changed to .htm and.html).
There may be an intent that will open the correct settings page 
for the user to change the default app for browsing the web (may not be relevant on some versions of Android)
Regards, ah

Thiemo Melhorn

unread,
Jan 29, 2023, 3:46:24 PMJan 29
to DroidScript
Thanks to a tutorial - the tutorial is available in the tutorials in DS - I have not found anything about my project but about the dialog box.

//Called when application is started.
function OnStart()
{
 //Create a layout with objects vertically centered.
 lay = app.CreateLayout( "linear", "VCenter,FillXY" )
 //Create image.
 img = app.CreateImage( "/Sys/Img/Hello.png", 0.1 )
 lay.AddChild( img )
 //Create a 'Send File' button
 btnSend = app.CreateButton( "Send File to another App", 0.8 )
 btnSend.SetMargins( 0, 0.05, 0, 0 )
 btnSend.SetOnTouch( btnSend_OnTouch )
 lay.AddChild( btnSend )
 //Create a 'Send Image' button
 btnImg = app.CreateButton( "Send Image to Google Drive", 0.8 )
 btnImg.SetMargins( 0, 0.05, 0, 0 )
 btnImg.SetOnTouch( btnImg_OnTouch )
 lay.AddChild( btnImg )
 //Create a 'Send Text' button
 btnTxt = app.CreateButton( "Send Text to Google Drive", 0.8 )
 btnTxt.SetMargins( 0, 0.05, 0, 0 )
 btnTxt.SetOnTouch( btnTxt_OnTouch )
 lay.AddChild( btnTxt )
 //Add layout to app.
 app.AddLayout( lay )
}
//Send a file to another App (user's choice).
function btnSend_OnTouch()
{
    var file = "/sdcard/sftest.txt";
    app.WriteFile( file, "Hello World" )
 app.SendFile( file, "sftest.txt", "Send File" )
}
//Send an image to Google Drive.
function btnImg_OnTouch()
{
    var file = "/sdcard/MyDroid.jpg";
    img.Save( file )
    var packageName = "com.google.android.apps.docs";
    var className = "com.google.android.apps.docs.shareitem.UploadSharedItemActivity";
    var action = "android.intent.action.SEND";
    var category = "android.intent.category.DEFAULT"
    var uri = null;
    var type = "multipart/*";
    var extras = [
        {name:"android.intent.extra.STREAM", type:"file", value:file},
        {name:"android.intent.extra.SUBJECT", type:"string", value:"MyDroid.jpg"},
    ];
    extras = JSON.stringify( extras )
    app.SendIntent(packageName, className, action, category, uri, type, extras)
}
//Send text to Google Drive.
function btnTxt_OnTouch()
{
    var textData = "The cat sat on the mat";
    var packageName = "com.google.android.apps.docs";
    var className = "com.google.android.apps.docs.shareitem.UploadSharedItemActivity";
    var action = "android.intent.action.SEND";
    var category = "android.intent.category.DEFAULT"
    var uri = null;
    var type = "text/plain";
    var extras = [
        {name:"android.intent.extra.TEXT", type:"string", value:textData},
    ];
    extras = JSON.stringify( extras )
    app.SendIntent(packageName, className, action, category, uri, type, extras)
}

Jumar

unread,
Jan 30, 2023, 8:43:39 AMJan 30
to DroidScript
Hi what I mean about the json format is something like this

{
    "manifest":
    {
        "minSdkVersion": 23,
        "targetSdkVersion": 28,
        "debuggable": false,
        
        "action": "android.intent.action.VIEW",
        "category": "android.intent.category.BROWSABLE"
    }
}

And I don't think it's the right way to do it. You also need to set the scheme which I think is the pathPattern equivalent.

If you want to set your app as the default browser within your app app.SendIntent would be the right way to do it. But I'm afraid there's no enough information in this forum about those values that we need to pass in app.SendIntent especially the extras thing.

Maybe something like.

    var action = "android.intent.action.CHOOSER";
    var category = "android.intent.category.BROWSABLE"
    var uri = null;
    var type = "";
    var extras = [
        {name:"android.intent.extra.INTENT", type:"STRING", value:"Select default browser"},
        ... another extras goes here
    ];
    extras = JSON.stringify( extras )
    app.SendIntent(null, null, action, category, uri, type, extras)

Regards
Jumar

Thiemo Melhorn

unread,
Jan 30, 2023, 9:35:21 AMJan 30
to DroidScript
As soon as I run the code in the development app, nothing happens. Do I need to add the code to a function with a button?

Thiemo Melhorn

unread,
Jan 30, 2023, 9:52:27 AMJan 30
to DroidScript
I believe that all the code belongs in a function of a button but I am unsure about this.

Dave

unread,
Jan 31, 2023, 1:55:07 PMJan 31
to DroidScript
You should be able to use the 'deep linking' feature of DS to achieve this - 

{
    "manifest": {
        "urlScheme": "https",
        "urlHost": "*"
    }
}

or maybe this - 

{
    "manifest": {
        "urlScheme": "https",
        "urlHost": ""
    }
}


Alan Hendry

unread,
Jan 31, 2023, 2:01:35 PMJan 31
to DroidScript
Hi,
Pretty sure that if the build.json works then as soon as the user installs the app then it will become the default browser, so a button cannot turn it on and off.
In the browser tabs app the webview cannot show videos, so the user can open the URL in the default browser, may need changing to try and open Chrome specifically.
As far as I recall, it's possible for intents to open Android Settings screens, but the user has to make the update. See
ACTION_APP_OPEN_BY_DEFAULT_SETTINGS
ACTION_MANAGE_DEFAULT_APPS_SETTINGS
Regards, ah
Message has been deleted

Alan Hendry

unread,
Mar 19, 2023, 11:39:14 AM (yesterday) Mar 19
to DroidScript
HI,
Reportedly neither of these build.jsons do the trick.
Some websites seem to suggest specifyng action (view), categories (default and browsable) and data (http and https).
I presume that this should allow the user to choose this app when opening links, and when choosing an app to be the default browser.
Regards, ah

Right2TheV0id

unread,
Mar 19, 2023, 2:37:38 PM (yesterday) Mar 19
to DroidScript
As we already stated that a webview based browser isn't a full-fledged browser, isn't asking to provide the ability to make an app recognized as a "browser" beyond the scope of DroidScript?
I ask this to point out the fact that, even if it could happen one day, it might get very low on the priorities list.

Alan Hendry

unread,
Mar 19, 2023, 2:59:41 PM (yesterday) Mar 19
to DroidScript
HI,
I think that we really want user's to click on a URL (in any app) 
and open this app
(or at least give the user a list of apps that can open URLs, let them choose once or always).
Regards, ah

Right2TheV0id

unread,
Mar 19, 2023, 3:13:37 PM (yesterday) Mar 19
to DroidScript
Isn't it the default behavior when no default browser has been set?
A solution would be to ask the user to remove the default browser setting.

Alan Hendry

unread,
6:16 AM (16 hours ago) 6:16 AM
to DroidScript
HI,
I can't set it to have no default browser (radio buttons in android 8).
As far as I can tell android shows a list of apps that can accept intents to view URLs.
Regards, ah

Right2TheV0id

unread,
6:53 AM (15 hours ago) 6:53 AM
to DroidScript
You're right, this is more tricky than I thought.
The only way I managed to get the behavior I described was by uninstalling all the apps recognized as potential "default browser" by Android (I don't recommend to do it).
Then I when I click a link, a chooser prompts to choose an app to continue, with all my DS apps able to open links listed.
For this to work build.json needs those entries:
"urlHost": "*",
"urlScheme": "http,https"

People also proposes to use special apps as default browser that will catch every links and always open a chooser prompt to le the user decide which app to use:
Reply all
Reply to author
Forward
0 new messages