2

当应用程序关闭时,我的警报管理器无法在棒棒糖版本上运行,而它正在运行其他 Android 版本的棉花糖,牛轧糖,完美

alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, AlarmReciver.class);
        intent.putExtra("msg", msgstring);
        intent.putExtra("num", recipstring);
        intent.putExtra("recipname", name);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, number, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);``

这是我的警报接收器:

public class AlarmReciver extends WakefulBroadcastReceiver {
@Override  public void onReceive(Context context, Intent intent) {
  Notification.Builder builder= new Notification.Builder(context);
        builder.setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL)
                .setWhen(System.currentTimeMillis()).setColor(Color.WHITE)
                .setSmallIcon(R.mipmap.ic_launcher).setPriority(Notification.PRIORITY_HIGH)
                .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_SOUND)
                .setContentTitle("test")
                .setContentText(message);
        NotificationManager notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, builder.build());
        dbhelper.insertdilvery(message, name);
}
    }

清单文件:

   <receiver android:name="com.simulatorgames3d.EventsNotifications.alarmreceiver.AlarmReciver"
            android:process=":remote"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

权限

<uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>

当应用程序未关闭时,herr 是 logcat pic 在此处输入图像描述

当应用程序关闭并且警报不触发时定位 在此处输入图像描述

4

0 回答 0