3

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?

jyomin
  • 1,957
  • 2
  • 11
  • 27
Anil kumar
  • 1,534
  • 3
  • 14
  • 20
  • What is the url you are using to launch you're app from the browser? – Dylan Watson Mar 18 '14 at 09:12
  • Possible duplicate of [Android - redirect to store if app not installed (launch from website)](https://stackoverflow.com/questions/13518453/android-redirect-to-store-if-app-not-installed-launch-from-website) – rds Jun 15 '17 at 12:12

5 Answers5

3

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.

Eric Woodruff
  • 6,380
  • 3
  • 36
  • 33
  • From the link "This works in the Chrome for Android browser, version 18 and earlier. It also works in the Android browser, of course." Though the "and earlier" part is confusing, I think it means to say "and later". It works on my phone with Chrome 33. – Eric Woodruff Mar 19 '14 at 15:40
0

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. If app is present - it navigates away. If app is not present - next continue to open the google play link.

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

Amit
  • 124
  • 10
0

If you need to redirect the link to play store if app is not installed then try firebase dynamic link. Try this url. https://firebase.google.com/docs/dynamic-links

-1

I would use the URL https://play.google.com/store/apps/details?id=com.anil.myapp on the webpage. 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. 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.

Josh
  • 10,618
  • 2
  • 32
  • 36
-3

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 ;
}

}

Shadow
  • 6,864
  • 6
  • 44
  • 93
  • code is here, it's your choice where to use it.when you click on button or when you launch your app @Anilkumar – Shadow Mar 05 '14 at 07:36
  • 1
    @Shadow.. ya fine... Thanks for code... But I am launching app from browser on clicking link myapp://myhostname , & requirement is like app is not in device. So I cant use anywhere in code.. Hope you understood the situation... – Anil kumar Mar 05 '14 at 07:40
  • The question requires an answer with some intent filter magic or some html/javascript for the web page. – Eric Woodruff Mar 18 '14 at 22:30