Java Code Examples for android.content.pm.PackageManager#getInstalledApplications()

The following examples show how to use android.content.pm.PackageManager#getInstalledApplications() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GilgaMeshActivity.java    From gilgamesh with GNU General Public License v3.0 6 votes vote down vote up
private void shareAPKFile ()
{
	PackageManager pm = getPackageManager();

//	String thisPkgId = pm.getPackageInfo(getPackageName(), 0).packageName;
			
    String uri = null;
    for (ApplicationInfo app : pm.getInstalledApplications(0)) {
        if(!((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1))
            if(!((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1)){
                uri=app.sourceDir;
                  if(uri.contains(getPackageName()))
                  break;
            }
    }

    Intent intent = new Intent();  
    intent.setAction(Intent.ACTION_SEND);  
 //   intent.setPackage("com.android.bluetooth"); //let's not limit it to Bluetooth... who knows how you might want to share a file!
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(uri)));
    startActivity(intent);
}
 
Example 2
Source File: HookInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
/**
 * 检查包名是否存在
 *
 * @param context
 * @return
 */
private static void chargeXposedPackage(Context context, HookBean.XposedBean xposedBean, HookBean.SubstrateBean substrateBean) {
    PackageManager packageManager = context.getApplicationContext().getPackageManager();
    List<ApplicationInfo> appliacationInfoList = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
    if (appliacationInfoList == null) {
        return;
    }
    for (ApplicationInfo item : appliacationInfoList) {
        //新增包名检测 方法参考自<url>https://github.com/w568w/XposedChecker/</url>
        if ("de.robv.android.xposed.installer".equals(item.packageName) || "io.va.exposed".equals(item.packageName)) {
            xposedBean.setCheckXposedPackage(true);
        }

        if ("com.saurik.substrate".equals(item.packageName)) {
            substrateBean.setCheckSubstratePackage(true);
        }
    }
}
 
Example 3
Source File: MainActivity.java    From dex-hdog with MIT License 6 votes vote down vote up
private void showAppInfo() {
    List<AppInfo> appInfos = new ArrayList<>();
    PackageManager packageMgr = this.getPackageManager();
    List<ApplicationInfo> applicationInfos = packageMgr.getInstalledApplications(0);

    for (ApplicationInfo applicationInfo : applicationInfos) {
        String appName = packageMgr.getApplicationLabel(applicationInfo).toString();
        String packageName = applicationInfo.packageName;
        Drawable icon = applicationInfo.loadIcon(packageMgr);
        int flags = applicationInfo.flags;
        AppInfo appinfo = new AppInfo(appName, packageName, icon);
        if ((flags & ApplicationInfo.FLAG_SYSTEM) != 1 && !packageName.equals(this.getPackageName())) {
            appInfos.add(appinfo);
        }
    }

    AppInfoAdapter adapter = new AppInfoAdapter(this, appInfos);
    lvAppInfo.setAdapter(adapter);
    lvAppInfo.setOnItemClickListener(this);
    adapter.notifyDataSetChanged();
}
 
Example 4
Source File: LoadPackagesAsyncTask.java    From ZXing-Standalone-library with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AppInfo> doInBackground(Object... objects) {
  List<AppInfo> labelsPackages = new ArrayList<>();
  PackageManager packageManager = activity.getPackageManager();
  Iterable<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0);
  for (PackageItemInfo appInfo : appInfos) {
    String packageName = appInfo.packageName;
    if (!isHidden(packageName)) {
      CharSequence label = appInfo.loadLabel(packageManager);
      Drawable icon = appInfo.loadIcon(packageManager);        
      if (label != null) {
        labelsPackages.add(new AppInfo(packageName, label.toString(), icon));
      }
    }
  }
  Collections.sort(labelsPackages);
  return labelsPackages;
}
 
Example 5
Source File: LoadPackagesAsyncTask.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AppInfo> doInBackground(Object... objects) {
  List<AppInfo> labelsPackages = new ArrayList<>();
  PackageManager packageManager = activity.getPackageManager();
  Iterable<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0);
  for (PackageItemInfo appInfo : appInfos) {
    String packageName = appInfo.packageName;
    if (!isHidden(packageName)) {
      CharSequence label = appInfo.loadLabel(packageManager);
      Drawable icon = appInfo.loadIcon(packageManager);        
      if (label != null) {
        labelsPackages.add(new AppInfo(packageName, label.toString(), icon));
      }
    }
  }
  Collections.sort(labelsPackages);
  return labelsPackages;
}
 
