Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27070] Android: Add canStartActivity() method to "Ti.Android.Activity"

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsactivity, android, intent
ReporterJoshua Quick
AssigneeJoshua Quick
Created2019-05-08T18:34:38.000+0000
Updated2019-05-09T04:20:16.000+0000

Description

*The Issue:* Currently, Titanium does not have an API to detect if there are any registered activities that can be started for a given intent. An app developer's only option is to call Titanium's [startActivity()](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Activity-method-startActivity) method and see if it throws an exception or not. This is an issue for apps that need to detect this in advance without launching an activity. *Solution:* Add a new canStartActivity(Intent) method to Ti.Android.Activity which will return true if at least 1 activity was found for the given intent. Internally, this should call Google's [PackageManager.resolveActivity()](https://developer.android.com/reference/android/content/pm/PackageManager.html#resolveActivity(android.content.Intent,%20int)) method, where if it returns a non-null reference, then we know an activity exists for the given intent. Alternatively, we could call Google's [PackageManager.queryIntentActivities()](https://developer.android.com/reference/android/content/pm/PackageManager.html#queryIntentActivities(android.content.Intent,%20int)) method which returns a list of activities matching the given intent, where we could check if at least 1 activity was returned. *Use-Case:* Can be used to detect if there is a 3rd party app installed for viewing a file, such as PDF. If canStartActivity() returns false, then you can alert the end-user that viewer app needs to be installed. *Note:* While it would be more powerful to provide a queryIntentActivities() method in Titanium, the vast majority of app developers simply want to know if at least 1 activity exists. So, it's better to keep it simple for now. The only good use-case I've heard where you want to scrutinize the activity list is when you want to exclude an activity from a particular app that has known issues.

Comments

No comments

JSON Source