如何获得APK的应用程序名称编程(未安装) [英] How to get the application name of the APK programmatically (not installed)

查看:103
本文介绍了如何获得APK的应用程序名称编程(未安装)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据<一href="http://stackoverflow.com/questions/7802780/how-to-get-the-name-of-the-application-in-android">How获取应用程序的名称,在Android中?。

我有这样的片段。 `andPath |是APK的位置。

I have this snippet. `andPath| is the location of the APK.

PackageInfo info = getPackageManager().getPackageArchiveInfo(andPath, 0);
ApplicationInfo appinfo = info.applicationInfo;
String packageName = getPackageManager().getApplicationLabel(appinfo).toString();

PackageManager pm=getPackageManager();
ApplicationInfo ai;
try {
     ai = pm.getApplicationInfo(packageName, 0);
} catch (final NameNotFoundException e) {
     ai = null;
}

final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");

的applicationName 返回我的包名。

CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName,PackageManager.GET_META_DATA));

C 返回我

有谁知道我在这里失踪了什么?

Does anyone know what I'm missing here?

推荐答案

如果您在这里有一个问题,我发布了全code,以获得应用程序的名称

if you have a problem here i post the full code to get the application name

的回报ApplicationInfo

public List<ApplicationInfo> getApplicationList(Context con){
        PackageManager p = con.getPackageManager(); 
        List<ApplicationInfo> info = p.getInstalledApplications(0);
        return info;
    }

返回应用程序名称

public String applicationLabel(Context con,ApplicationInfo info){
        PackageManager p = con.getPackageManager();
        String label = p.getApplicationLabel(info).toString();
        return label;
    }

您的onCreate函数粘贴低于code

List<ApplicationInfo> info = new ArrayList<ApplicationInfo>();

        info = list.getApplicationList(this);
        LinearLayout layout = (LinearLayout)findViewById(R.id.content);
        layout.setOrientation(1);
        int size = info.size();
        Log.d("size",String.valueOf(size));
        for(int i=0;i<size;i++){
            Log.d("Val of I",String.valueOf(i));
            String appname = list.applicationLabel(this,info.get(i)).toString();
            Log.d("AppName",appname);
            TextView tv = new TextView(this);
            tv.setText(appname);
            layout.addView(tv);
        }

    }

这篇关于如何获得APK的应用程序名称编程(未安装)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