Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

I am launching android app from browser. 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.

How can I achieve that?

like image 290
Anil kumar Avatar asked Nov 30 '25 02:11

Anil kumar


1 Answers

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. 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):

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:

<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.

like image 71
Eric Woodruff Avatar answered Dec 02 '25 15:12

Eric Woodruff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!