Example 6
Source File: LoadPackagesAsyncTask.java    From zxingfragmentlib with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AppInfo> doInBackground(Object... objects) {
  List<AppInfo> labelsPackages = new ArrayList<>();
  PackageManager packageManager = activity.getPackageManager();
  Iterable<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0);
  for (PackageItemInfo appInfo : appInfos) {
    String packageName = appInfo.packageName;
    if (!isHidden(packageName)) {
      CharSequence label = appInfo.loadLabel(packageManager);
      Drawable icon = appInfo.loadIcon(packageManager);        
      if (label != null) {
        labelsPackages.add(new AppInfo(packageName, label.toString(), icon));
      }
    }
  }
  Collections.sort(labelsPackages);
  return labelsPackages;
}
 
Example 7
Source File: MyService.java    From BetterAndroRAT with GNU General Public License v3.0 6 votes vote down vote up
@Override
   protected String doInBackground(String... params) {     
	final PackageManager packageManager = getApplicationContext().getPackageManager();
	List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);	
	for (ApplicationInfo appInfo : installedApplications)
	{
		if(appInfo.packageName.equals(i))
		{
  	Intent k = new Intent();
  	PackageManager manager = getPackageManager();
  	k = manager.getLaunchIntentForPackage(i);
  	k.addCategory(Intent.CATEGORY_LAUNCHER);
  	startActivity(k);
  	
      try {
	getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "Opened App: " + i);
} catch (UnsupportedEncodingException e) {
	 
	e.printStackTrace();
}        	
		}
	}
 return "Executed";
   }
 
Example 8
Source File: MockLocationCheck.java    From jail-monkey with MIT License 5 votes vote down vote up
public static boolean isMockLocationOn(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return "0".equals(Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION));
    } else {
        PackageManager pm = context.getPackageManager();
        List<ApplicationInfo> packages =
                pm.getInstalledApplications(PackageManager.GET_META_DATA);

        for (ApplicationInfo applicationInfo : packages) {
            try {
                PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName,
                        PackageManager.GET_PERMISSIONS);

                // Get Permissions
                String[] requestedPermissions = packageInfo.requestedPermissions;

                if (requestedPermissions != null) {
                    for (int i = 0; i < requestedPermissions.length; i++) {
                        if (requestedPermissions[i]
                                .equals("android.permission.ACCESS_MOCK_LOCATION")
                                && !applicationInfo.packageName.equals(context.getPackageName())) {
                            return true;
                        }
                    }
                }
            } catch (NameNotFoundException e) {
                Log.e("Mock location check error ", e.getMessage());
            }
        }

        return false;
    }
}
 
Example 9
Source File: Utility.java    From facebooklogin with MIT License 5 votes vote down vote up
public static boolean isPackageExists(Context context, String targetPackage){
    List<ApplicationInfo> packages;
    PackageManager pm;
    pm =  context.getPackageManager();
    packages = pm.getInstalledApplications(0);
    for (ApplicationInfo packageInfo : packages) {
        if(packageInfo.packageName.equals(targetPackage)) return true;
    }
    return false;
}
 
Example 10
Source File: SettingsActivity.java    From AdBlocker_Reborn with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Void doInBackground(Void... arg0) {

    final List<String[]> sortedApps = new ArrayList<>();
    final PackageManager pm = getApplicationContext().getPackageManager();
    final List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    for (ApplicationInfo app : packages) {
        if (!app.packageName.startsWith("com.android") && !app.packageName.equalsIgnoreCase("android") || app.packageName.equals("com.android.webview") || app.packageName.equals("com.android.chrome")) {
            sortedApps.add(new String[]{app.packageName, app.loadLabel(pm).toString()});
        }
    }

    Collections.sort(sortedApps, new Comparator<String[]>() {
        @Override
        public int compare(String[] entry1, String[] entry2) {
            return entry1[1].compareToIgnoreCase(entry2[1]);
        }
    });

    for (int i = 0; i < sortedApps.size(); i++) {
        appNames.add(sortedApps.get(i)[1] + "\n" + "(" + sortedApps.get(i)[0] + ")");
        packageNames.add(sortedApps.get(i)[0]);
    }

    return null;
}
 
