80,350
社区成员
发帖
与我相关
我的任务
分享
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("MyReceiver", "onReceive");
noti(context);
}
private void noti(Context context){
Log.d("MyReceiver", "noti");
NotificationManager manager=(NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent=new Intent(context,NotiActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi=PendingIntent.getBroadcast(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification=new Notification.Builder(context)
.setTicker("new message")
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("title")
.setContentText("text")
.setContentIntent(pi)
.build();
manager.notify(1, notification);
}
}