开发者

get information of install app in 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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