Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 259
aandroidtest Avatar asked Sep 27 '13 08:09

aandroidtest


People also ask

How does deeplink work on Android?

In Android, a deep link is a link that takes you directly to a specific destination within an app. The Navigation component lets you create two different types of deep links: explicit and implicit.

How do I find deep links on Android?

By using Android Debug Bridge (ADB) shell commands one can test the deep link flow. It is used to verify if the link navigates to the correct section of your app. This command starts the ADB shell with the VIEW action and specifies the deep link URL to be tested.

What is an app scheme URL?

📘 URL Schemes are an advanced configuration option used to define a non-standard link format that will only open in your app and not the device browser e.g. youruniquestring://yoursite.com/path This functionality is helpful in authentication redirect flows or for a more seamless user experience.


1 Answers

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"
like image 54
Lazy Ninja Avatar answered Oct 30 '22 22:10

Lazy Ninja