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.
Related
I want to get list of all the apps installed in android phone. By following code I am able to get only user installed apps but I want to get system apps too.
packageManager = getPackageManager();
List<PackageInfo> packageList = packageManager.getInstalledPackages(packageManager.GET_PERMISSIONS);//PackageManager.GET_META_DATA
List<PackageInfo> packageList1 = new ArrayList<PackageInfo>();
PackageManager pm = this.getPackageManager();
/*To filter out System apps*/
for(PackageInfo pi : packageList) {
boolean b = isSystemPackage(pi);
if(!b) {
packageList1.add(pi);
}
}
apkList = (ListView) findViewById(R.id.AppList);
apkList.setAdapter(new ApkAdapter(this, packageList1, packageManager));
apkList.setOnItemClickListener(this);
}
private boolean isSystemPackage(PackageInfo pkgInfo) {
return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true
: false;
}
Try this:
final PackageManager pm = getActivity().getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> apps = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
Hope it will helps you..!
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.
i have tried the code i pasted below ..but that gives me every application installed but then i need to check each of the app is mine or not by checking with the package name...Is there a code to where i can pass the package name to the phone system so that it gives me all the apps installed based on that package name.
PackageManager manager = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_DEFAULT);
final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
ArrayList<String> oArrInstalledHomeApps = new ArrayList<String>();
if (apps != null)
{
final int count = apps.size();
for (int i = 0; i < count; i++)
{
ResolveInfo info = apps.get(i);
String strpackageName = info.activityInfo.applicationInfo.packageName;
if(strpackageName.contains ("com.ZZ."))
{
oArrInstalledHomeApps.add(strpackageName);
}
}
return oArrInstalledHomeApps;
}
Theres a cleaner way to do that.
final PackageManager pm = getPackageManager();
ArrayList<String> oArrInstalledHomeApps = new ArrayList<String>();
// get a list of installed apps.
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));
if (packageInfo.packageName.contains("com.ZZ."))
{
oArrInstalledHomeApps.add(packageInfo.packageName);
}
}
return oArrInstalledHomeApps;
Copied shamelessly from this link
I want list of all applications installed on the device which use a specific permission like INTERNET.
i am using this code , but not able to retrieve results , please help .
private ArrayList<String> getInstalledApps(Context context) {
ArrayList<String> results = new ArrayList<String>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> applist = packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it = applist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.INTERNET, pk.packageName))
results.add("" + pk.applicationInfo.loadLabel(packageManager));
}
for (int i = 0; i <= results.size(); i++) {
Log.v("app using internet = ", results.toString());
}
return results;
}
I tried the code on android 2.2 emulator and it was working fine. Following is the working code:
private ArrayList<String> getInstalledApps(Context context) {
ArrayList<String> results = new ArrayList<String>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> applist = packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it = applist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
Log.v("system app using internet = ", ""+pk.applicationInfo.loadLabel(packageManager));
continue;
}
if (PackageManager.PERMISSION_GRANTED == packageManager
.checkPermission(Manifest.permission.INTERNET,
pk.packageName))
results.add("" + pk.applicationInfo.loadLabel(packageManager));
}
Log.v("app using internet = ", results.toString());
return results;
}
i had the same scenario, i solved it using the following check
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
if (PackageManager.PERMISSION_GRANTED != pm.checkPermission(Manifest.permission.INTERNET, p.packageName)) {
continue;
}
the packs variable is a array of class that holds information about the application installed and it consists of the objects with info of all the applications currently installed in system
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.