<service android:name=".atservice.ATService" android:process="com.android.phone">
<intent-filter>
<action android:name="com.sagereal.atcmd.service.ACTION"/>
</intent-filter>
</service>
以上是四大组件之一服务的注册。若不指定process,则进程名为包名;若要指定运行在某一进程中,如phone进程,则组件要在注册时加上:android:process="com.android.phone"。若要运行在phone进程,此时组件所在模块的Android.mk文件要有:"LOCAL_CERTIFICATE := platform"方可,这句表示使用platform来签名,即系统级别的签名。
注:
1). 获取当前进程名
/**
* 获取当前进程的名字,一般就是当前app的包名
*
* @param context 当前上下文
* @return 返回进程的名字
*/
public static String getAppName(Context context){
int pid = android.os.Process.myPid(); // Returns the identifier of this process
ActivityManager am =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
if (runningApps == null) {
return null;
}
for (ActivityManager.RunningAppProcessInfo processInfo : runningApps) {
if (processInfo.pid == pid) {// 根据进程的信息获取当前进程的名字
return processInfo.processName;
}
}
return null;
}
2). action是在intent-filter内的,若书写不对,会报错:INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES。
3). 清单文件修改之后,要重启手机,才有效果。
参考: