I am trying to pass parameters to deep links in Android and that is not working.
I have specified a hostName variable in the app/build.gradle file to distinguish between UAT and production URLs. This hostName variable is referenced in AndroidManifest.xml like so:
<activity
android:name=".ui.MyActivity"
android:theme="#style/MyTheme"
android:configChanges="orientation"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- deep links for home page. -->
<data
android:scheme="https"
android:host="${hostName}"
android:pathPrefix="/login.jsp?signup=true" />
</intent-filter>
</activity>
I am trying to use adb to test for deep links like so:
adb.exe shell am start -W -a android.intent.action.VIEW -d "https://www.mywebsite.co.in/login.jsp?signup=true" com.myapp.ui.MyActivity
The error I get is:
Starting: Intent { act=android.intent.action.VIEW dat=https://www.mywebsite.co.in/... pkg=com.myapp.android.alpha }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=https://www.mywebsite.co.in/... flg=0x10000000 pkg=com.myapp.android.alpha }
I have read through a number of similar questions here on SO and all of them suggest escaping the special characters. But that has not worked in this case.
Any insights on resolving this will be most welcome.
The android:pathPrefix is invalid in your AndroidManifest.xml.
It should only contain the path element, not the query:
android:pathPrefix="/login.jsp"
The query string ?signup=true is not part of the path. You cannot filter on query strings.
Related
I am trying to open an app using a custom url scheme.
I ran into the following error while testing through adb before deployment.
Exception occurred while executing 'start':
java.lang.IllegalArgumentException: Unknown option: -
at android.content.Intent.parseCommandArgs(Intent.java:8358)
at com.android.server.am.ActivityManagerShellCommand.makeIntent(ActivityManagerShellCommand.java:349)
at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:451)
at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:192)
at android.os.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:98)
at android.os.ShellCommand.exec(ShellCommand.java:44)
at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:13144)
at android.os.Binder.shellCommand(Binder.java:965)
at android.os.Binder.onTransact(Binder.java:839)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:6044)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3642)
at android.os.Binder.execTransactInternal(Binder.java:1195)
at android.os.Binder.execTransact(Binder.java:1159)
I tried to open it with the following command.
adb shell am start -W -a android.intent.action.VIEW - "onionmarkethost://onionmarket.open" kr.gowoonwoori.oniontime
This code is the manifest code for me to create a custom schema.
<activity android:name=".schema.SchemaActivity">
<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:host="onionmarkethost"
android:scheme="onionmarket.open" />
</intent-filter>
</activity>
What's the matter? I really don't know. Please, Help me.
Just remove the hyphen '-' after 'android.intent.action.VIEW' and use a single space instead before your url scheme
I'm trying to get make a url open the app and to have some data with this url passed into the app, but it doesn't work.
My activity tag in AndroidManifest.xml:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask"> <-- added this
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="fcm.ACTION.HELLO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<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="conv"
android:host="convid"/> <-- so urls of the form 'conv://convid/ will open the app
</intent-filter>
</activity>
And I added to the entry class of the app:
componentDidMount() {
Linking.addEventListener('url', (e) => {
console.log("url", e);
});
Linking.getInitialURL().then((url) => {
if (url) {
console.log('Initial url is: ' + url);
}
})
}
But when I open the browser and go to conv://convid nothing is being logged and the app doesn't open.
Of course I opened my app before the browser.
The app will not open if the link is entered into the browser's address bar. It has to be a web page <a/> tag like:
link inside some page. (https://developer.chrome.com/multidevice/android/intents)
As you probably do not have a web page to put tag inside, for your tests you can use adb command. Open the console and write the following line:
adb shell am start -W -a android.intent.action.VIEW -d "YOURHOST://YOURSCEME/" com.YOURAPPNAME
for example in your case it should be something like (change YOURAPPNAME with the name of your app):
adb shell am start -W -a android.intent.action.VIEW -d "convid://conv/" com.YOURAPPNAME
if you are using windows and, and if it says adb command is undefined you need to run the command from platform-toolsfolder inside your SDK folder such as:
Android/Sdk/platform-tools/
I am working with build variants and want to capture additional links based on the variant. I want all variants to capture links from host one so I have declared an intent-filter in my main AndroidManifest.xml file like so:
<activity android:name=".activity.DeepLinkActivity"
android:noHistory="true">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:host="hostOne.com" android:path="/page.aspx" android:scheme="http"/>
</intent-filter>
</activity>
I am also generating a partial manifest for other variants such as hostTwo.com like so:
<?xml version="1.0" encoding="UTF-8"?><manifest package="com.package.my.domain">
<application xmlns:android="http://schemas.android.com/apk/res/android" android:name="AlarmMobile">
<activity android:name=".activity.DeepLinkActivity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http://" android:host="hostTwo.com" android:path="/page.aspx"/>
</intent-filter>
</activity>
</application>
</manifest>
It is placed in an appropriately named folder according to the build variant (based upon the documentation here) and Android studio's merged manifest view shows that the intent-filter for host two has been added to the final merged manifest, however, the emulator or actual device fails to capture intents meant for the second host.
I am generating intents like so in the command prompt:
adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://hostone.com/page.aspx"
which works for hostone, but doing
adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://hosttwo.com/page.aspx"
will launch the browser because the app fails to capture it.
Do android app links only work for one host name? Is there anything else which I can try?
I figured out that the partial manifest was incorrect. In the intent-filter's data tag, android:scheme="http://" is invalid due to the trailing ://.
According to google's documentation, Android builds the intent-filter URI like so: <scheme>://<host>:<port>/<path> so including it in the declaration is unnecessary.
After changing my declaration to android:scheme="http" the merge continues to be successful and the OS attempts to validate the links defined in the partial manifest!
Corrected partial manifest:
<?xml version="1.0" encoding="UTF-8"?><manifest package="com.package.my.domain">
<application xmlns:android="http://schemas.android.com/apk/res/android" android:name="AlarmMobile">
<activity android:name=".activity.DeepLinkActivity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http" android:host="hostTwo.com" android:path="/page.aspx"/>
</intent-filter>
</activity>
</application>
</manifest>
I'm trying to enable deep linking so that certain links launch my app.
I read this turotial https://developer.android.com/training/app-indexing/deep-linking.html and following it pretty close but when I try to test it by using adb to send the VIEW intent to the app I just get the error
Error: Activity not started, unable to resolve Intent { act=android.intent.actio
n.VIEW dat=example://gizmos flg=0x10000000 pkg=com.myapp.DeepLinkActivity }
DeepLinkActivity.java
public class DeepLinkActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getAction() == Intent.ACTION_VIEW) {
Uri uri = getIntent().getData();
}
}
}
Android Manifest declaring deeplink activity
<activity android:name="com.myapp.DeepLinkActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="gizmos"
android:scheme="example" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data
android:host="www.example.com"
android:pathPrefix="gizmos"
android:scheme="http" />
</intent-filter>
</activity>
ADB command to send the view intent
adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.myapp.DeepLinkActivity
But I don't think I even need the full path to the activity
adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.myapp
Try skipping package param entirely. I had exactly same problem and it works.
adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos"
Comment out the second data part from your Android Manifest. As per google documentation of deep link :
"Intent filters may only contain a single data element for a URI pattern. Create separate intent filters to capture additional URI patterns."
In your manifest you defined your scheme as "http" but in your intent constructor you are using "example."
The problem is you have one intent filter for 2 types of deep links:
<activity
android:name="app.myActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos”-->
<data
android:host="gizmos"
android:scheme="example" />
</intent-filter>
<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:host="www.example.com"
android:pathPrefix="/gizmos"
android:scheme="http" />
<!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>
</activity>
And you will be able to use both on the ADB shell. Please see my full answer here
Simply try as follows
Command:
adb shell am start -d your-deep-link
Example:
adb shell am start -d rmagazine://opensetting/v1
I have the following in my AndroidManifest.xml (I just added a second activity to the default project):
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.com.testapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.com.testapp.TestActivity"
android:label="#string/title_activity_test" >
<intent-filter>
<action android:name="com.testapp.action.TEST_ACTION" />
</intent-filter>
</activity>
I want to launch the TestActivity using adb command. I tried:
./adb shell am start -a com.testapp.action.TEST_ACTION
But it gives the error:
Error: Activity not started, unable to resolve Intent { act=com.testapp.action.TEST_ACTION flg=0x10000000 }
Can someone please explain why I am getting this error and how to resolve it?
Edit :
Can anyone tell a way to just use action to launch the 'TestActivity'.
I think you should add the code below into your intentfilter
<category android:name="android.intent.category.DEFAULT"/>
try using:
adb shell "am start -n com.example.com.testapp/.TestActivity -a com.testapp.action.TEST_ACTION"
or
adb shell "am start com.example.com.testapp -a com.testapp.action.TEST_ACTION"
hope that works.
Try adb shell am start -n com.mypackage.name/com.mypackage.name.TEST_ACTION (replace the package names and activity names as needed)
Take a look at this solution.
To expand on what 陈薛星 wrote, in the "Android developer guide on Intent Filters" under "Category Test", it states
Note: Android automatically applies the CATEGORY_DEFAULT category to all implicit intents passed to startActivity() and startActivityForResult(). If you want your activity to receive implicit intents, it must include a category for "android.intent.category.DEFAULT" in its intent filters, as shown in the previous example.
So you need to add
<category android:name="android.intent.category.DEFAULT"/> to your intent filter.
This will match an implicit intent. (Several other answers show how to target a class explicity).