Java 引导完成的接收器不';我不能在安卓5.1.1的海信设备上工作
我正在开发一个应用程序,在这个应用程序中,我需要在重新启动时设置警报,以便在特定的时间间隔内启动服务 我已经创建了必需的启动完成接收器类,添加了使用权限,并在清单文件中定义了接收器。我在每台设备上都测试过许多真实的和模拟的设备,除了使用安卓5.1.1的海信设备外,接收器都能正常工作 我已经尝试过这些解决方案 我还删除了android:installLocation=“auto”并添加了一些线程中建议的Java 引导完成的接收器不';我不能在安卓5.1.1的海信设备上工作,java,android,broadcastreceiver,android-manifest,Java,Android,Broadcastreceiver,Android Manifest,我正在开发一个应用程序,在这个应用程序中,我需要在重新启动时设置警报,以便在特定的时间间隔内启动服务 我已经创建了必需的启动完成接收器类,添加了使用权限,并在清单文件中定义了接收器。我在每台设备上都测试过许多真实的和模拟的设备,除了使用安卓5.1.1的海信设备外,接收器都能正常工作 我已经尝试过这些解决方案 我还删除了android:installLocation=“auto”并添加了一些线程中建议的android:directBootAware=“true”android:enabled
android:directBootAware=“true”android:enabled=“true”android:exported=“true”
请在下面查找收件人类别和清单代码
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Set instance Alarm on boot
Calendar calendar = Calendar.getInstance();
Intent messageCheckerIntent = new Intent(context, MessageCheckerService.class);
PendingIntent pendingIntent =
PendingIntent.getService(context, REQ_MESSAGE_CHECK,
messageCheckerIntent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// Cancel if any existing alarm for given pendingIntent (MessageCheckerService)
alarmManager.cancel(pendingIntent);
// Alarm is reset every time when this service is called,
// still keep alarm repeating so if one call fails does not affect following calls
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
ALARM_INTERVAL, pendingIntent);
}
}
清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.project.myapp">
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup">
<activity
android:name=".SplashScreen"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask">
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<service android:name=".GPSTrack" />
<service
android:name=".MessageCheckerService"
android:enabled="true" />
<receiver
android:name=".BootReceiver"
android:directBootAware="true"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>
</manifest>
您是否尝试将接收器设置为后台服务?@ParthBhatti不,我还没有设置。但我不明白我到底需要为此做些什么。你有一个链接,其中解释了示例代码。