Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Accessing another apps by listing installed applicatoins in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 304
    Comment on it

    This tutorial is for getting the list of installed apps in your android devices. The information we reterive with the currently installed apps in a device using  PackageManager class. We will get the instance of this class by calling getPackageManager(), which provide the information on the application packages that are currently the part of device. Below the LoadApplication AsyncTask class implemented in a UI thread. We executing a progress dialog at onPreExecute method, in background we get the list of installed apps and loading that list to recycler view in onPostExecute.

    private class LoadApplications extends AsyncTask<Void, Void, Void> {
            private ProgressDialog progress = null;
    
     	@Override
            protected void onPreExecute() {
                progress = ProgressDialog.show(AppsList.this, null, "Loading application info...");
                super.onPreExecute();
            }
    
            @Override
            protected Void doInBackground(Void... params) {
    
                applist = checkForLaunchIntent(packageManager.getInstalledApplications(PackageManager.GET_META_DATA));
                listadaptor = new ApplicationAdapter(AppsList.this, applist);
    
                return null;
            }
    
            @Override
            protected void onCancelled() {
                super.onCancelled();
            }
    
            @Override
            protected void onPostExecute(Void result) {
                mRecyclerView.setAdapter(listadaptor);
                progress.dismiss();
                super.onPostExecute(result);
            }
    
            @Override
            protected void onProgressUpdate(Void... values) {
                super.onProgressUpdate(values);
            }
        }

    This list having application information to launch particular app. Using getLaunchIntentForPackage() method we can get the app having its launcher activity by getting its catagory tag inside intent-filter. It will return null if package name not found or having no launcher/main activity.

    private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) {
            ArrayList<ApplicationInfo> applist = new ArrayList<ApplicationInfo>();
            for (ApplicationInfo info : list) {
                try {
                    if (packageManager.getLaunchIntentForPackage(info.packageName) != null) {
                        applist.add(info);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return applist;
    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: