如何使用回调意图从Android中的应用程序打开Goog​​le Play商店?

时间:2016-04-22 03:40:57

标签: android

我正在开发一个包含应用程序列表的应用程序,我要做的是当用户从列表中点击特定应用程序时,他将被重定向到谷歌游戏商店并在此之后下载该应用程序,如果成功下载显示吐司并且如果然后在我的应用程序中显示错误的Toast消息。为了对此我使用Intent进行回调,但我不知道如何回拨。请帮助我。

这是我的代码: -

Uri uri = Uri.parse("https://play.google.com");// sending to Deal Website
            Intent i = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(i);

2 个答案:

答案 0 :(得分:1)

您可以使用startActivityForResult方法

try 
{
  Intent viewIntent = new Intent("android.intent.action.VIEW",
  Uri.parse("https://play.google.com/store/apps/details?id=your.app.id.here"));
  startActivityForResult(viewIntent, 1);
}
catch(Exception e) 
{
  Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...",Toast.LENGTH_LONG).show();
  e.printStackTrace();
}

使用onActivityresult方法获取结果

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) 
{
   super.onActivityResult(requestCode, resultCode, data);
   switch (requestCode) {
        case (1):
            if (resultCode == Activity.RESULT_OK) 
            {
               //Do your stuff here
            }
}

答案 1 :(得分:0)

您想要使用

market://details?id=<package_name>

而不是

http://play.google.com/store/apps/details?id=<package_name>

作为链接到应用的网址。