简体   繁体   中英

Receiving data for custom url scheme in Android

Currently in my app, I have my own URI scheme to detect when user clicks on a particular URI.

Code used in Manifest file is as below:

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

If a user clicks on a link which has my custom URI in browser, It will now popup a options for user to choose my app.

But how do I pass this data which is the link to my app when started for further processing? Basically how do I pass data from browser to my app?

Thanks in Advance

Suppose that your url is: http://twitter.com/status/1234
You can get the data using the following method.

  // http://twitter.com/status/1234
    Uri data = getIntent().getData();
    Log.d(TAG, data.toString());
    String scheme = data.getScheme(); // "http"
    Log.d(TAG, scheme);
    String host = data.getHost(); // "twitter.com"
    Log.d(TAG, host);
    String inurl = data.toString();
    List<String> params = data.getPathSegments();
    String first = params.get(0); // "status"
    String second = params.get(1); // "1234"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM