2017-09-07 31 views
0

私はAmazonのアプリケーションをプログラムで開こうとしていますが、それが電話で見つからない場合、ユーザーはプレイストアからインストールするように求められますが、問題はプレイストアで開くときに表示されていることですItem not foundエラーです。プレイストアで「Amazon」アプリをプログラムで開くにはどうすればいいですか?

は、ここに私のコードです:

public void openApp(final String packageName, final String appName) { 
     Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(packageName); 
     if (intent != null) { 
      startActivity(intent); 
     } else { 
      AlertDialog.Builder builder; 
      builder = new AlertDialog.Builder(MainActivity.this); 
      builder.setMessage(appName + " not found. Would you like to install " + appName + " from play store?") 
        .setPositiveButton("YES", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          try { 
           startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName))); 
          } catch (android.content.ActivityNotFoundException anfe) { 
           startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName))); 
          } 
         } 
        }) 
        .setNegativeButton("NO", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 

         } 
        }) 
        .show(); 
     } 
    } 

packageNamein.amazon.mShop.android.shoppingあるとappNameAmazonです。

私はここで間違って何が起こっている、アプリのplaystoreのリンクから、すなわち、https://play.google.com/store/apps/details?id=in.amazon.mShop.android.shopping&hl=en

をパッケージ名を持っているし、どのデバイスでI playstoreに成功したオープンアマゾンアプリを見つけたことができない場合は?

+1

私はちょうどあなたのコードでチェックして、私のためにPlayストアのamazonアプリを読み込みます。ここに投稿したのと同じパッケージ名を渡してもよろしいですか?すなわちin.amazon.mShop.android.shopping?そこにタイプミスがないことを確認してください。 –

+0

@ sam_0829私の別の愚かな間違い。ありがとう! –

答えて

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

     return false; 
    } 

アプリがインストールされている見つけたりしないようにこのメソッドを使用し、次いで

ブールisAppInstalled = appInstalledOrNot( "com.check.application")。

if(isAppInstalled) { 
     //This intent will help you to launch if the package is already installed 
     Intent LaunchIntent = getPackageManager() 
      .getLaunchIntentForPackage("com.check.application"); 
     startActivity(LaunchIntent); 

     Log.i("Application is already installed.");  
    } else { 
     // Do whatever we want to do if application not installed 
     // For example, Redirect to play store 

     Log.i("Application is not currently installed."); 
    } 
関連する問題