0

I'd like to have some kind of prioritized app launch from a browser on android. Goal would be to : 1. launch app A if present 2. If not, but app B is present launch app B 3. If neither : redirect to app A in google play store

Thanks.

Skrew
  • 1,492
  • 14
  • 15

2 Answers2

1

You can use below function to open an application from it's package name

    public void runApp(String appName) throws IllegalArgumentException {
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    for ( ResolveInfo info : getPackageManager().queryIntentActivities( mainIntent, 0) ) {
        if ( info.loadLabel(getPackageManager()).equals(appName) ) {
            Intent launchIntent = getPackageManager().getLaunchIntentForPackage(info.activityInfo.applicationInfo.packageName);
            startActivity(launchIntent);
            return;
        }
    }
    throw new IllegalArgumentException("Application not found!");
}
Rakshit Nawani
  • 2,490
  • 12
  • 25
0

Yes it is possible. First of all make you app browsable via intent.

<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="yourapp.com" android:path="/get/" />
</intent-filter>

Now you can go to this app directly from browser. Add a landing page with simple script like

<script>
    if( navigator.userAgent.match(/android/i) ) {    
        // redirect to the Play store    
    } else if( navigator.userAgent.match(/iPhone/i) ) {    
        // redirect IOS store    
    }
</script>

Now you can redirect the user to app if it is installed or in you case now to another app then to the playstore.

<a href="http://yourapp.com/get/"/>

More details are here.

Rajan Kadeval
  • 249
  • 1
  • 2
  • 9