Like the dozen other threads out there, I am trying to debug directly on a device using Android Studio via a uri. But I can't seem to find an exact example of someone doing so from Android Studio using the Edit Configuration. Sure something simple I am missing...
Here is what I am doing:
Here is the intent in the AndroidManifest.xml:
<activity
android:name="com.mayapp.StartActivity"
android:configChanges="orientation|keyboardHidden|screenSize|keyboard|navigation"
android:label="StartActivity"
android:launchMode="singleTask"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme=myapp" />
</intent-filter>
</activity>
The following error shows up when I try to debug:
As Text:
11/21 13:15:05: Launching MyApp
Launching deeplink: myapp%3A%2F%2Fdispatch.
$ adb shell setprop log.tag.AppIndexApi VERBOSE
$ adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d myapp%3A%2F%2Fdispatch -D
Error while executing: am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d myapp%3A%2F%2Fdispatch -D
Starting: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=myapp://dispatch }
Error: Activity not started, unable to resolve Intent act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=myapp://dispatch flg=0x10000000
Error while Launching URL
So, it would seem that there are several problems to what I was doing. What is interesting is that the way the AndroidManifest.xml was configured some 4 years ago seemed to be working, but to run in Android Studio not only does the scheme
need to be specified but also the home
in the Intent. In my case I have several actions associated with the same scheme
, so the answer was to have multiple data sections within the same intent
. I could not find any Android documentation on that, but I could have just missed it. So for anyone who might encounter this in the future here is what I did:
In the AndroidManifest.XML define the intent
just like I did, but make sure there is a home
also. Obviously what you want the app to do when it does open can be different, seems to be a lot of info on that around so I am not including it here. For each action you want to trigger off of, add a new data
section:
<activity
android:name="com.myapp.StartActivity"
android:configChanges="orientation|keyboardHidden|screenSize|keyboard|navigation"
android:label="StartActivity"
android:launchMode="singleTask"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="anondispatch"/>
<data android:scheme="myapp" android:host="dispatch"/>
<data android:scheme="myapp" android:host="openform"/>
<data android:scheme="myapp" android:host="opendispatch"/>
</intent-filter>
</activity>
In the code you can catch the opening in the onIntent()
method in the specified activity
(in my example it is StartActivity
). Here is a sample of the code parsing out the elements you are looking for:
protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); Intent intent = getIntent(); if (intent.getAction() != null) { if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri uri = intent.getData(); String host = uri.getHost(); ` String uriStr = uri.toString(); if (host.equalsIgnoreCase("anondispatch")) { // parse out that you want } else if (host.equalsIgnoreCase("opendispatch")) { // parse out that you want } else if (host.equalsIgnoreCase("openform")) { // parse out that you want } else if (host.equalsIgnoreCase("dispatch)) { // parse out that you want } } } } }
Update the configuration, from the Edit Configuration so the debugger can run on a remote device via USB by using the following:
User contributions licensed under CC BY-SA 3.0