关于在启动时启动应用程序的 Stackoverflow 有很多问题。 我对所有这些都进行了搜索,搜索谷歌但是它不起作用。
的AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver
android:name=".BootUpReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
BootUpReceiver
@Override
public void onReceive(Context context, Intent intent) {
Log.w(TAG, "onReceive: starting app");
Intent i = new Intent(context, Launcher.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
启动时的相关日志:
D/PackageManager: PROCAPK:/data/app/com.example.app-1 pkg name:com.example.app
W/PackageManager: Failure retrieving resources for com.example.app: Resource ID #0x0
AppOps: check op 53 uid 10109 for com.example.app
**BroadcastQueue: App ops not allowed for broadcast to uid 10109 pkg com.example.app**
D/BroadcastQueue: processNextBroadcast app ops skip = true, action = android.intent.action.BOOT_COMPLETED, package = com.example.app
I/LMS: find package:com.example.app, cert idx :19
pkg key: long string
修改
此代码适用于模拟器。我想这确实取决于设备证券......任何想法?