I'm trying to develop an android app that could list all app's which has cache, I successfully got the information about cache, but now I want to display those app which has some cache in the screen, I have the package name, but problem is how to get the application name from package name,
Let's say package name is com.android.browser
then app name will be Browser
How to achieve this task ?
Please don't mind if this question is silly to you, please help me in solving this riddle,
Thanks in advance.
You need to use PackageManager to get detailed information about installed packages.
PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo = null;
try {
applicationInfo = packageManager.getApplicationInfo(packageName, 0);
} catch (final NameNotFoundException e) {}
final String title = (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???");
Try to use PackageManager#getActivityInfo();
There is field which contain app name.
Related
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage(getBaseContext().getPackageName());
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
After changing the language from inside the application, when I use this code in an unsigned APK then it will work fine.
But when I generate signed APK, the code above does not work.
Please help me with this.
There is no specific error provided, but my answer is based on the assumption that PackageManager.NameNotFoundException() is being thrown.
I cannot see the location of the code either, but I'm generally cautious about using getBaseContext(). You should be using getApplicationContext() to get the package information.
The app can get its own application ID like this:
Log.i(TAG, BuildConfig.APPLICATION_ID);
By default when you create an app in Android Studio, the package name and the application ID are identical. You could use this method if you are struggling for a solution.
Edit:
BuildConfig.APPLICATION_ID is now deprecated. Use the following instead:
BuildConfig.LIBRARY_PACKAGE_NAME
But most likely the problem can be solved by using the correct Context with the PackageManager rather than using BuildConfig.
Hello guys I am new to android core apps but I love to do animation stuffs in Android. But what I want is I want to start another another app using my application. For eg. I want to start facebook app using my application.
I dont know if the question is understood or not, but really need a clue on how to do such stuffs.
Thank you!!
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(launchIntent);
In your case, you should check this apps package names and replace them.
It wouldn't be a bad idea to check if it's installed first :
private boolean isPackageInstalled(String packagename, Context context) {
PackageManager pm = context.getPackageManager();
try {
pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
check android's developer document about: Intent
refer to Context:
startActivity
startService
sendBroadcast
It is possible to parse some information from the apk file using a tool as mentioned here:
How to parse the AndroidManifest.xml file inside an .apk package
My requirement is to parse information like Application name,description, image urls from a link like :
market://details?id=com.replica.replicaisland
Is there any standard way to parse this information without having the apk file ?
is there any RSS feed available based on the identifier "com.replica.replicaisland" ?
There is an open source library android-market-api created by some developers which allow you retrieve some basic app info directly from google's official android market, worth to check it out.
For the first thing you could just download the webpage from the web browser version of the link which would be https://market.android.com/details?id=com.replica.replicaisland
From there you could parse through the source of the page in your own creative way.
As with RSS feed, no clue.
You may want to check out PackageManager and ApplicationInfo to see if it has everything you need.
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
try {
ApplicationInfo appInfo = pm.getApplicationInfo(packageInfo.packageName, 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified();
Log.d(TAG, "lastModified = " + installed);
//Drawable icon = appInfo.loadIcon(pm);
//Bitmap bitmap = ((BitmapDrawable)icon).getBitmap();
}
catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
How could I write a code which can tell me that android market is installed on your android phone?
There are two ways. You can use the already mentioned getPackageManager() and getApplicationInfo() (if the package is not found, a PacketManager.NameNotFoundException will be thrown - see here). Android Market's package name is com.android.vending.
However, you can also create a dummy intent for searching the market and check how it is handled. If the resulting list has at least one entry, you can be sure that Android Market is installed:
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=dummy"));
PackageManager manager = getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(mmarket, 0);
Here's what I did (assumes browser exists):
Intent market = new Intent(Intent.ACTION_VIEW).setData(Uri
.parse("market://details?id=com.example.app"));
Intent website = new Intent(Intent.ACTION_VIEW).setData(Uri
.parse("http://play.google.com/store/apps/details?id=com.example.app"));
try {
startActivity(market);
} catch (ActivityNotFoundException e) {
startActivity(website);
}
I am using the following snippet to get the application name and icon of few of the APKs on my SD Card.
PackageInfo packageInfo = packageManager.getPackageArchiveInfo(apkPath, 0);
ApplicationInfo appInfo = packageInfo.applicationInfo;
Drawable appIcon = appInfo.loadIcon(packageManager);
String appName = appInfo.loadLabel(packageManager).toString();
I am able to access the package name but the loadIcon returns the default Android application icon for all the apks and the loadLabel returns the package name (Not the application label).
I also get the following warning messages in logcat:
Failure retrieving icon 0x7f020005 in package com.sample.radio
Failure retrieving text 0x7f050000 in package com.taskkiller.demo
I am running Android 2.2, any pointers will be appreciated. Thanks.
You may need to add two lines before creating appIcon, AppName:
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);
// NEW LINES
pi.applicationInfo.sourceDir = APKFilePath;
pi.applicationInfo.publicSourceDir = APKFilePath;
String AppName = (String)pi.applicationInfo.loadLabel(pm);
Drawable appIcon=pm.getApplicationIcon(pi.applicationInfo);