前提・実現したいこと
端末起動時にServiceを開始する
発生している問題・エラーメッセージ
Androidセキュリティパッチレベルが更新(ソフトウェアアップデート)されると
既存の"端末起動時にServiceを開始する"という処理が動作しなくなる。
■Androidセキュリティパッチレベル
2017年6月1日→2018年8月5日
以下のコードに記載してあるClassの
public void onReceive(Context context, Intent intent) {
に受信されない。
どうすれば、"端末起動"をBroadcastReceiverが受信できるでしょうか。
Android Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test" android:versionCode="2" android:versionName="02.00.00" android:sharedUserId="test.id" android:installLocation="internalOnly" > <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="25" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <service android:name="TestService" /> <receiver android:name="BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.PACKAGE_REPLACED" /> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="package" /> </intent-filter> </receiver> </application> </manifest>
BootReceiver.Class
public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //端末起動時にサービス起動 if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
補足情報(FW/ツールのバージョンなど)
端末 :NEC PC-TE508HAW
Ver :Android7.1.1
あなたの回答
tips
プレビュー