Pages

26 Nov 2013

Create a flexible link to open Google Play or your own App from web browser in Android

Today I learnt a completely new thing as the title says it all, so I want to note it here for later uses.
So how to do?

In manifest.xml:
        <activity 
            android:label="@string/activity_label"
            android:name="com.your.package.ActivityName">
            <intent-filter>
                 <data
                      android:host="your-domain-or-whatever.com"
                      android:scheme="your-own-scheme" />
                 <action android:name="android.intent.action.VIEW" />
                 <category android:name="android.intent.category.BROWSABLE" />
                 <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity> 

And your link should look like:
<a href="intent://your-domain-or-whatever.com/?param1=value1&amp;param2=value2#Intent;scheme=your-own-scheme;package=com.your.app.package;end">OPEN APP OR GOOGLE PLAY</a>

The last thing is catching parameters in your com.your.package.ActivityName. In onCreate of the Activity:
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.your_activity_layout);
  Uri mUri = getIntent().getData();
  String value1 = mUri.getQueryParameter("param1");
  String value2 = mUri.getQueryParameter("param2");
 }


That's all, bye xD!
P/S: Oh yeah, I just found this one too: https://developers.google.com/chrome/mobile/docs/intents, check it out!

No comments:

Post a Comment

Note: only a member of this blog may post a comment.