gpt4 book ai didi

android - 查看是否安装了应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:02:51 27 4
gpt4 key购买 nike

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

最佳答案

这个问题已得到解答 here .您可以使用以下代码来检查包名称

com.facebook.android OR 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 ;
}
}

关于android - 查看是否安装了应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17373135/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com