简体   繁体   English

在Android中接收自定义网址方案的数据

[英]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. 目前在我的应用程序中,我有自己的URI方案来检测用户何时点击特定的URI。

Code used in Manifest file is as below: Manifest文件中使用的代码如下:

<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. 如果用户在浏览器中单击具有我的自定义URI的链接,它现在将弹出一个选项供用户选择我的应用程序。

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 假设您的网址是: http://twitter.com/status/1234http://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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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