发布网友 发布时间:2022-06-27 04:51
共1个回答
热心网友 时间:2024-01-22 04:52
PID是android应用程序进程的ID,网上找到了一个方法,可以根据PID得出应用程序的包名,代码如下
[java] view plain copy
private String getAppName(int pID)
{
String processName = "";
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRunningAppProcesses();
Iterator i = l.iterator();
PackageManager pm = this.getPackageManager();
while(i.hasNext())
{
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
try
{
if(info.pid == pID)
{
CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
//Log.d("Process", "Id: "+ info.pid +" ProcessName: "+ info.processName +" Label: "+c.toString());
//processName = c.toString();
processName = info.processName;
}
}
catch(Exception e)
{
//Log.d("Process", "Error>> :"+ e.toString());
}
}
return processName;
}
打印出包名是com.huawei.android.totemweather,我的手机是华为荣耀6,根据包名还有百度搜索可以判断这是手机的系统程序“天气”,然后找到应用程序管理直接停用它就行了,反正我不用这个系统自带的天气,我用墨迹天气。