包com.mmu.mpo;
import android.app.Notification;进口 android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver;进口 android.content.Context; import android.content.Intent;进口 android.net.Uri; import android.os.Bundle;进口 android.widget.Toast;公共类AlarmReceiver扩展 BroadcastReceiver {private static int NOTIFICATION_ID = 1;
@Override public void onReceive(Context context,Intent intent){
NotificationManager manger = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification
notification = new Notification(R.drawable.ic_launcher,“Combi Note”, System.currentTimeMillis的());
PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ID, new Intent(context, AlarmReceiver.class), 0); Bundle extras=intent.getExtras(); String title=extras.getString("title"); String
注= extras.getString( “注意”);
notification.setLatestEventInfo(context, title, "Venue : " + note, contentIntent); //notification.flags =
Notification.FLAG_INSISTENT; notification.defaults | = Notification.DEFAULT_SOUND;
manger.notify(NOTIFICATION_ID++, notification); } };
答案 0 :(得分:1)
尝试这是否有帮助!
Context context = getApplicationContext();
CharSequence contentTitle = "Notification";
CharSequence contentText = "New Notification";
final Notification notifyDetails = new Notification(R.drawable.icon, "Consider yourself notified", System.currentTimeMillis());
Intent notifyIntent = new Intent(context, YourActivity.class);
PendingIntent intent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, notifyDetails);