需求:
在设备配置参数中增加开机自启APP参数配置,以实现开启自动APP。
修改步骤:
1、 修改系统默认配置,增加参数
文件位置:device/rockchip/rk3576/device.mk
#persist.sys.start.app 开机启动的app,格式为包名&类名,如com.xxx.xxxxTest&com.xxx.xxxTest.ShowActivity
PRODUCT_PROPERTY_OVERRIDES += \
persist.sys.start.app= com.xxx.xxxxTest&com.xxx.xxxTest.ShowActivity\
persist.sys.app.rotation=portrait
2、 获取参数启动APP
文件位置:frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
修改 systemReady() 增加Intent
@Override
public void systemReady() {
........
//开机启动app add code start
IntentFilter intentFilter = new IntentFilter("android.intent.action.BOOT_COMPLETED");
mContext.registerReceiver(mWallpaperChangedReceiver, intentFilter);
//add code end
mAutofillManagerInternal = LocalServices.getService(AutofillManagerInternal.class);
mGestureLauncherService = LocalServices.getService(GestureLauncherService.class);
}
// add core start
BroadcastReceiver mWallpaperChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG, "----mWallpaperChangedReceiver--------action:"+action);
try {
String apkStr = SystemProperties.get("persist.sys.start.app", "");
Log.d(TAG, "----mWallpaperChangedReceiver--------apkStr:"+apkStr);
if (action.equals("android.intent.action.BOOT_COMPLETED")
&& !"".equals(apkStr)) {
String[] apkInfo = apkStr.split("&");
if(apkInfo.length != 2){
return;
}
Log.d(TAG, "---mWallpaperChangedReceiver--------apkInfo:"+apkInfo[0]+"---"+apkInfo[1]);
Intent launchIntent = new Intent();
launchIntent.setClassName(apkInfo[0], apkInfo[1]);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context. startActivity(launchIntent);
}
}catch (Exception e) {
Log.e(TAG, "----mWallpaperChangedReceiver Exception--------",e);
}
}
};
标签:RK3576,apkStr,app,Android14,mWallpaperChangedReceiver,Intent,apkInfo,action,APP
From: https://blog.csdn.net/weixin_56061795/article/details/144849316