Java 警报没有在android中调用

Java 警报没有在android中调用,java,android,android-intent,alarmmanager,Java,Android,Android Intent,Alarmmanager,此警报正在触发其他接收器,即UpdateTables.java(正在工作) 现在在UpdateTables.java中,它也在创建报警并将意图传递给另一个接收器。但是接收者没有收到意图 AlarmManager alarmManager=(AlarmManager) getSystemService(ALARM_SERVICE); Intent alarmIntent=new Intent(context,UpdateTables.class); Pendin

此警报正在触发其他接收器,即UpdateTables.java(正在工作)

现在在UpdateTables.java中,它也在创建报警并将意图传递给另一个接收器。但是接收者没有收到意图

AlarmManager alarmManager=(AlarmManager) getSystemService(ALARM_SERVICE);

        Intent alarmIntent=new Intent(context,UpdateTables.class);

        PendingIntent pendingIntent=PendingIntent.getBroadcast(context,0,alarmIntent,PendingIntent.FLAG_UPDATE_CURRENT);

        alarmManager.cancel(pendingIntent);

        Calendar alarmStartTime = Calendar.getInstance();

        alarmStartTime.setTimeInMillis(System.currentTimeMillis());

        //midnight
        alarmStartTime.set(Calendar.HOUR_OF_DAY, 19);
        alarmStartTime.set(Calendar.MINUTE, 18);
        alarmStartTime.set(Calendar.SECOND, 0);

        if(Calendar.getInstance().getTimeInMillis()>alarmStartTime.getTimeInMillis())
        {
            alarmStartTime.add(Calendar.DATE,1);
        }

        Log.i("TIME IS ",Long.toString(alarmStartTime.getTimeInMillis()));


        System.out.println("Updating table time "+alarmStartTime);
        System.out.println("Time in millseconds "+alarmStartTime.getTimeInMillis());


        alarmManager.setInexactRepeating(AlarmManager.RTC,alarmStartTime.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent);

        Log.d("Alarm","Set for midnight");
清单文件

public class notificationService extends BroadcastReceiver {

    public static String TAG="notificationService";
    @Override
    public void onReceive(Context context, Intent intent) {

        String notificatioTitle=intent.getExtras().getString("Notification_title");
        String notificationMsg=intent.getExtras().getString("Notification_text");

        Log.i(TAG,"Notification title "+notificatioTitle);
        Log.i(TAG,"Notification msg "+notificationMsg);

        NotificationCompat.Builder notification=new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(notificatioTitle)
                .setContentText(notificationMsg);

        NotificationManager mNotificationManager =(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(0,notification.build());
    }


}

我已经根据这里给出的答案更改了密码,但仍然没有响起警报

要确保您的事件正在调用,请使用以下方法:

 RTC #19: Alarm{3788170 type 1 when 1484142480449 user.com.hlthee}

    tag=*alarm*:user.com.hlthee/.UpdateTables

    type=1 whenElapsed=+23h56m29s342ms when=2017-01-11 19:18:00

    window=-1 repeatInterval=86400000 count=0

    operation=PendingIntent{3e5f6ce9: PendingIntentRecord{7068d6e user.com.hlthee broadcastIntent}}



u0a195:user.com.hlthee +79ms running, 3 wakeups:

    +69ms 0 wakes 1 alarms: *alarm*:user.com.hlthee/.UpdateTables

