2016-11-02 290 views
0

什麼是字符串uri從我的應用程序打開ola應用程序?如何從我的應用程序打開ola應用程序?

我已經試過這

try { 
    pm.getPackageInfo("com.olacabs.customer",PackageManager.GET_ACTIVITIES); 
} catch (PackageManager.NameNotFoundException e) { 
    try { 
     getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.olacabs.customer"))); 
    } catch (android.content.ActivityNotFoundException anfe) { 
     getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.olacabs.customer"))); 
    } 
} 

回答

0
Uri uri = Uri.parse("market://details?id=com.olacabs.customer"); 
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); 

    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | 
        Intent.FLAG_ACTIVITY_NEW_DOCUMENT | 
        Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
    try { 
     startActivity(goToMarket); 
    } catch (ActivityNotFoundException e) { 
     startActivity(new Intent(Intent.ACTION_VIEW, 
       Uri.parse("http://play.google.com/store/apps/details?id=com.olacabs.customer"))); 
    } 

如果奧拉應用程序已經安裝,那麼你可以調用啓動這樣

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.olacabs.customer"); 
    if (launchIntent != null) { 
    startActivity(launchIntent);//null pointer check in case package name was not found 
    } 

最終代碼會是這樣: 終極密碼:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.olacabs.customer"); 
     if (launchIntent != null) { 
     startActivity(launchIntent);//null pointer check in case package name was not found 
     }else 
     { 
     Uri uri = Uri.parse("market://details?id=com.olacabs.customer"); 
     Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); 

     goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | 
        Intent.FLAG_ACTIVITY_NEW_DOCUMENT | 
        Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
     try { 
      startActivity(goToMarket); 
     } catch (ActivityNotFoundException e) { 
      startActivity(new Intent(Intent.ACTION_VIEW, 
       Uri.parse("http://play.google.com/store/apps/details?id=com.olacabs.customer"))); 
     } 
    } 
+0

謝謝你Ganesh它工作正常。 –

相關問題