如何检查编程如果应用程序在Android的安装或没有?应用程序、Android

由网友(笑叹红尘纷扰)分享简介:我们已经通过编程安装的应用程序。We have installed applications programmatically.如果该应用程序已经安装在设备中的应用程序会自动打开。否则安装特定的应用。指导我。我不知道。谢谢你。Guide Me. I have no idea.Thanks.推荐答案试试这个...

我们已经通过编程安装的应用程序。

We have installed applications programmatically.

如果该应用程序已经安装在设备中的应用程序会自动打开。 否则安装特定的应用。

指导我。我不知道。 谢谢你。

Guide Me. I have no idea. Thanks.

推荐答案

试试这个:

public class Example 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();
        boolean app_installed;
        try {
            pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            app_installed = true;
        }
        catch (PackageManager.NameNotFoundException e) {
            app_installed = false;
        }
        return app_installed;
    }
}
阅读全文

相关推荐

最新文章