    +10ms 3 wakes 3 alarms: *walarm*:user.com.hlthee/services.notificationService
专用静态AlarmManager am;
私有静态void init(上下文ctx){
如果(am==null)
am=(AlarmManager)ctx.getSystemService(Activity.ALARM\u服务);
}
@SuppressLint(“新API”)
公共静态void startBylarmWake(上下文ctx,长nexttim){
init(ctx);
意向意向=新意向(ctx,BRWake.class);
PendingEvent pi=PendingEvent.getBroadcast(ctx,SOMEID,intent,PendingEvent.FLAG_CANCEL_CURRENT);
int currentapiVersion=android.os.Build.VERSION.SDK\u int;
if(currentapiVersion
要确保您的事件正在调用,请使用以下方法:

 RTC #19: Alarm{3788170 type 1 when 1484142480449 user.com.hlthee}

    tag=*alarm*:user.com.hlthee/.UpdateTables

    type=1 whenElapsed=+23h56m29s342ms when=2017-01-11 19:18:00

    window=-1 repeatInterval=86400000 count=0

    operation=PendingIntent{3e5f6ce9: PendingIntentRecord{7068d6e user.com.hlthee broadcastIntent}}



u0a195:user.com.hlthee +79ms running, 3 wakeups:

    +69ms 0 wakes 1 alarms: *alarm*:user.com.hlthee/.UpdateTables

    +10ms 3 wakes 3 alarms: *walarm*:user.com.hlthee/services.notificationService
专用静态AlarmManager am;
私有静态void init(上下文ctx){
如果(am==null)
am=(AlarmManager)ctx.getSystemService(Activity.ALARM\u服务);
}
@SuppressLint(“新API”)
公共静态void startBylarmWake(上下文ctx,长nexttim){
init(ctx);
意向意向=新意向(ctx,BRWake.class);
PendingEvent pi=PendingEvent.getBroadcast(ctx,SOMEID,intent,PendingEvent.FLAG_CANCEL_CURRENT);
int currentapiVersion=android.os.Build.VERSION.SDK\u int;
if(currentapiVersion
我无法理解您的代码是否在所有通知中都没有触发,或者它触发了,但您看不到它。程序是否进入setAlarmToCallNotificationService方法?您能看到这两行生成的日志吗?Log.i(标签,“通知标题”+通知标题);Log.i(标记,“通知消息”+通知消息)?是,它正在进入函数setAlarmToCallNotificationService()并打印日志。但是它没有进入notificationService广播接收者。我不知道你的代码是否在所有通知中都没有触发,或者它触发了,但是你看不到它。程序是否进入setAlarmToCallNotificationService方法?您能看到这两行生成的日志吗?Log.i(标签,“通知标题”+通知标题);Log.i(标记,“通知消息”+通知消息)?是,它正在进入函数setAlarmToCallNotificationService()并打印日志。但是它没有进入notificationService广播接收器我相应地更改代码,但notificationService服务器仍在呼叫我相应地更改代码,但notificationService服务仍在呼叫我相应地更改代码,但notificationService服务仍在呼叫我相应地更改代码,但仍在呼叫notificationService服务未调用
 RTC #19: Alarm{3788170 type 1 when 1484142480449 user.com.hlthee}

    tag=*alarm*:user.com.hlthee/.UpdateTables

    type=1 whenElapsed=+23h56m29s342ms when=2017-01-11 19:18:00

    window=-1 repeatInterval=86400000 count=0

    operation=PendingIntent{3e5f6ce9: PendingIntentRecord{7068d6e user.com.hlthee broadcastIntent}}



u0a195:user.com.hlthee +79ms running, 3 wakeups:

    +69ms 0 wakes 1 alarms: *alarm*:user.com.hlthee/.UpdateTables

    +10ms 3 wakes 3 alarms: *walarm*:user.com.hlthee/services.notificationService
private static AlarmManager am;
    private static void init(Context ctx){
        if (am == null)
            am = (AlarmManager) ctx.getSystemService(Activity.ALARM_SERVICE);
    }
    @SuppressLint("NewApi")
    public static void startbyalarmWake(Context ctx, long nexttim) {
        init(ctx);

        Intent intent = new Intent(ctx,BRWake.class);

        PendingIntent pi = PendingIntent.getBroadcast(ctx, SOMEID, intent, PendingIntent.FLAG_CANCEL_CURRENT);

        int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        if (currentapiVersion < android.os.Build.VERSION_CODES.KITKAT){
            am.set(AlarmManager.RTC_WAKEUP, nexttime, pi);
        } else {
            if (currentapiVersion < android.os.Build.VERSION_CODES.M) {
                am.setExact(AlarmManager.RTC_WAKEUP, nexttime, pi);
            } else {
                am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nexttime, pi);
            }
        }
    }