0

我是一些什麼意識到科爾多瓦,現在我在我的插件類中實現通知。原生通知android代碼在科爾多瓦插件java類

我已經使用了下面的android代碼在我的java類中創建通知。 我已經導入了與通知相關的所有軟件包。 但我得到通知異常,並無法得到通知

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]) 

一些機構可以提出建議寫通知邏輯在科爾多瓦插件java類?

回答

0

最後,我已經做了一些修改,建立通知對象,它爲我工作。

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); 
    } 
0

我相信你需要提供至少一個小圖標。

取消註釋.setSmallIcon(1)並用資源ID替換1,以便將drawable用作通知中的圖標。

+0

但它是java類,它是說:「在R.drawable.notification_icon找不到符號R上。 我沒有任何資源類在我的混合應用程序導入。 @Jim羅茲 –