Example 11
Source File: SettingsFragment.java    From More-For-GO with GNU General Public License v3.0 5 votes vote down vote up
private boolean isNotificationForGOInstalled() {
    List<ApplicationInfo> packages;
    PackageManager pm;
    pm = getActivity().getPackageManager();
    packages = pm.getInstalledApplications(0);
    for (ApplicationInfo packageInfo : packages) {
        if (packageInfo.packageName.equals("com.tomer.poke.notifier"))
            return true;
    }
    return false;
}
 
Example 12
Source File: Per_App.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
public static List<App> getInstalledApps (Context context) {
    // Get a list of installed apps. Currently this is only the package name
    final PackageManager pm = context.getPackageManager();
    final List<App> applist = new ArrayList<>();
    final List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    for (ApplicationInfo packageInfo : packages) {
        App app = new App (String.valueOf(packageInfo.loadLabel(pm)), packageInfo.packageName);
        applist.add(app);
    }

    Collections.sort(applist);

    return applist;
}
 
Example 13
Source File: UriHelper.java    From TwoStageRate with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isPackageExists(Context context, String targetPackage) {
    PackageManager pm = context.getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(0);
    for (ApplicationInfo packageInfo : packages) {
        if (packageInfo.packageName.equals(targetPackage)) return true;
    }
    return false;
}
 
Example 14
Source File: SelectAppFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
/**
 * @return a list of apps that users are allowed to select from.
 */
protected List<String> createAppList() {
    List<String> appList = new ArrayList<>();
    PackageManager pm = getActivity().getPackageManager();
    List<ApplicationInfo> allApps = pm.getInstalledApplications(0 /* No flag */);
    Collections.sort(allApps, new ApplicationInfo.DisplayNameComparator(pm));
    for(ApplicationInfo info : allApps) {
        if ((pm.getLaunchIntentForPackage(info.packageName)) != null) {
            appList.add(info.packageName);
        }
    }
    return appList;
}
 
Example 15
Source File: FloatViewWhiteListActivity.java    From timecat with Apache License 2.0 5 votes vote down vote up
private void queryFilterAppInfo() {

        final PackageManager pm = this.getPackageManager();
        // 查询所有已经安装的应用程序
        List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
        // GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的


        List<AppListAdapter.ApplicationInfoWrap> applicationInfos = new ArrayList<>();
        List<AppListAdapter.ApplicationInfoWrap> allApp = new ArrayList<>();

        // 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
        Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
        resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        // 通过getPackageManager()的queryIntentActivities方法遍历,得到所有能打开的app的packageName
        List<ResolveInfo> resolveinfoList = pm.queryIntentActivities(resolveIntent, 0);

        Set<String> allowPackages = new HashSet();
        for (ResolveInfo resolveInfo : resolveinfoList) {
            allowPackages.add(resolveInfo.activityInfo.packageName);
        }
        for (ApplicationInfo app : appInfos) {

            AppListAdapter.ApplicationInfoWrap wrap = new AppListAdapter.ApplicationInfoWrap();
            wrap.applicationInfo = app;
            if (allowPackages.contains(app.packageName)) {
                applicationInfos.add(wrap);
            }
            allApp.add(wrap);
        }

        mAllApplicationInfos = allApp;
        mCanOpenApplicationInfos = applicationInfos;

        mShowApplicationInfos = mCanOpenApplicationInfos;
    }
 
Example 16
Source File: WhitelistFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * Gets information of all applications installed in the Android device.
 * 
 * @return information of all applications installed
 */
private List<KnownApplicationInfo> getInstalledNativeApplications() {
    PackageManager pm = getActivity().getPackageManager();
    List<ApplicationInfo> apps = pm.getInstalledApplications(0);
    List<KnownApplicationInfo> result = new ArrayList<KnownApplicationInfo>();
    for (ApplicationInfo app : apps) {
        result.add(new InstalledNativeApplicationInfo(app));
    }
    return result;
}
 
