2

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; 
}
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133

4 Answers4

1

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

ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
1

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

Dinesh Sharma
  • 11,533
  • 7
  • 42
  • 60
0

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();
    }
}
Paolo Rovelli
  • 9,396
  • 2
  • 58
  • 37
0

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.

Pintac
  • 1,565
  • 3
  • 21
  • 38