-2
如何檢查應用程序被安裝或沒有後點擊按鈕,如果從谷歌沒有安裝對話框顯示下載的應用程序發揮 的Java/Android的查找已安裝的應用程序或不併顯示對話框
如何檢查應用程序被安裝或沒有後點擊按鈕,如果從谷歌沒有安裝對話框顯示下載的應用程序發揮 的Java/Android的查找已安裝的應用程序或不併顯示對話框
public class Sample extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Put the package name here...
boolean installed = appInstalledOrNot("com.Ch.Example.pack");
if(installed) {
//This intent will help you to launch if the package is already installed
Intent LaunchIntent = getPackageManager()
.getLaunchIntentForPackage("com.Ch.Example.pack");
startActivity(LaunchIntent);
System.out.println("App is already installed on your phone");
} else {
System.out.println("App is not currently installed on your phone");
}
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}
}
這裏是方法。
private boolean isPackageInstalled(String packagename) {
PackageInfo info = null;
boolean isInstalled = false;
PackageManager pm = getPackageManager();
try {
info = pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
isInstalled = true;
} catch (Exception e) {
e.printStackTrace();
}
return isInstalled;
}
該方法將返回true或false.You可以調用它如下。
if(isPackageInstalled("Your package name")) {
/*Perform task when package is installed*/
}
這將幫助你。 http://stackoverflow.com/a/11392276/2784838 –
歡迎來到堆棧溢出。我非常感謝你的英語可能不是很好,但請閱讀http://stackoverflow.com/help/how-to-ask,尋求如何提出問題的幫助,以便人們能夠輕鬆理解並能夠給你答案你需要 – Mikkel