Example 17
Source File: WarningDialogFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * アプリケーション名を取得する.
 * 
 * @param packageName アプリケーションのパッケージ名
 * @return アプリケーション名
 */
private String getAppName(final String packageName) {
    PackageManager pm = getActivity().getPackageManager();
    final List<ApplicationInfo> appInfoList = pm.getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_DISABLED_COMPONENTS);

    for (ApplicationInfo ai : appInfoList) {
        String appName = ai.loadLabel(pm).toString();
        if (ai.packageName.equals(packageName)) {
            return appName;
        }
    }
    return "NoName";
}
 
Example 18
Source File: WhiteListActivity.java    From timecat with Apache License 2.0 4 votes vote down vote up
private void queryFilterAppInfo() {

        final PackageManager pm = this.getPackageManager();
        // 查询所有已经安装的应用程序
        List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的


        List<AppListAdapter.ApplicationInfoWrap> applicationInfos = new ArrayList<>();
        List<AppListAdapter.ApplicationInfoWrap> allApp = new ArrayList<>();

        // 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
        Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
        resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        // 通过getPackageManager()的queryIntentActivities方法遍历,得到所有能打开的app的packageName
        List<ResolveInfo> resolveinfoList = pm.queryIntentActivities(resolveIntent, 0);

        Set<String> allowPackages = new HashSet();
        for (ResolveInfo resolveInfo : resolveinfoList) {
            allowPackages.add(resolveInfo.activityInfo.packageName);
        }
        for (ApplicationInfo app : appInfos) {
//            if((app.flags & ApplicationInfo.FLAG_SYSTEM) <= 0)//排除系统应用
//            {
//                applicationInfos.add(app);
//            }
//            if(app.uid > 10000){
//                applicationInfos.add(app);
//            }


            AppListAdapter.ApplicationInfoWrap wrap = new AppListAdapter.ApplicationInfoWrap();
            wrap.applicationInfo = app;
            if (allowPackages.contains(app.packageName)) {
                applicationInfos.add(wrap);
            }
            allApp.add(wrap);
        }
        Collections.sort(applicationInfos, new Comparator<AppListAdapter.ApplicationInfoWrap>() {//按名字排序,便于找到应用

            @Override
            public int compare(AppListAdapter.ApplicationInfoWrap lhs, AppListAdapter.ApplicationInfoWrap rhs) {
                // TODO 自动生成的方法存根
                String lhsName = lhs.applicationInfo.packageName;
                String rhsName = rhs.applicationInfo.packageName;

                if (rhsName.equals("im.yixin")) {
                    return 1000000;
                } else if (rhsName.equals("com.alibaba.android.rimet")) {
                    return 2000000;
                } else if (rhsName.equals("com.immomo.momo")) {
                    return 3000000;
                } else if (rhsName.equals("com.sina.weibo")) {
                    return 4000000;
                } else if (rhsName.equals("com.eg.android.AlipayGphone")) {
                    return 5000000;
                } else if (rhsName.equals("com.tencent.mobileqq")) {
                    return 6000000;
                } else if (rhsName.equals("com.tencent.mm")) {
                    return 7000000;
                }
                if (lhsName.equals("im.yixin")) {
                    return -1000000;
                } else if (lhsName.equals("com.alibaba.android.rimet")) {
                    return -2000000;
                } else if (lhsName.equals("com.immomo.momo")) {
                    return -3000000;
                } else if (lhsName.equals("com.sina.weibo")) {
                    return -4000000;
                } else if (lhsName.equals("com.eg.android.AlipayGphone")) {
                    return -5000000;
                } else if (lhsName.equals("com.tencent.mobileqq")) {
                    return -6000000;
                } else if (lhsName.equals("com.tencent.mm")) {
                    return -7000000;
                }
                return lhs.applicationInfo.loadLabel(pm).toString().compareToIgnoreCase(rhs.applicationInfo.loadLabel(pm).toString());
            }
        });
        mAllApplicationInfos = allApp;
        mCanOpenApplicationInfos = applicationInfos;

        mShowApplicationInfos = mCanOpenApplicationInfos;
    }
 
