相关疑难解决方法(0)

单击Android通知操作不会关闭通知抽屉

我正在使用NotificationCompat库向系统栏添加通知.此通知有两个操作按钮.此外,AutoCancel()Notification上的属性设置为true.

单击操作按钮,系统配置为启动IntentService调用NotificationManager.cancel(NOTIFICATION_ID),然后在新任务中启动活动.
问题是虽然此调用会从托盘中删除通知,但它不会折叠抽屉.被叫活动在抽屉后面绘制.

除了取消通知之外,有人可以详细说明关闭抽奖需要什么特殊代码吗?

谢谢.

android android-intent android-notifications

47
推荐指数
3
解决办法
1万
查看次数

在没有打开应用程序的情况下通过操作按钮关闭正在进行的Android通知

我有一个应用程序,持续通知,以帮助记忆.我希望能够通过其中一个操作按钮关闭此通知,但我不想在按下按钮时打开应用程序.我更喜欢使用内置的通知操作按钮,而不是创建一个RemoteViews对象来填充通知.我在我的应用程序中看到了一个在这个按钮上使用BroadcastReceiver的帖子提及,虽然他的教程非常无益,但听起来这是朝着正确的方向发展.

Intent resultIntent = new Intent(getBaseContext(), Dashboard.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getBaseContext());
        stackBuilder.addParentStack(Dashboard.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
                );
    Intent cancel = new Intent(getBaseContext(), CancelNotification.class);
        stackBuilder.addParentStack(Dashboard.class);
        stackBuilder.addNextIntent(cancel);
        PendingIntent pendingCancel =
                stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
                );

    NotificationCompat.Builder mb = new NotificationCompat.Builder(getBaseContext());
        mb.setSmallIcon(R.drawable.cross_icon);
        mb.setContentTitle(ref);
        mb.setContentText(ver);
        mb.setPriority(NotificationCompat.PRIORITY_LOW);
        mb.setOngoing(true);
        mb.setStyle(new NotificationCompat.BigTextStyle().bigText(ver));
        mb.setContentIntent(resultPendingIntent);
        mb.addAction(R.drawable.ic_cancel_dark, "Dismiss", pendingCancel);

    manager.notify(1, mb.build());  
Run Code Online (Sandbox Code Playgroud)

notifications android broadcastreceiver

18
推荐指数
2
解决办法
2万
查看次数

关闭单击Action的当前通知

我有一个带有操作按钮的自定义通知:

public class NotificationReceiver extends com.parse.ParsePushBroadcastReceiver {
    @Override
    public void onPushReceive(Context context, Intent intent) {

    ...

    NotificationActivity notification = new NotificationActivity();
    notification.createNotification(context, message, notificationId);

    Log.i("tag", "Notification Received!");
}
Run Code Online (Sandbox Code Playgroud)
public class NotificationActivity {

    public int notificationId;

    public void createNotification(Context context, String message, String studentId, String notificationId){
         this.notificationId = Integer.parseInt(notificationId);

         // manager
         NotificationManager notificationManager = 
         (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

         // notification
         Notification.Builder mBuilder = new Notification.Builder(context);
         mBuilder.setContentTitle("My Title");
         mBuilder.setContentText(message);
         mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
         mBuilder.setAutoCancel(true);
         mBuilder.setStyle(new Notification.BigTextStyle()
             .bigText(message));

         // cancel intent
         Intent cancelIntent = new Intent(context, CancelNotification.class);
         Bundle …
Run Code Online (Sandbox Code Playgroud)

java android push-notification

8
推荐指数
1
解决办法
8029
查看次数

通知未关闭(Android)

如果单击“操作”,则通知setAutoCancel(true)不起作用

我有一个通知,其中包含操作。当我点击通知时,它将从列表中删除。但是,当我单击“操作”时,它成功完成了该操作(即拨打电话),但是当我返回到通知列表时,它仍然存在。AlarmReceiver的相对代码:

public class AlarmReceiver extends BroadcastReceiver {
Meeting meeting;

/**
 * Handle received notifications about meetings that are going to start
 */
@Override
public void onReceive(Context context, Intent intent) {

    // Get extras from the notification intent
    Bundle extras = intent.getExtras();
    this.meeting = extras.getParcelable("MeetingParcel");

    // build notification pending intent to go to the details page when click on the body of the notification
    Intent notificationIntent = new Intent(context, MeetingDetails.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.putExtra("MeetingParcel", meeting);      // send meeting that we received to …
Run Code Online (Sandbox Code Playgroud)

notifications android dismiss

5
推荐指数
1
解决办法
1305
查看次数

如何在Android应用程序中点击后隐藏通知

这是在服务启动时发出通知的代码

NotificationCompat.Builder mbuild = new NotificationCompat.Builder(getApplicationContext());

Intent in = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent resultIN =   PendingIntent.getActivity(getApplicationContext(),code,in,NOTIFICATION_COUNT);           mbuild.setSmallIcon(R.drawable.images1);    
mbuild.setContentText(NOTIFICATION_COUNT +" New Message");
mbuild.setContentIntent(resultIN);          //mbuild.addAction(R.drawable.notifications,NOTIFICATION_COUNT +"New Messages",resultIN);

 NotificationManager nmagr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nmagr.notify(1, mbuild.build());
Run Code Online (Sandbox Code Playgroud)

每个人都正常工作..代码打开目标活动,但通知仍然保留在通知栏中.我尝试过使用mbuil.setautocancel(true); 但它无所事事

notifications android

4
推荐指数
1
解决办法
2386
查看次数