3
2

More than 5 years have passed since last update.

"Not posting notification with icon==0:"と言われて通知が出ない

Posted at

問題

以下のようなログが出て通知領域に通知が出ない。

11:07:12.517      490-490/? E/NotificationService﹕ Not posting notification with icon==0: Notification(pri=0 contentView=info.snaka.unitygcmplugindemo/0x1090064 vibrate=null sound=null defaults=0x0 flags=0x0 kind=[null])
12-23 11:07:12.517      490-490/? E/NotificationService﹕ WARNING: In a future release this will crash the app: info.snaka.unitygcmplugindemo

解決

NotificationCompat.Builder で .setSmallIcon() が抜けていたため。
以下のようにsmallIcon()を追加。

builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("GCM Notification")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setContentText(msg);

問題2

上記を解決した後、今度は R$drawable が無いって言われる。

ava.lang.NoClassDefFoundError: info.snaka.unitygcmpluginlib.R$drawable

解決2

Unityがビルド時にリソースを置き換えてるっぽいので、Resourcesクラス使ってリソースを取得。

Assets/Plugins/Android/res/drawable に notify.png を用意して

先ほどの通知を作成している箇所を以下のように変更。

builder = new NotificationCompat.Builder(this)
                .setSmallIcon(getResources().getIdentifier("notify", "drawable", getPackageName()))
                .setContentTitle("GCM Notification")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setContentText(msg);

参考: UnityのAndroid用プラグインを作るときにリソースを含める方法

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2