Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Perform different operations using package name in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 274
    Comment on it

    1) If your requirement is to get app icon from package name then below few lines of code will be helpful for you.

    try
        {
           Drawable app_icon = getPackageManager().getApplicationIcon("PACKAGE_NAME");
           my_imageView.setBackgroundDrawable(app_icon);
        }
        catch (PackageManager.NameNotFoundException e)
        {
            return;
        }
    

    2) To launch particular app knowing only its package name

    PackageManager pm = context.getPackageManager();
    Intent launchIntent = pm.getLaunchIntentForPackage("PACKAGE_NAME");
    
    	if (launchIntent != null) {
    
    	    context.startActivity(launchIntent);
    	} else {
    
    	    Toast.makeText(context, "Package not found", Toast.LENGTH_SHORT).show();
    	}

    3) We can get last updated time of particular app.

    try {
    		packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    	} catch (PackageManager.NameNotFoundException e) {
    		e.printStackTrace();
    	}
    
    	lastUpdateTime = packageInfo.lastUpdateTime;
    	elapsed = ((System.currentTimeMillis() - lastUpdateTime) / 1000);
    	
    	lastUpdateTotalTime = String.format("%02d:%02d:%02d", elapsed / 3600, (elapsed % 3600) / 60, (elapsed % 60));
    	Log.d("Last Update Time:",lastUpdateTotalTime);

    4) We can get list of activities used in application using package name

     try {
             PackageInfo pi = getPackageManager().getPackageInfo("PACKAGE_NAME", PackageManager.GET_ACTIVITIES);
    
             mActivities = new ArrayList<ActivityInfo>(Arrays.asList(pi.activities));
    
         } catch (PackageManager.NameNotFoundException e) 
         {
             return;
         }

     

 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: