是进程名相同的Andr​​oid包名?进程、Andr、oid

2023-09-06 07:33:46 作者:ゝ心 伤

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

 <清单的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是进程运行的名字。所以,我们基本上都采用进程名作为包名获得应用程序信息。

首先是这种做法是否正确?其次,这是真的,如果我们没有为活动/服务等提供了新的工艺过程与同名的包名的创建? 解决方案

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

至于你的问题,

1>在这种情况下,您的应用程序的名称是一样的默认包名称,这就是为什么它是工作。试着改变进程名。它会无法正常工作。

2->这是真的。这是默认。请参阅机器人:过程中的以下链接:https://developer.android.com/guide/topics/manifest/application-element.html

希望这回答您的问题!

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.

First of all is this approach correct ? 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,

1-> In this case your application name is same as the default package name, that's why it is working. Try changing the process name. It'll not work.

2-> That's true. It is by default. Refer to "android:process" in the following link: https://developer.android.com/guide/topics/manifest/application-element.html

Hope this answers your question!