美文网首页
Android 通知 点击通知 跳转到对应页面

Android 通知 点击通知 跳转到对应页面

作者: 慶孟國 | 来源:发表于2017-12-08 15:13 被阅读0次

    Bitmap btm= BitmapFactory.decodeResource(getResources(), R.drawable.ic_menu_compose);

    NotificationCompat.Builder mBuilder=newNotificationCompat.Builder(getApplication()).setSmallIcon(R.mipmap.ic_launcher)

    .setContentTitle("消息").setContentText("新消息");

    mBuilder.setTicker("新的消息");

    //mBuilder.setNumber(12);

    mBuilder.setLargeIcon(btm);

    mBuilder.setAutoCancel(true);

    mBuilder.setPriority(Notification.PRIORITY_MAX);

    mBuilder.setDefaults(Notification.DEFAULT_ALL);

    mBuilder.setOnlyAlertOnce(true);

    //构建一个intent

    Intent resultIntent=newIntent(getApplicationContext(), PushNewsActivity.class);

    resultIntent.putExtra("content",content);

    resultIntent.putExtra("id",idChar);

    resultIntent.putExtra("title",title);

    PendingIntent resultPI=PendingIntent.getActivity(getApplication(),requestCode,resultIntent,PendingIntent.FLAG_CANCEL_CURRENT);

    mBuilder.setContentIntent(resultPI);

    NotificationManager mNotif= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mNotif.notify(requestCode,mBuilder.build());

    相关文章

      网友评论

          本文标题:Android 通知 点击通知 跳转到对应页面

          本文链接:https://www.haomeiwen.com/subject/clveixtx.html