是进程名相同的Andr​​oid包名? [英] Is process name same as package name in android?

查看:219
本文介绍了是进程名相同的Andr​​oid包名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过过程中,我的意思是我们在提供安卓过程并通过包我的意思是包

 <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.osg.appkiller
    安卓版code =1
    机器人:=的versionName1.0>

更多细节进程和线程 - Android开发者

我想获得的所有正在运行的应用程序的名称。所以,这就是我在寻找各种来源(和它的作品)之后做了。

  ActivityManager activityManager =(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    软件包管理系统软件包管理系统= getPackageManager();
    最终名单< RunningAppProcessInfo> runningProcesses = activityManager.getRunningAppProcesses();
    对于(RunningAppProcessInfo processInfo:runningProcesses){
        CharSequence中的appName = NULL;
        尝试{
            的appName = packageManager.getApplicationLabel(packageManager.getApplicationInfo(processInfo.processName,PackageManager.GET_META_DATA));
        }赶上(ē的NameNotFoundException){
            Log.e(TAG,应用程序的信息没有发现过程:+ processInfo.processName,E);
        }
    }

如果您看到PackageManager.getApplicationInfo文档

  ApplicationInfo android.content.pm.PackageManager.getApplicationInfo(字符串的packageName,INT标志)抛出的NameNotFoundException

但我传递

  processInfo.processName

其中processName是进程运行的名字。所以,我们基本上都采用进程名作为包名获得应用程序信息。


  1. 首先是这种做法是否正确?

  2. 其次,这是真的,如果我们没有为活动/服务等提供了新的工艺过程与同名的包名的创建?


解决方案

在默认情况下采用的Andr​​oid作为进程名包名。但是,如果你在清单文件的应用程序标记来定义流程属性安卓过程=com.example.newprocessname则应用程序将使用该名称com.example.newprocessname运行

至于你的问题,

希望这回答您的问题!

By process I mean what we provide in android:process and by package I mean package in

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.osg.appkiller"
    android:versionCode="1"
    android:versionName="1.0" >

More details Processes and Threads - Android Developer

I wanted to get application names of all running apps. So this is what I did after looking at various sources (and it works).

    ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager packageManager = getPackageManager();
    final List<RunningAppProcessInfo> runningProcesses = activityManager.getRunningAppProcesses();
    for(RunningAppProcessInfo processInfo : runningProcesses) {
        CharSequence appName = null;
        try {
            appName = packageManager.getApplicationLabel(packageManager.getApplicationInfo(processInfo.processName, PackageManager.GET_META_DATA));
        } catch (NameNotFoundException e) {
            Log.e(TAG,"Application info not found for process : " + processInfo.processName,e);
        }
    }

If you see Documentation for PackageManager.getApplicationInfo

ApplicationInfo android.content.pm.PackageManager.getApplicationInfo(String packageName, int flags) throws NameNotFoundException

but I am passing

processInfo.processName

where processName is name of process running. So we are basically using process name as package name to get application info.

  1. First of all is this approach correct ?
  2. Secondly is it true that if we do not provide process for activities/services etc new process is created with same name as that of package name ?

解决方案

By default android takes the package name as the process name. But if you define process property in application tag in manifest file android:process="com.example.newprocessname" then the application will run with this name "com.example.newprocessname".

As for your questions,

Hope this answers your question!

这篇关于是进程名相同的Andr​​oid包名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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