Android Question If an Intent...

LucaMs

Expert
Licensed User
Longtime User
What happen if there are no apps able to handle an Intent I "started"?

Ehm... how can I start this "kind" of Intent to test this situation? (I confess that I have not searched if there is a complete list of available Intents, before writing this post, sorry :)).

I mean: can I intercept the situation in which an Intent I started can not be "resolved"?


Many thanks in advance.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Found in http://developer.android.com/guide/components/intents-common.html

Caution: If there are no apps on the device that can receive the implicit intent, your app will crash when it calls startActivity(). To first verify that an app exists to receive the intent, call resolveActivity() on your Intent object. If the result is non-null, there is at least one app that can handle the intent and it's safe to call startActivity(). If the result is null, you should not use the intent and, if possible, you should disable the feature that invokes the intent.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have found a solution:

upload_2015-7-31_14-27-57.png



Thank you anyway :)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
This code seems to work (to avoid the use of Library Phone):
B4X:
Sub ResolvableActivity(pIntent As Intent) As Boolean
    Dim r As Reflector
    r.Target = pIntent
    Dim ComponentName As Object
    ComponentName = r.RunPublicmethod("resolveActivity", Array As Object(getPackageManager), Array As String("android.content.pm.PackageManager"))
    Return (ComponentName <> Null)
End Sub

Sub getPackageManager As Object
    Dim context As JavaObject
    context.InitializeContext
    Return context.RunMethod("getPackageManager", Null)
End Sub

If someone wanted confirm... thanks.
 
Upvote 0
Top