表記の件につきまして質問致します。
CordovaでAndroidアプリのサーバから端末へのプッシュ通知をする機能を用意しておりますが、ステータスバーの通知アイコンの変更ができません。
javaの知識は殆どありませんが、調べた限りだと
java
1setSmallIcon(context.getApplicationInfo().icon)
で失敗しているのではと以下のログから推測する次第です。
txt
109-11 21:06:44.059: W/IInputConnectionWrapper(26298): showStatusIcon on inactive InputConnection
この原因調査や、対応方法について情報がありましたら、何卒ご教授をお願い致します。
補足資料になりますが、以下にsetSmallIcon を指定しているメソッドを記します。
java
1 public void createNotification(Context context, Bundle extras) 2 { 3 NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 4 String appName = getAppName(this); 5 6 Intent notificationIntent = new Intent(this, PushHandlerActivity.class); 7 notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); 8 notificationIntent.putExtra("pushBundle", extras); 9 10 int requestCode = new Random().nextInt(); 11 PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 12// PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 13 14 int defaults = Notification.DEFAULT_ALL; 15 16 if (extras.getString("defaults") != null) { 17 try { 18 defaults = Integer.parseInt(extras.getString("defaults")); 19 } catch (NumberFormatException e) {} 20 } 21 22 NotificationCompat.Builder mBuilder = 23 new NotificationCompat.Builder(context) 24 .setDefaults(defaults) 25 .setSmallIcon(context.getApplicationInfo().icon) 26 .setWhen(System.currentTimeMillis()) 27 .setContentTitle(extras.getString("title")) 28 .setTicker(extras.getString("title")) 29 .setContentIntent(contentIntent) 30 .setAutoCancel(true); 31 32 String message = extras.getString("message"); 33 if (message != null) { 34 mBuilder.setContentText(message); 35 } else { 36 mBuilder.setContentText("<missing message content>"); 37 } 38 39 String msgcnt = extras.getString("msgcnt"); 40 if (msgcnt != null) { 41 mBuilder.setNumber(Integer.parseInt(msgcnt)); 42 } 43 44 int notId = 0; 45 46 try { 47 notId = Integer.parseInt(extras.getString("notId")); 48 } 49 catch(NumberFormatException e) { 50 Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage()); 51 } 52 catch(Exception e) { 53 Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage()); 54 } 55 56 // notId が無い場合は重複するので乱数から生成 57 if (notId == 0) { 58 notId = new Random().nextInt(100000); 59 Log.d(TAG, "Generated random notId: " + notId); 60 } else { 61 Log.d(TAG, "Received notId: " + notId); 62 } 63 64 mNotificationManager.notify((String) appName, notId, mBuilder.build()); 65 }
以下、プッシュ通知を端末が受信した際のログになります。
txt
1x109-11 21:07:07.056: V/GCMBroadcastReceiver(26298): onReceive: com.google.android.c2dm.intent.RECEIVE 209-11 21:07:07.057: V/GCMBroadcastReceiver(26298): GCM IntentService class: com.plugin.gcm.GCMIntentService 309-11 21:07:07.057: V/GCMBaseIntentService(26298): Acquiring wakelock 409-11 21:07:07.066: V/GCMBaseIntentService(26298): Intent service name: GCMIntentService-GCMIntentService-2 509-11 21:07:07.072: D/GCMIntentService(26298): onMessage - context: android.app.Application@1a33275f 609-11 21:07:07.077: E/GCMIntentService(26298): Number format exception - Error parsing Notification ID: Invalid int: "null" 709-11 21:07:07.078: D/GCMIntentService(26298): Generated random notId: 49777 809-11 21:07:07.201: V/GCMBaseIntentService(26298): Releasing wakelock 909-11 21:07:15.697: I/chromium(26298): [INFO:CONSOLE(25)] "No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.", source: file:///android_asset/www/plugins/cordova-plugin-whitelist/whitelist.js (25)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。