Reputation: 8616
I need my application opens when clicking on a link. for this I read that I must use a URL scheme. The link must have the form myapp://parameters.
I read every post on this subject, but when I send an email with "myapp://addUser/?id=22" and I open from chrome (on my phone), it is not clickable.
My manifest:
<activity
android:name="com.example.SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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="myapp" android:host="com.example"/>
</intent-filter>
</activity>
My class:
public class SplashActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
String id = uri.getQueryParameter("id");
}
}
Content of the mail to test the code:
myapp://addUser/?id=22
Reference Links:
Make a link in the Android browser start up my app?
https://legacy.madewithmarmalade.com/devnet/forum/custom-url-scheme-primarily-android-3
UPDATE
I think the problem is the mail body, but I don't know how I can test this.
Upvotes: 8
Views: 9956
Reputation: 469
I made a test here and in the manifest file I just removed the "android:host" parameter, leaving this:
<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>
and it opened an URL myapp://testing
here that I put on a simple HTML file just for trying.
Upvotes: 1
Reputation: 1459
In your manifest
<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="com.example"/>
</intent-filter>
you define android:host="com.example", so you should modify link URL :
myapp://addUser/?id=22 //error
myapp://com.example/?id=22 //correct
then it can work!!
Upvotes: 3