Run Activity at URL

I am trying to launch an application when a user browses a specific url. I found several examples, and they all have the same thing in the manifest, but this does not work for me. I put an intent filter in action as well as in the receiver.

Here is my manifest snippet:

<intent-filter> <action android:name="android.intent.action.VIEW"></action> <category android:name="android.intent.category.DEFAULT"></category> <category android:name="android.intent.category.BROWSABLE"></category> <data android:host="www.urbandictionary.com" android:scheme="http"></data> </intent-filter> 

When I was under the Activity, I tried to use onNewIntent, and when it was under the receiver, I tried to use onReceiveIntent, like with a simple call to Log.i to see if he was fired or not. I was not lucky.

+4
source share
1 answer

I use this in manifest.xml:

 <activity android:name=".SomeName"> <intent-filter> <category android:name="android.intent.category.ALTERNATIVE" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="google.com" android:scheme="http" /> </intent-filter> </activity> 

This will launch Activity SomeName. I do not use www in android: the host part might matter.

When the action begins, you can get the data that is behind .com using (for example):

 Uri data = getIntent().getData(); if(data != null && data.getPathSegments().size() >= 2){ List<String> params = data.getPathSegments(); String somestuff = params.get(0); } 

Edit: if you cannot verify the host inside the action, use this method:

 data.getHost(); 
+7
source

Source: https://habr.com/ru/post/1303277/


All Articles