0

This is what i have now. It is checking to see if GoLauncher is installed and if it is, it takes it to the go launcher main screen. If its not installed it takes user to market to have it installed.

What i need though is that if it is installed already i need to pop up a alert box showing the user how to install the theme. After user hits okay then it should go to GoLaunhcer main screen

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();
            }
        }

    });

Added your updated code and now getting this error.. !1

BigDX
  • 3,519
  • 5
  • 38
  • 52

1 Answers1

0

Look at the answer to Detect an application is installed or not? That explains how to query the PackageManager to find out if your app is already installed.

EDIT: Add code

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;
}
Community
  • 1
  • 1
David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • That part of it is working. I just wanted to display a message if it is before it actually starts the activity – BigDX Jun 20 '12 at 17:13
  • You can use a toast. Or you can put up a dialog, then when the user dismisses the dialog, you can use that event to actually start the activity. – David Wasser Jun 20 '12 at 17:15
  • So what do you need help on? Your code that you posted shows that you already know how to put up a dialog? – David Wasser Jun 20 '12 at 17:16
  • I wanted to add another dialog. Right now the dialog shows up if the user does not have go launcher installed asking if they want to install it. I need a dialog to come up if it IS installed so the user knows how to install. – BigDX Jun 20 '12 at 17:23
  • thanks for you help.. update my post with image of error im getting – BigDX Jun 20 '12 at 17:50
  • Sorry, missed a ")" in this line: `if (isAppInstalled("com.gau.go.launcherex"))`. I edited my code again. Just add the missing ")" at the end of the "if" statement – David Wasser Jun 20 '12 at 17:54
  • okay, got that and installed it BUT its saying its not installed.. I know its installed because it was working before. any ideas? – BigDX Jun 20 '12 at 18:03
  • its just going to the "else" alert dialog box saying go not found – BigDX Jun 20 '12 at 18:04
  • it give no info in logcat once i press the button gralloc : Allocated 0x660072 size 6488161 that is all that comes up – BigDX Jun 20 '12 at 18:11
  • Try replacing PackageManager.GET_ACTIVITIES with 0 like this: `pm.getPackageInfo(uri, 0);` – David Wasser Jun 20 '12 at 18:12
  • sorry didnt have the private boolean as you had it.. trying again – BigDX Jun 20 '12 at 18:14