I defined a description for a activity with attribute "android:description"
how to get it programally?
i've tried this code:
PackageManager pm = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN);
mainIntent.addCategory(CATEGORY);
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
for (int i = 0; i < len; i++) {
ResolveInfo info = list.get(i);
String desc = "";
try {
desc = res.getString(info.activityInfo.descriptionRes);
} catch(NotFoundException e) {
desc = info.activityInfo.name;
}
}
this code throws a NotFoundException.
I have watched the value in debug mode, the param "descriptionRes" did have a int value.
how to get the description? great regards if any help.
Related
I need get app's names but without local language, only in original language.
I'm from Poland and I need apps names list in original ENGLISH!
I have that code:
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
final List<ResolveInfo> activities = packageManager.queryIntentActivities( intent, 0 );
final int size = activities.size();
for (int i = 0; i < size; i++){
final ResolveInfo info = activities.get(i);
final String label = info.loadLabel(packageManager).toString();
final String pkgName = info.activityInfo.packageName;
final String className = info.activityInfo.name;
Log.d("INFO", label);
}
You can use getResourcesForApplication() from package manager. You can set resource culture and get values.
Please check the code below
PackageManager packageManager = getPackageManager();
final String packageName = "com.android.wallpaper.livepicker";
try {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
if (null != applicationInfo) {
CharSequence label = packageManager.getApplicationLabel(applicationInfo);
Log.d("MyTag", "Default app label is " + label);
Configuration configuration = new Configuration();
configuration.setLocale(new Locale("en"));
Resources resources = packageManager.getResourcesForApplication(packageName);
resources.updateConfiguration(configuration, getBaseContext().getResources().getDisplayMetrics());
String localizedLabel = resources.getString(applicationInfo.labelRes);
Log.d("MyTag", "Localized app label is " + localizedLabel);
}
} catch (PackageManager.NameNotFoundException e) {
Log.e("MyTag", "Failed to obtain app info!");
}
I use code as follow to share image to twitter but when display screen of twitter app to input text and image,it only display text ,image don't display.
public void shareImageByTwitter(Context mContext, String path) {
File myFile = new File(path);
final String[] twitterApps = {
// package // name - nb installs (thousands)
"com.twitter.android", "com.twidroid",
"com.handmark.tweetcaster", "com.thedeck.android" };
Intent tweetIntent = new Intent();
tweetIntent.setType("image/jpeg");
tweetIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(myFile));
final PackageManager packageManager = mContext.getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(
tweetIntent,0);
for (int i = 0; i < twitterApps.length; i++) {
for (ResolveInfo resolveInfo : list) {
String p = resolveInfo.activityInfo.packageName;
if (p != null && p.startsWith(twitterApps[i])) {
tweetIntent.setPackage(p);
}
}
}
mContext.startActivity(tweetIntent);
}
How must I do.
How can I check that? Do i have to use PackageManager? Thank you :D
I check it this way (check if the returned value is unequal to null):
public static Intent findFacebookClient(Context con)
{
final String[] FacebookApps = {"com.facebook.android", "com.facebook.katana"};
Intent facebookIntent = new Intent();
facebookIntent.setType("text/plain");
final PackageManager packageManager = con.getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(facebookIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (int i = 0; i < FacebookApps.length; i++)
{
for (ResolveInfo resolveInfo : list)
{
String p = resolveInfo.activityInfo.packageName;
if (p != null && p.startsWith(FacebookApps[i]))
{
facebookIntent.setPackage(p);
return facebookIntent;
}
}
}
return null;
}
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package : " + packageInfo.packageName);
}
Then you can check if packageInfo.packageName is equal to some string which contains the package name of that application.
I am developing an application which show all current applications. I am getting the apps package names, thats good but not specific applications name How should I do it, I am using following code:
Context context = this.getApplicationContext();
ActivityManager mgr = (ActivityManager)context.getSystemService(ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = mgr.getRunningTasks(30);
List<ActivityManager.RunningAppProcessInfo> tasksP = mgr.getRunningAppProcesses();
int numOfTasks = tasks.size();
for(int i = 0; i < numOfTasks; i++){
ActivityManager.RunningAppProcessInfo task = tasksP.get(i);
PackageInfo myPInfo = null;
try {
myPInfo = getPackageManager().getPackageInfo(task.processName, 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
Toast.makeText(location.this,
task.processName,
Toast.LENGTH_LONG).show();
}
Also please tell me how to display these apps name in check boxes, so that I can kill my desired app.
Try this code for getting Installed Application in your phone :
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> pkgAppsList = this.getPackageManager().queryIntentActivities( mainIntent, 0);
List<String> componentList = new ArrayList<String>();
for (ResolveInfo ri : pkgAppsList) {
if (ri.activityInfo != null) {
String app_name=ri.activityInfo.loadLabel(getPackageManager()).toString();
Log.d("Apps Name", ""+ri.activityInfo.loadLabel(getPackageManager()).toString());
}
}
}
Check this Link for further Reference :
Installed Application Details
Intent filter = new Intent(Intent.ACTION_MAIN);
filter.addCategory(Intent.CATEGORY_LAUNCHER);
Context context = getApplicationContext();
PackageManager manager = getPackageManager();
List<ResolveInfo> infos = getPackageManager().queryIntentActivities(filter,0);
List<Intent> filters = new ArrayList<Intent>();
filters.add(filter);
ComponentName component = new ComponentName(context.getPackageName(), MainActivity.class.getName());
List<ComponentName> activities = new ArrayList<ComponentName>();
//ComponentName[] components = new ComponentName[] {new ComponentName("//com.neo.application", "com.neo.application.Application"), component};
try {
manager.getApplicationInfo(//PACKAGE_NAME);//just Ctrl+space it u'll get the package names.
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Basically, I want to get a list of all installed apps and pick one to run from an activity.
I've tried ACTION_PICK with Intents but that seems to leave out apps that were downloaded and it has a bunch of junk in it.
Thanks
// to get the list of apps you can launch
Intent intent = new Intent(ACTION_MAIN);
intent.addCategory(CATEGORY_LAUNCHER);
List<ResolveInfo> infos = getPackageManager().queryIntentActivities(intent, 0);
// resolveInfo.activityInfo.packageName = packageName
// resolveInfo.activityInfo.name = className
// reusing that intent
intent.setClassName(packageName, className);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(intent)
Hope that's enough to help you figure out.
final File favFile = new File(Environment.getRootDirectory(), DEFAULT_FAVORITES_PATH);
try {
favReader = new FileReader(favFile);
} catch (FileNotFoundException e) {
Log.e(LOG_TAG, "Couldn't find or open favorites file " + favFile);
return;
}//gives the path for downloaded apps in directory
private void loadApplications(boolean isLaunching) {
if (isLaunching && mApplications != null) {
return;
}
PackageManager manager = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
if (apps != null) {
final int count = apps.size();
if (mApplications == null) {
mApplications = new ArrayList<ApplicationInfo>(count);
}
mApplications.clear();
for (int i = 0; i < count; i++) {
ApplicationInfo application = new ApplicationInfo();
ResolveInfo info = apps.get(DEFAULT_KEYS_SEARCH_LOCAL);
application.title = info.loadLabel(manager);
application.setActivity(new ComponentName(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name),
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
application.icon = info.activityInfo.loadIcon(manager);
mApplications.add(application);
}
}
This will help u to load all the apps downloaded.