Android深层链接问题!如何使用自定义网址方案myapp://some_data [英] Android Deep Linking issue ! How to use Custom Url scheme myapp://some_data

查看:55
本文介绍了Android深层链接问题!如何使用自定义网址方案myapp://some_data的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了 link1 link3 link5 链接6

这里介绍了有关 DeepLinking

我想要的是自定义uri myapp://some_data,打开安装在需要some_data来初始化应用程序的设备中的本机应用程序.

What i want is the custom uri myapp://some_data, opens the native application installed in the device that requires some_data to initialise the application.

在两种情况下,可以单击自定义URL.

There are 2 scenarios in which the custom url can be clicked.

1)从SMS应用程序中,当用户点击链接时,它会自动打开已安装的应用程序,否则打开托管该应用程序的googleplay商店

1) from within the SMS app, when user taps the link it should automatically open the installed otherwise open the googleplay store where the app is hosted

2)来自电子邮件正文中.

2) from within the body of a email message.

我已经尝试了上面列出的所有链接,但是没有一个对我有用.我在计划部分有重大问题.

I have tried all the above listed links, but none of them works for me. I m having major problem with the scheme part.

这是我的AndroidManifest.xml

Here's my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="MainActivity"
        android:label="@string/app_name"
         android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

            <data android:scheme="inderbagga" />
        </intent-filter>
    </activity>
</application>

这是MainActivity.java

and here's the MainActivity.java

TextView tvText=(TextView)findViewById(R.id.tvid);

    if (getIntent().getAction() == Intent.ACTION_VIEW&&getIntent().getScheme().equals("inderbagga")) {
        Toast.makeText(getApplicationContext(), ""+getIntent().getScheme(), Toast.LENGTH_SHORT).show();
        Uri uri = getIntent().getData();
        // do stuff with uri
        tvText.setText(uri.toString());
    }
    else tvText.setText("NULL");

更具体地说,我想在单击类型为inderbagga://a1b22c333的u url时打开本机应用程序,无论是来自sms应用程序还是gmail/yahoomail电子邮件正文.

To be more specific, i want to open the native application when u url of type inderbagga://a1b22c333 is clicked, Either from sms application or gmail/yahoomail email message body.

为了达到相同的目的,我使用了意图过滤器来设置方案.和getIntent()读取MainActivity中等于a1b22c333的数据.

in order to achieve the same, i 've used intent filters to set the scheme. and getIntent() to read the data that equals to a1b22c333 in the MainActivity.

推荐答案

点击链接表示此代码有效

click link means this code will work

          <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="http"
      android:host="domain.com(google.com)"android:pathPrefix="/wp/poc1/(sufexes)" />

    </intent-filter>

获取网址数据

        //get uri data
     Uri data = getIntent().getData();
     //get schma
     String scheme = data.getScheme(); // "http"
     //get server name
     String host = data.getHost(); // Ipaddress or domain name
    //get parameter
     String urltextboxname=data.getQueryParameter("name");
     //set value in textview
     name.setText(urltextboxname);

这篇关于Android深层链接问题!如何使用自定义网址方案myapp://some_data的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