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)