get information of install app in android - android

hello expert, i need build app that share mobile app to second mobile so that
i need know that how can i get all app information like : name,date,icon,etc.
package com.AppInfo;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
public class AppInfo extends Activity {
/** Called when the activity is first created. */
private ListView lView;
private ArrayList results = new ArrayList();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}}
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
// Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}

checkout this : http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon

Although the info you want can be retrieved using getInstalledPackages() and using PackageInfo
But as you want to share the app from one phone to another I dont think its possible atleast unless the device is rooted

C2MD is nice to send small amount of data and its fairly easy to implement. If you dont want to do that just send a sms to the other phone and have a receiver on the second mobile.

You can retrieve the information you need using the PackageManager, both ApplicationInfo and PackageInfo may be used.
private static final String TAG = "MyActivity";
...
final PackageManager pm = getPackageManager();
final List<ApplicationInfo> installedApps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for ( ApplicationInfo app : installedApps ) {
Log.d(TAG, "Package: " + app.packageName);
Log.d(TAG, "Directory: " + app.sourceDir);
Log.d(TAG, "Icon: " + app.icon);
try {
PackageInfo packageInfo = pm.getPackageInfo(app.packageName, PackageManager.GET_PERMISSIONS);
Date installTime = new Date( packageInfo.firstInstallTime );
Date updateTime = new Date( packageInfo.lastUpdateTime );
Log.d(TAG, "Installed: " + installTime.toString());
Log.d(TAG, "Updated: " + updateTime.toString());
Log.d(TAG, "Version: " + packageInfo.versionCode);
Log.d(TAG, "Name: " + packageInfo.versionName);
}
catch ( PackageManager.NameNotFoundException e ) {
e.printStackTrace();
}
}

Related

Is there a way to read the name of all the apps and their sizes installed in Android?

I was trying to see how much size my app is taking and log it.
I know I can check the size of folder where I store data but is there any way to know all apps installed and their size?
By using the packageManager you can get all installed apps
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(TAG,appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}

How to get installed package name in a list? [duplicate]

This question already has answers here:
How to get a list of installed android applications and pick one to run
(20 answers)
Closed 8 years ago.
I am new in android.I had to retrieve list of all installed application package names using the following code
List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
for(PackageInfo pack : packages)
{
ActivityInfo[] activityInfo = getPackageManager().getPackageInfo(pack.packageName, PackageManager.GET_ACTIVITIES).activities;
Log.i("Pranay", pack.packageName + " has total " + ((activityInfo==null)?0:activityInfo.length) + " activities");
if(activityInfo!=null)
{
for(int i=0; i<activityInfo.length; i++)
{
Log.i("PC",""+ activityInfo[i]);
myList = new ArrayList();
myList.add(pack.packageName);
}
aplist = new ArrayList<String>();
aplist.add(pack.packageName);
Toast.makeText(this, "list are "+aplist, Toast.LENGTH_LONG).show();
}
}
but it gets the packagename in diff toast. How Can I get all package name in a single list ??
Below helper function retrieves all installed apps with the application name, package name, version-number and -code as well as the icons. The method getPackages() returns an ArrayList with all the apps.
class PkgInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList<PkgInfo> getPackages() {
ArrayList<PkgInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
private ArrayList<PkgInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PkgInfo> res = new ArrayList<PkgInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PkgInfo newInfo = new PkgInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}
Hope this helps you.
Why are you initializing apList and myList variable in each iteration?.
Have a look at the modified code below which should solve your problem:
aplist = new ArrayList<String>();
List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
for(PackageInfo pack : packages)
{
ActivityInfo[] activityInfo = getPackageManager().getPackageInfo(pack.packageName, PackageManager.GET_ACTIVITIES).activities;
Log.i("Pranay", pack.packageName + " has total " + ((activityInfo==null)?0:activityInfo.length) + " activities");
if(activityInfo!=null)
{
for(int i=0; i<activityInfo.length; i++)
{
Log.i("PC",""+ activityInfo[i]);
if (myList != null)
myList = new ArrayList();
myList.add(pack.packageName);
}
aplist.add(pack.packageName);
}
}
Toast.makeText(this, "list are "+aplist, Toast.LENGTH_LONG).show();

Launcher Name Of Installed Apps

I have to get list of installed apps from android device . I am able to get the list. But there is some problem in getting the launcher name (which is defined in launcher activity tag in manifest not in application tag) of applications from the PackageInfo object. How to get the launcher name of installed apps from the PackageInfo object.??
I have tried in this way
packageInfo.applicationInfo.loadLabel(packageManager)
But this is not giving launcher name. It is giving the application tag string.
Use the following code to get the launcher activity of all packages:
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}
If you want the applications that handle the launcher, then you can look for applications that handle the intent filter Intent.CATEGORY_HOME with the PackageManager.

How to get the list of installed application from google play store in android?

i want the application list that is installed from google play or from any external storage, but not the pre installed system application.
i just use below code.....
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v("", "*** appname = " + appname + " *** \n" + " packagename = " + pname + "\n" + " version name = " + versionName + "\n" + " version code = " + versionCode + " \n\n\n\n");
}
}
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(true); /* false = no system packages */
final int max = apps.size();
int i = 0;
for (i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
Log.v(TAG, "Total APPs = "+i);
return apps;
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(PackageManager.GET_META_DATA);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}
but this code gives me information of system application also.....
can anybody know how to get only installed application except the installed system application ?
thanks....
To discover if your application is a system application you can use the following code:
PackageManager pm = getPackageManager();
List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);
for (ApplicationInfo aInfo: installedApps) {
if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
// system application
} else {
//user application
}
}
If you need to discover if an application is installed from a market you need to use the following method of Package: getInstallerPackageName. It will return the packageName of the application that installed your application.
public class AppList extends Activity {
private ListView lView;
private ArrayList results = new ArrayList();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lView = (ListView) findViewById(R.id.list1);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
results.add(rInfo.activityInfo.applicationInfo
.loadLabel(pm).toString());
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
.loadLabel(pm).toString());
}
lView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
}
}

how to make a list of installed apps clickable?

Okay i managed to make a button list all installed applications like this:
public void launcher(View v){
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
myMenu.this.startActivity(mainIntent);
So when I click the button a window pops up like a dialog and lists all the applications. However, when I click any of the applications the dialog closes and nothing happens. how can I make these applications clickable?
Code would be preferrable and I'm a noobie so please be specific in your answer.
Thanks! :)
Here i am give one example which basically get all information of all install app from your device.
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}

Categories

Resources