1

特定の時間に通知を開始しようとしています。BroadcastReceiverに入ったのですが通知が始まらない。多分私の間違いはマニフェストにありますか?ご協力ありがとうございました。

 public void to_reminder(View v)
 { 
     Calendar cal=Calendar.getInstance();
     cal.set(Calendar.HOUR_OF_DAY, 15); 
     cal.set(Calendar.MINUTE, 16);   
     cal.set(Calendar.SECOND, 0);
     cal.set(Calendar.MILLISECOND, 0);

     AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent i = new Intent(this, Notifica.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
am.cancel(pi);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 24*60*60*1000 , pi);
 }

.

public class Notifica extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent arg1) {

    showNotification(context);
}
private void showNotification(Context context) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, Login.class), 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
            .setSmallIcon(0)
            .setContentTitle("My notification")
            .setContentText("Hello World!");
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    mBuilder.setAutoCancel(true);

    NotificationManager mNotificationManager =
    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());

}  
}

.

 <!-- Broadcast receiver -->
<receiver android:name="reminder.Notifica"></receiver>


</application>

4

1 に答える 1

2

PendingIntent.getBroadcastの代わりに追加する必要がありPendingIntent.getServiceます。詳細については、これを参照してください

于 2014-06-03T13:37:14.457 に答える