【问题标题】:Find out if app is installed查看是否安装了应用程序
【发布时间】:2013-06-26 17:23:16
【问题描述】:

我认为这个问题说明了一切:找出用户是否在他的手机上安装了 Facebook 或 Whatsapp 的最佳方法是什么?我是否必须检查包裹或最好的方法是什么?

【问题讨论】:

标签: android facebook package whatsapp


【解决方案1】:

这个问题已回答here。您可以使用以下代码检查包名

com.facebook.android 或 com.facebook.katana

代码:

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.facebook.android");  
            if(installed)
            {
            //This intent will help you to launch if the package is already installed
            Intent LaunchIntent = getPackageManager()
                .getLaunchIntentForPackage("com.facebook.android");
        startActivity(LaunchIntent);


                      System.out.println("App already installed om your phone");


            }
            else
            {
                System.out.println("App is not installed om your phone");
            }
        }
        private boolean appInstalledOrNot(String uri)
        {
            PackageManager pm = getPackageManager();
            boolean app_installed = false;
            try
            {
                   pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
                   app_installed = true;
            }
            catch (PackageManager.NameNotFoundException e)
            {
                   app_installed = false;
            }
            return app_installed ;
    }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    相关资源
    最近更新 更多