0

这就是我现在所拥有的。它正在检查是否安装了 GoLauncher,如果是,它会将其带到 go 启动器主屏幕。如果未安装,则需要用户到市场才能安装。

我需要的是,如果它已经安装,我需要弹出一个警告框,向用户展示如何安装主题。用户点击 OK 后,它应该转到 GoLaunhcer 主屏幕

gosetting = (ImageButton) findViewById(R.id.gosetting);
    gosetting.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setComponent(new ComponentName("com.gau.go.launcherex","com.jiubang.ggheart.apps.desks.diy.GoLauncher"));
                startActivity(intent);
            } 
            catch (ActivityNotFoundException e) {
                AlertDialog.Builder alert = new AlertDialog.Builder(HelperActivity.this);
                alert.setTitle("GO Not Found");
                alert.setMessage("Do you want to vist the GO Launcher Android Market page?");
                alert.setIcon(R.drawable.go_icon2);
                alert.setPositiveButton("Yes",
                 new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                      final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("market://details?id=com.gau.go.launcherex"));
                      startActivity(intent);
                  }
                 });
                alert.setNegativeButton("No",
                 new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                      return;
                  }
                 });

                alert.show();

            } catch (Exception go) {
                go.printStackTrace();
            }
        }

    });

添加了您更新的代码,现在收到此错误..!1

4

1 回答 1

0

看看Detect an application is installed or not的回答?这解释了如何查询 PackageManager 以了解您的应用程序是否已安装。

编辑:添加代码

public void onClick(View v) {
    if (isAppInstalled("com.gau.go.launcherex")) {
        // Show dialog about installing the theme
        AlertDialog.Builder alert = new AlertDialog.Builder(HelperActivity.this);
        alert.setTitle("GO Theme installer");
        alert.setMessage("You need to install the theme like this...");
        alert.setIcon(R.drawable.go_icon2);
        alert.setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                  // Here actually start the GoLauncher
                  final Intent intent = new Intent(Intent.ACTION_MAIN);
                  intent.setComponent(new ComponentName("com.gau.go.launcherex","com.jiubang.ggheart.apps.desks.diy.GoLauncher"));
                  startActivity(intent);
              }
             });
        alert.show();
    } else {
        // Here you put up the dialog about visitng the market page
        AlertDialog.Builder alert = ...
    }
}

private boolean isAppInstalled(String uri) {
    PackageManager pm = getPackageManager();
    boolean installed = false;
    try {
       pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
       installed = true;
    } catch (PackageManager.NameNotFoundException e) {
       installed = false;
    }
    return installed;
}
于 2012-06-20T17:02:53.703 回答