利用包名查找本地存在的app(奶瓶)

2018-01-30  本文已影响0人  _奶瓶

一,查找包名

 public boolean PackageNames(Context context, String packageName) {  
      PackageManager pm = context.getPackageManager();  
  
    //获取本地的所有APP包名
    List<PackageInfo> packList = pm.getInstalledPackages(0);  
  //循环
    for (int i = 0; i < packList.size(); i++) {  
  //比对
        if (((PackageInfo) packList.get(i)).packageName  
                .equalsIgnoreCase(packageName))  
            return true;  
    }  
    return false;  
}  

  //判断使用
if(PackageNames(cloudListActivity.this,"com.tfboy.tf")){}

二,从A.app跳转到B.app

//要调用另一个APP的activity所在的包名
            String packageName = "com.np.uu.demo";
            //要调用另一个APP的activity名字,是你要跳转的Activity,不一定是主Activity
            String activity = "com.np.uu.demo.DemoMainActivity";
            
            ComponentName component = new ComponentName(packageName, activity);
            Intent intent = new Intent();
            intent.setComponent(component);
            intent.setFlags(101);
                    //key值对比
            intent.putExtra("vid", vid);
            intent.putExtra("authinfo", cl.getmsg());
            startActivity(intent);
上一篇下一篇

猜你喜欢

热点阅读