Page 1 of 1

List of installed link handler

Posted: 13 Sep 2018 03:26
by anuraag
Hey
Can anyone help me getting list of installed package names for a particular uri type?

Like i want to get list of web browsers installed which can open links? I think this could be done through java but i don't know how to do.

Thanks

Re: List of installed link handler

Posted: 16 Sep 2018 00:54
by anuraag
I have created a script which is working using a tasker example for music player

Code: Select all

intent=callJavaConstructor("android.content.Intent", "Intent()");
callJavaMethod(intent, "android.content.Intent", "setAction(java.lang.String)", "android.intent.action.VIEW");
callJavaMethod(intent, "android.content.Intent", "addCategory(java.lang.String)", "android.intent.category.BROWSABLE");
Uri=callJavaMethod(intent, "android.content.Intent", "setData(android.net.Uri)", callJavaStaticMethod("android.net.Uri", "parse(java.lang.String)", 'https:'));

ctx=getContext();
pacman=callJavaMethod(ctx, "android.content.Context", "getPackageManager()");

reslist=callJavaMethod(pacman, "android.content.pm.PackageManager", "queryIntentActivities(android.content.Intent, int)", intent, "0");
reslist contains list of apps. For example one entry

Code: Select all

ResolveInfo{9449d8a com.android.chrome/com.google.android.apps.chrome.IntentDispatcher m=0x208000}
Now can anyone tell me how to get activity of those apps?

Re: List of installed link handler

Posted: 16 Sep 2018 10:24
by Desmanto
This is interesting. May I know what is the purpose?
I don't much about java, but I can pull some data from dumpsys. You need to use adb to this. Or in rooted phone, you can directly use execute root command

Code: Select all

dumpsys package pref
Then look for http and https

Re: List of installed link handler

Posted: 16 Sep 2018 10:40
by anuraag
I want to create a flow with list of available browsers to open a link. I will use input dialog to choose browser i need. I ofen switch between brave, chrome and adm browser. I know there is an app available for this but that doesn't fulfill my requirement.

I got list of browser as mentioned above but i stuck at getting app name, activity name.

Re: List of installed link handler

Posted: 16 Sep 2018 15:05
by Desmanto
Why don't just reset the default app browser, and always choose everytime you need to open link? It is easier.

I used to make a flow with view url intent and intercept all those, redirect to each app/browser. But now I simply use Chrome as default. When I need to open in IDM browser, I simply copy the link, use the gesture or smartbar shortcut to access the shortcut to open the clipboard link in IDM browser. Much more control. The same goes thru for other type of link or app.

If you still want an input dialog, it is better to build a default choices, along with its package name and activity name. Use map, to store those activitiy and use the key as the choice. Any choice will be mapped to the corresponding app and activity to be used in action Open Url in Browser. I don't know the activity for the brave and adm, but you can check it in Open Url action, copy those and put into map.

Re: List of installed link handler

Posted: 16 Sep 2018 15:29
by anuraag
@Desmanto that will be my alternative option if i couldn't find an answer java way.

Re: List of installed link handler

Posted: 19 Sep 2018 08:11
by anuraag
Since i couldn't make it further with java, i used builtin available function in automagic to get package name and activity. Here is rest of script

Code: Select all

global_browsers=newMap();
for (i in [0 to length(reslist)-1])
{obj=getElement(reslist, i);
pac=getElement(split(obj, " "), 1);

packageName=getElement(split(pac, "/"), 0);
activity=getElement(split(pac, "/"), 1);
appname=getAppName(packageName);

if (startsWith(activity, ".")==true)
{activity=packageName + activity;}
list=newList();
addElement(list, packageName);
addElement(list, activity);
addMapEntry(global_browsers, appname, list)
}

Edit:: did it programatically

Code: Select all

 packageNameList=newList();
classNameList=newList();
appnameList=newList();
iconList=newList();

for (i in [0 to length(reslist)-1])
{obj=getElement(reslist, i);
compInfo=callJavaMethod(obj, "android.content.pm.ResolveInfo", "getComponentInfo()");
compName=callJavaMethod(compInfo, "android.content.pm.ComponentInfo", "getComponentName()");
className=callJavaMethod(compName, "android.content.ComponentName", "getClassName()");
packageName=callJavaMethod(compName, "android.content.ComponentName", "getPackageName()");
resid=callJavaMethod(obj, "android.content.pm.ResolveInfo", "getIconResource()");

resid=callJavaMethod(obj, "android.content.pm.ResolveInfo", "resolveIconResId()");
icon="android.resource://"+packageName+"/"+resid;

appname=getActivityName(packageName, className);
addElement(packageNameList, packageName);
addElement(classNameList, className);
addElement(appnameList, appname);
addElement(iconList, icon) 
}