清除Android的本地通知科尔多瓦插件 [英] Clear Android's Local Notifications cordova plugin

查看:164
本文介绍了清除Android的本地通知科尔多瓦插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的PhoneGap的localNotification插件为Android 显示通知特定的日期。

I use Phonegap's localNotification Plugin for Android to show notifications on specific dates.

我用科尔多瓦[2.2]放大器;我用科尔多瓦的<一个href="http://docs.phonegap.com/en/2.2.0/guide_plugin-development_android_index.md.html#Developing%20a%20Plugin%20on%20Android"相对=nofollow>升级教程修改插件。

I use Cordova [2.2] & I used cordova's upgrading tutorial to modify the plugin.

的通知显示,但是当我点击它,应用程序不打开,并通知不会清零。

The notification is displayed, but when I click on it, the application doesn't open and the notification isn't cleared.

我该如何解决这个问题?

How can I fix this?

推荐答案

在AlarmReceiver.java,围绕线70,你会看到code以下行:

In AlarmReceiver.java, around line 70, you will see the following lines of code:

    // Construct the notification and notificationManager objects
    final NotificationManager notificationMgr = (NotificationManager) systemService;
    final Notification notification = new Notification(R.drawable.ic_launcher, tickerText,
            System.currentTimeMillis());
    final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.vibrate = new long[] { 0, 100, 200, 300 };
    notification.setLatestEventInfo(context, notificationTitle, notificationSubText, contentIntent);

添加适当的行以匹配以下:

Add the appropriate lines to match the following:

    // Construct the notification and notificationManager objects
    final NotificationManager notificationMgr = (NotificationManager) systemService;
    final Notification notification = new Notification(R.drawable.ic_launcher, tickerText,
            System.currentTimeMillis());
    Intent notificationIntent = new Intent(context, CLASS_TO_OPEN.class);
    final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.vibrate = new long[] { 0, 100, 200, 300 };
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.setLatestEventInfo(context, notificationTitle, notificationSubText, contentIntent);

在这里CLASS_TO_OPEN是要打开时,通知是pressed类的名称。

where CLASS_TO_OPEN is the name of the class you wish to open when the notification is pressed.

编辑:
为了澄清,才能有通知打开活动时,它是preSS,你需要这个活动的通知对象相关联。这是通过创建一个意图,指定活动打开(如NAME_OF_ACTIVITY.class)作为第二个参数,并通过本意图 PendingIntent 作为第三个参数。这,反过来,被传递给经由 setLatestEventInfo 方法的通知对象。


To clarify, in order to have the notification open an activity when it is press, you need to associate this activity with the notification object. This is done by creating an Intent, specifying the activity to open (as in NAME_OF_ACTIVITY.class) as the second parameter, and passing this Intent to a PendingIntent as the third parameter. This, in turn, is passed to the notification object via the setLatestEventInfo method.

在这上面的code片断都为你除了指定要打开活动的执行,因为这将是具体到项目中。除非你已经添加了额外的活动,一个的PhoneGap /科尔多瓦项目包含一个活动,即打开科尔多瓦的WebView之一。如果你不知道或者不记得在你的项目本次活动的名称,你可以找到它在Package Explorer(在Eclipse)由以下内容:

In the code snippet above this is all done for you with the exception of specifying the activity to open, as this is going to be specific to your project. Unless you have added additional activities, a PhoneGap/Cordova project contains one activity, namely the one that opens the Cordova WebView. If you do not know or remember the name of this activity in your project, you can find it in the Package Explorer (in Eclipse) by following:

来源> NAME_OF_YOUR_PACKAGE> NameOfActivity.java

src>NAME_OF_YOUR_PACKAGE>NameOfActivity.java

要确保这是类的名称,用文本编辑器打开Java文件,你会看到 NAME_OF_ACTIVITY延伸DroidGap 。更换CLASS_TO_OPEN在上面的代码片段与你的活动的名称(必须包含.class文件扩展名)。

To be sure this is the name of the class, open the java file with a text editor and you will see NAME_OF_ACTIVITY extends DroidGap. Replace CLASS_TO_OPEN in the above snippet with the name of your activity (must include .class file extension).

这篇关于清除Android的本地通知科尔多瓦插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