[TIMOB-14291] Android: Support for PackageManager and queryIntentActivities
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Low |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Release 3.1.1 |
Fix Version/s | n/a |
Components | Android |
Labels | android, intent, packagemanager |
Reporter | Mads Moller |
Assignee | Joshua Quick |
Created | 2013-06-19T07:13:51.000+0000 |
Updated | 2019-05-08T21:07:33.000+0000 |
Description
At the moment, there is no way to figure out which apps and intents is available on the users device.
So we need to guess, or do try catch logic, like this:
try {
var intent = Ti.Android.createIntent({
action : Ti.Android.ACTION_SEND,
packageName : "com.twitter.android",
className : "com.twitter.android.PostActivity",
flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
type : "text/plain"
});
if (options.text) {
intent.putExtra(Ti.Android.EXTRA_TEXT, options.text);
}
Ti.Android.currentActivity.startActivity(intent);
} catch(e){
// Fallback - if app is not installed
// do something
}
What we need is access to Android Package Manager. This way we can loop through the installed applications, and figure out what is available, instead of guessing.
I could do something like this: http://stackoverflow.com/questions/6827407/how-to-customize-share-intent-in-android/9229654#9229654
Proposal:
// test
var bool = Ti.Android.isPackageNameSupported("com.twitter.android");
// get all apps installed
var mainIntent = Ti.Android.createIntent({
action : Ti.Android.ACTION_SEND
});
mainIntent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
var packageManager = Ti.Android.getPackageManager();
var applist = packageManager.queryIntentActivities( mainIntent, 0);
Priority: None nice one :)
You're welcome. :) I'll get the team to work on scoping this.
I built a module that provides PackageManager access: https://github.com/iotashan/TiAppHelper
@Shannon Hicks: Can you please advice me how to install your module? It's JAR only file... Thanks
You'll have to build that one from source.
I will try this out. Seems like 3 years old. Hope it's still working