简体   繁体   English

重定向到Google Play商店(如果从浏览器启动android应用时未安装应用)

[英]Redirecting to Google Play store, if app is not installed while launching android app from browser

I am launching android app from browser. 我正在从浏览器启动android应用。 I write the below code in manifest for launching app from browser & launching successfully, 我将以下代码写在清单中,用于从浏览器启动应用程序并成功启动,

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

My requirement is like I have to redirect to google play store, if the app is not installed. 我的要求就像我必须重定向到Google Play商店(如果未安装该应用程序)。

How can I achieve that? 我该如何实现?

Adding the intent filter is good, but here's what I do to open an intent on an android device when the user agent matches as such. 添加意图过滤器是好的,但是当用户代理匹配时,这是我在android设备上打开意图的操作。 I'm specifically using rails but you can do it however you like in your server code (such as in the form of a link): 我专门使用Rails,但是您可以按照自己的服务器代码(例如链接形式)进行操作:

resources :users, path: '/', only: [], constraints: { :id => /\d+/ } do
  constraints :user_agent => /Android/i do
    #https://developers.google.com/chrome/mobile/docs/intents
    get '/:some_key' => redirect {|params, request| "intent://my-domain.com/#{params[:user_id]}/#{params[:some_key}#Intent;package=com.mypackage;scheme=myscheme;end;"}
  end
end

In your intent filter use the custom scheme: 在您的意图过滤器中,使用自定义方案:

<data android:scheme="myscheme"/>
<data android:host="my-domain.com"/>

See https://developers.google.com/chrome/mobile/docs/intents as it gives this example: 请参见https://developers.google.com/chrome/mobile/docs/intents ,其中提供了以下示例:

<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end"> Take a QR code </a>

Note: By giving the qualified package name this way, Android will direct the user to the play store for the app matching that package key if it is not installed. 注意:通过这种方式给合格的软件包名称命名,Android会将用户定向到Play商店,查找与该软件包密钥匹配的应用程序(如果未安装)。

http://developers.mobileapptracking.com/deeplinking-mobile-app-website/ http://developers.mobileapptracking.com/deeplinking-mobile-app-website/

Check this - they suggest one nice way. 对此进行检查-他们建议一种不错的方法。

In your app - you need to register to :// and then try to open that URL from JS on browser. 在您的应用中-您需要注册到://,然后尝试在浏览器上从JS打开该URL。 If app is present - it navigates away. 如果存在应用程序-它会导航。 If app is not present - next continue to open the google play link. 如果应用不存在-接下来继续打开Goog​​le Play链接。

Hope this serves the purpose. 希望这能达到目的。

(Note: another way is intent:// - but this has one issue - When you open Google Play - you cannot pass referrer to find out where the click has come from). (注意:另一种方法是intent://-但这有一个问题-打开Goog​​le Play时-您无法通过引荐来源网址来确定点击来自何处)。 It that is not your requirement - then intent:// is definitely the best way - I tried it on Android browser, Chrome, Firefox, Opera on Android 4.4 and works fine on all. 这不是您的要求-那么intent://绝对是最好的方法-我在Android浏览器,Chrome,Firefox,Opera 4.4上的Opera上进行了尝试,并且在所有平台上都能正常运行。

If you need to redirect the link to play store if app is not installed then try firebase dynamic link. 如果您未安装应用,则需要将链接重定向到Play商店,请尝试使用Firebase动态链接。 Try this url. 试试这个网址。 https://firebase.google.com/docs/dynamic-links https://firebase.google.com/docs/dynamic-links

I would use the URL https://play.google.com/store/apps/details?id=com.anil.myapp on the webpage. 我会在网页上使用URL https://play.google.com/store/apps/details?id=com.anil.myapp This would open the Play Store on the device, which will let the user open the app if it is installed, or install it if it's not. 这将在设备上打开Play商店,如果安装了该应用程序,则用户可以打开该应用程序;如果没有安装,则可以将其安装。 This will work regardless of any intent filtering in the manifest. 无论清单中是否有任何意图过滤,此方法都将起作用。

If you'd like to get the intent filtering working with this approach, I believe you could try 如果您想使用这种方法来进行意图过滤,我相信您可以尝试

<data android:scheme="https" android:host="play.google.com" android:pathPrefix="/store/apps/details?id=com.anil.myapp"/>

but I'm not sure if that will match. 但我不确定是否会匹配。

Do like this. 这样吧

   boolean installed =appinstalledOrNot("package name"); 
   if(installed) {
   //do your stuff
   }

   else
   {
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setData(Uri.parse("market://details?id=package name"));
   startActivity(intent);
   }

 private boolean appinstalledOrNot(String uri) {
    PackageManager pm = getPackageManager();
    boolean app_installed = false;
    try {
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        app_installed = true;
    }
    catch (PackageManager.NameNotFoundException e) {
        app_installed = false;
    }
    return app_installed ;
}

} }

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

相关问题 通过单击浏览器或邮件应用程序中的链接,在Android中未安装应用程序时打开Play商店 - open play store when app not installed in android by clicking the link from browser or mail App 由于Google Play服务8.3.0,无法从Play商店安装Android应用 - Android app can not be installed from the play store because of Google Play Services 8.3.0 应用:从官方Google Play商店安装还是从磁盘安装? - App: installed from official Google Play Store or from disk? Android:安装APK后从Play商店重定向到Android应用 - Android: Redirect to android app from play store when apk is installed 对于在Android上进行的应用内购买,是否必须从Google Play安装该应用? - For in app purchases on Android, does the app have to be installed from Google Play? 从 Google Play 商店安装应用程序时崩溃 - App is crashing when installed from Google Play store PiracyChecker 无法检查应用程序是否从 Google Play 商店安装 - PiracyChecker fails to check whether the app is installed from Google Play Store 从浏览器重定向到Android应用 - redirecting to Android app from browser 如果未安装应用,请启动Google Play商店 - Launch google play store if app is not installed 从Play商店安装应用程序时,Android BroadcastReceiver无法正常工作 - Android BroadcastReceiver not working when app is installed from play store
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM