在Android上克隆后删除通知

时间:2015-07-27 17:31:08

标签: java android unity3d notifications

我目前正在使用Unity插件,这样我就可以推送本地"通知。它的工作正常,除了一件事:点击后通知不会消失。

以下是代码:

onClick=getResult()

即使我不是java开发者,我也理解这段代码的大部分内容。我已经尝试了一些技巧:

$(function() {

    // You should maybe put an ID on the button as well to select it
    $("select[type=button]").click(function() {
        var keyword = getResult();
        tm = ...
    }
}

但正如我所期待的那样,那是行不通的......

那么,有没有人可以向我解释如何实现这一目标? 谢谢伙伴们!

3 个答案:

答案 0 :(得分:0)

试试这可能会对你有所帮助:

 NotificationManager  mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent = new Intent(this, Destination.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,intent , 0);
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    long[] vibration = {0, 200, 50, 200};
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.app_icon)
                    .setContentTitle("MyCar Notification")
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(msg))
                    .setSound(uri)
                    .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)
                    .setVibrate(vibration)
                    .setAutoCancel(true)
                    .setContentText(msg);
    mBuilder.setContentIntent(contentIntent);
    int NOTIFICATION_ID = (int) System.currentTimeMillis();
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

答案 1 :(得分:0)

notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL

答案 2 :(得分:0)

添加标志Notification.FLAG_AUTO_CANCEL(或调用.setAutoCancel(true))并重建Unity项目后,请转到手机设置 - >应用程序,找到您的应用程序并单击它,然后单击" FORCE STOP"按钮。现在再次启动你的app,它应该可以工作。