Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用深度链接打开我的应用程序,而不是重定向到google play store站点?_Android_Deep Linking_Intentfilter - Fatal编程技术网

Android 如何使用深度链接打开我的应用程序,而不是重定向到google play store站点?

Android 如何使用深度链接打开我的应用程序,而不是重定向到google play store站点?,android,deep-linking,intentfilter,Android,Deep Linking,Intentfilter,当用户点击链接时,我尝试直接打开我的应用程序,而不打开google play商店或浏览器 我尝试过以下代码: <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenS

当用户点击链接时,我尝试直接打开我的应用程序,而不打开google play商店或浏览器

我尝试过以下代码:

     <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">

        <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="fptest"
                android:host="forgot"
                android:pathPrefix="/"/>
        </intent-filter>
    </activity>

I'm using link as follows

<a href="intent://TestApplication#Intent;scheme=fptest;package=com.example.testapplication;end">  
   Open App
 </a>

where , 
   TestApplication -- my app name
   package -- com.example.testapplication

哪里
TestApplication--我的应用程序名称
包--com.example.testapplication
但它总是打开Google Play或浏览器,而不是我的应用程序


我想从链接打开我的应用程序,例如:fptest://forgot . 我不想使用http作为方案

您可以通过以下代码实现这一点。如果您正在打开自己的应用程序,则无需更改任何内容。但是,如果您愿意打开不同的应用程序,则只需使用该特定应用程序更改
getPackageName

@SuppressLint("WrongConstant")
    public void OpentheApp()
    {
        Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + getPackageName()));
        localIntent.addFlags(1208483840);
        try
        {
            startActivity(localIntent);
        }
        catch (Exception localException)
        {
            startActivity(new Intent("android.intent.action.VIEW", Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
        }
    }
如果您想通过
webview
打开它。然后遵循以下步骤: 在活动中声明这两个

String market_url = "market://details?id=package_name";
String website_url = "https://play.google.com/store/apps/details?id=package_name";
内部OnCreate:

WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/index.html");               // path to html
webview.setWebViewClient(new Callback());


    private class Callback extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.equals(website_url)) {
                try {
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(market_url));
                    startActivity(intent);
                } catch (ActivityNotFoundException e) {
                }
            }
            return (false);
        }
    }
index.html

<a href="https://play.google.com/store/apps/details?id=package_name">App link</a>


它将在play store中打开应用程序。

您可以通过以下代码实现此目的。如果您正在打开自己的应用程序,则无需更改任何内容。但是,如果您愿意打开不同的应用程序,则只需使用该特定应用程序更改
getPackageName

@SuppressLint("WrongConstant")
    public void OpentheApp()
    {
        Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + getPackageName()));
        localIntent.addFlags(1208483840);
        try
        {
            startActivity(localIntent);
        }
        catch (Exception localException)
        {
            startActivity(new Intent("android.intent.action.VIEW", Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
        }
    }
<data
       android:host="www.yourdomain.com"
       android:pathPrefix="/api/forgot"
       android:scheme="https"
</data>
如果您想通过
webview
打开它。然后遵循以下步骤: 在活动中声明这两个

String market_url = "market://details?id=package_name";
String website_url = "https://play.google.com/store/apps/details?id=package_name";
内部OnCreate:

WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/index.html");               // path to html
webview.setWebViewClient(new Callback());


    private class Callback extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.equals(website_url)) {
                try {
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(market_url));
                    startActivity(intent);
                } catch (ActivityNotFoundException e) {
                }
            }
            return (false);
        }
    }
index.html

<a href="https://play.google.com/store/apps/details?id=package_name">App link</a>

它将在play store中打开应用程序。

将此添加为您的链接

<data
       android:host="www.yourdomain.com"
       android:pathPrefix="/api/forgot"
       android:scheme="https"
</data>
<a href="intent://forgot#Intent;scheme=fptest;package=com.example.testapplication;end">  
   Open App
 </a>

注意:我将TestApplication替换为忘记您需要在
意图之后使用主机://

将此添加为您的链接

<a href="intent://forgot#Intent;scheme=fptest;package=com.example.testapplication;end">  
   Open App
 </a>


注意:我用“忘记您需要使用主机”替换了TestApplication,原因是
意图://

您好,谢谢您抽出时间。我想打开安装在我的设备中的我自己的应用程序。实际上,我的功能是发送一个链接到邮件重置密码。点击链接,我们的应用程序应该打开(如果已安装)。我不想开游戏商店。若我给scheme http,那个么应用程序将打开。但我不想添加http,我的url是为例如:fptest://forgotHi 谢谢你抽出时间。我想打开安装在我的设备中的我自己的应用程序。实际上,我的功能是发送一个链接到邮件重置密码。点击链接,我们的应用程序应该打开(如果已安装)。我不想开游戏商店。若我给scheme http,那个么应用程序将打开。但我不想添加http,我的url是为例如:fptest://forgotHi 谢谢你抽出时间。我想使用自定义方案(不是https/http)。您好,谢谢您的时间。我想使用自定义方案(不是https/http)。