简介
最近做一个需求需要在Android版本8.1手机上启动一个3方服务.在SystemUI这类应用中启动3方应用,一定要在开机广播中启动.
思路
客户提供了3应用,没有源码,apk形式,文档上提供的调用方式.
步骤很少:检查对应的service是否存在,如果存在就启动服务
public void startGupshupServiceIfNeeded() {
Intent implicitIntent = new Intent("xxxx");
Intent explicitIntent = convertImplicitIntentToExplicitIntent(implicitIntent);
if (explicitIntent != null) {
mContext.startForegroundService(explicitIntent);
}
}
//查找服务是否存在
public Intent convertImplicitIntentToExplicitIntent(Intent implicitIntent) {
PackageManager pm = mContext.getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentServices(implicitIntent, 0);
if (resolveInfoList == null || resolveInfoList.size() != 1) {//1
Log.v(TAG,"staring service failed");
return null;
}
ResolveInfo serv