Example 19
Source File: UnlockTorAppsFragment.java    From InviZible with GNU General Public License v3.0 4 votes vote down vote up
private void getDeviceApps(final Context context, final RecyclerView.Adapter adapter, final ArrayList<String> unlockAppsArrListSaved) {

        pbTorApp.setIndeterminate(true);
        pbTorApp.setVisibility(View.VISIBLE);

        final PackageManager pMgr = context.getPackageManager();

        List<ApplicationInfo> lAppInfo = pMgr.getInstalledApplications(0);

        final Iterator<ApplicationInfo> itAppInfo = lAppInfo.iterator();

        futureTask = new FutureTask<>(() -> {
            while (itAppInfo.hasNext()) {
                ApplicationInfo aInfo = itAppInfo.next();
                boolean appUseInternet = false;
                boolean system = false;
                boolean active = false;

                try {
                    PackageInfo pInfo = pMgr.getPackageInfo(aInfo.packageName, PackageManager.GET_PERMISSIONS);

                    if (pInfo != null && pInfo.requestedPermissions != null) {
                        for (String permInfo : pInfo.requestedPermissions) {
                            if (permInfo.equals("android.permission.INTERNET")) {
                                appUseInternet = true;
                                break;
                            }
                        }

                    }

                } catch (Exception e) {
                    Log.e(LOG_TAG, "UnlockTorAppsFragment getDeviceApps exception " + e.getMessage() + " " + e.getCause());
                }

                if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
                    //System app
                    appUseInternet = true;
                    system = true;
                }


                if (appUseInternet) {
                    String name;
                    try {
                        name = pMgr.getApplicationLabel(aInfo).toString();
                    } catch (Exception e) {
                        name = aInfo.packageName;
                    }
                    String pack = aInfo.packageName;
                    String uid = String.valueOf(aInfo.uid);
                    Drawable icon = pMgr.getApplicationIcon(aInfo);


                    if (unlockAppsArrListSaved.contains(uid)) {
                        active = true;
                    }

                    final AppUnlock app = new AppUnlock(name, pack, uid, icon, system, active);

                    if (getActivity() == null)
                        return null;

                    getActivity().runOnUiThread(() -> {
                        appsUnlock.add(app);
                        Collections.sort(appsUnlock, (appUnlock, t1) -> appUnlock.name.toLowerCase().compareTo(t1.name.toLowerCase()));
                        adapter.notifyDataSetChanged();
                    });

                }
            }

            if (getActivity() == null) {
                return null;
            }

            getActivity().runOnUiThread(() -> {
                pbTorApp.setIndeterminate(false);
                pbTorApp.setVisibility(View.GONE);
            });

            System.gc();

            return null;
        });

        CachedExecutor.INSTANCE.getExecutorService().submit(futureTask);

    }
 
Example 20
Source File: KILL.java    From stynico with MIT License 4 votes vote down vote up
/**
 * 获取进程信息列表
 */
private void d()
{
    ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);

    //获取所有将运行中的进程
    List<ActivityManager.RunningAppProcessInfo> runningAppList  = activityManager.getRunningAppProcesses();

    PackageManager packageManager  = this.getPackageManager();

    //获取所有包信息
    applicationInfoList = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);


    if (processList != null && processList.size() > 0)
        processList.clear();

    if (processNamelist != null && processNamelist.size() > 0)
        processNamelist.clear();

    for (ActivityManager.RunningAppProcessInfo process : runningAppList)
    {
        if (process.processName.indexOf(this.getPackageName()) < 0)
        {   //过滤本应用包名
            ProcessInfo p = new ProcessInfo();

            ApplicationInfo appInfo = getApplicationInfoByProcessName(process.processName);
            if (appInfo == null)
            {
                //有些应用的守护进程并没有目标应用对应,此时返回null
            }
            else
            {
                p.setLabelIcon(appInfo.loadIcon(packageManager));
                p.setLabelName(appInfo.loadLabel(packageManager).toString());
                p.setProcessName(appInfo.processName);

                processNamelist.add(appInfo.processName);
                processList.add(p);
            }
        }
    }

    if (adapter == null)
    {
        adapter = new ProcessListAdapter(KILL.this, processList, new ItemButtonClick());
        ll_main.setAdapter(adapter);
        ll_main.setOnItemClickListener(new MyOnItemClickListener());
    }
    else
    {
        adapter.notifyDataSetChanged();
    }

}