cordova 插件中的本机通知 android 代码 java class
native notification android code in cordova plugin java class
我对 cordova 有所了解,现在我正在我的插件中实现通知 class。
我使用下面的 android 代码在我的 java class 中创建了通知。
我已经导入了所有与通知相关的包。
但是我收到通知异常,无法收到通知
NotificationManager notificationManager = (NotificationManager)this.getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
Notification notification=new Notification.Builder(getApplicationContext())
.setWhen(System.currentTimeMillis())
.setContentTitle("Welcome")
.setTicker("Click here to see the offers...")
.setContentText("Click here to see the offers...")
//.setSmallIcon(1)
.setAutoCancel(true)
.build();
notificationManager.notify(info, notification);
我得到的异常是
NotificationService(802): Not posting notification with icon==0: Notification(pri=0 icon=0 contentView=com.ionicframework.dummy292686/0x1090085 vibrate=null sound=null defaults=0x0 flags=0x10 when=1439564895752 ledARGB=0x0 contentIntent=N deleteIntent=N contentTitle=7 contentText=31 originalPackageName=N originalUserId=0 tickerText=31 kind=[null])
有人可以建议在 cordova 插件中编写通知逻辑吗 java class?
我相信你至少需要提供一个小图标。
取消注释 .setSmallIcon(1)
并将 1
替换为要在通知中用作图标的可绘制对象的资源 ID。
最后,我在构建通知对象时做了一些更改,它对我有用。
try{
Log.i(TAG, "In try block of notification");
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification.Builder(this)
.setTicker("My Company")
.setContentTitle("Welcome")
.setContentText("Click here to see offers...")
.setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent).getNotification();
notification.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}catch(Exception e){
Log.e(TAG, "In catch block of notification:"+e);
}
我对 cordova 有所了解,现在我正在我的插件中实现通知 class。
我使用下面的 android 代码在我的 java class 中创建了通知。 我已经导入了所有与通知相关的包。 但是我收到通知异常,无法收到通知
NotificationManager notificationManager = (NotificationManager)this.getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
Notification notification=new Notification.Builder(getApplicationContext())
.setWhen(System.currentTimeMillis())
.setContentTitle("Welcome")
.setTicker("Click here to see the offers...")
.setContentText("Click here to see the offers...")
//.setSmallIcon(1)
.setAutoCancel(true)
.build();
notificationManager.notify(info, notification);
我得到的异常是
NotificationService(802): Not posting notification with icon==0: Notification(pri=0 icon=0 contentView=com.ionicframework.dummy292686/0x1090085 vibrate=null sound=null defaults=0x0 flags=0x10 when=1439564895752 ledARGB=0x0 contentIntent=N deleteIntent=N contentTitle=7 contentText=31 originalPackageName=N originalUserId=0 tickerText=31 kind=[null])
有人可以建议在 cordova 插件中编写通知逻辑吗 java class?
我相信你至少需要提供一个小图标。
取消注释 .setSmallIcon(1)
并将 1
替换为要在通知中用作图标的可绘制对象的资源 ID。
最后,我在构建通知对象时做了一些更改,它对我有用。
try{
Log.i(TAG, "In try block of notification");
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification.Builder(this)
.setTicker("My Company")
.setContentTitle("Welcome")
.setContentText("Click here to see offers...")
.setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent).getNotification();
notification.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}catch(Exception e){
Log.e(TAG, "In catch block of notification:"+e);
}