問題
以下のようなログが出て通知領域に通知が出ない。
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);