2012-06-20 94 views
0

這就是我現在所擁有的。它正在檢查GoLauncher是否已安裝,如果是,它會將其帶到啓動器主屏幕。如果未安裝它,則需要用戶上市才能安裝它。需要提醒對話框在我的活動開始之前

但我需要的是,如果它已經安裝,我需要彈出一個警告框,顯示用戶如何安裝主題。用戶點擊後,沒關係那麼它應該去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

回答

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; 
} 
+0

它的部分工作。如果在實際開始活動之前,我只想顯示一條消息 – BigDX

+0

您可以使用祝酒。或者你可以建立一個對話框,然後當用戶關閉對話框時,你可以使用該事件來真正開始活動。 –

+0

那麼你需要什麼幫助?你發佈的代碼表明你已經知道如何建立一個對話框? –

相關問題