Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14291] Android: Support for PackageManager and queryIntentActivities

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.1.1
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, intent, packagemanager
ReporterMads Moller
AssigneeJoshua Quick
Created2013-06-19T07:13:51.000+0000
Updated2019-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);

Comments

  1. Mads Moller 2013-06-19

    Priority: None nice one :)
  2. Ingo Muschenetz 2013-06-28

    You're welcome. :) I'll get the team to work on scoping this.
  3. Shannon Hicks 2013-11-04

    I built a module that provides PackageManager access: https://github.com/iotashan/TiAppHelper
  4. Marian Kucharcik 2015-11-06

    @Shannon Hicks: Can you please advice me how to install your module? It's JAR only file... Thanks
  5. Shannon Hicks 2015-11-06

    You'll have to build that one from source.
  6. Joseph Sachs 2015-12-31

    I will try this out. Seems like 3 years old. Hope it's still working

JSON Source