質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Cordova

Cordovaは様々なデバイスで使うことができるオープンソースなモバイル用開発プラットフォームです。開発者に各デバイスの元のプラットフォームで開発する必要をなくし、HTML・JavaScript・CSSなどの一般的なウェブのテクノロジーを使ってすべてのデバイスで展開することができるモバイルのアプリケーションを生成することを可能にします。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

解決済

1回答

7232閲覧

ステータスバーの通知アイコンが変更できない

Clementine

総合スコア157

Cordova

Cordovaは様々なデバイスで使うことができるオープンソースなモバイル用開発プラットフォームです。開発者に各デバイスの元のプラットフォームで開発する必要をなくし、HTML・JavaScript・CSSなどの一般的なウェブのテクノロジーを使ってすべてのデバイスで展開することができるモバイルのアプリケーションを生成することを可能にします。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

1クリップ

投稿2015/09/11 12:44

表記の件につきまして質問致します。
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)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

プッシュ通知は受け取れているのですよね?
setSmallIcon(context.getApplicationInfo().icon)
で通知するときのアイコンを指定しています。
このままだと、アプリで設定されたiconにります。
通知するときに使用したいicon画像はありますでしょうか?
その画像を
project/res/drawable/ フォルダ以下
または
project/res/mipmap/ フォルダ以下
においてください。(Android StudioやEclipseによってpathは違います)
(最近のAndroidならmipmap推奨です。また、mipmap-hdpiみたいなフォルダがありますが、これらのフォルダ以下にサイズの異なる画像を指定することで、Androidの端末に合わせて表示する画像を変えてくれるものなので、端末に合わせたサイズの画像を指定したい場合はこちらにいれてください。端末いぞさせなくていい場合はmipmap-nodpiフォルダにおいてください)

画像をフォルダにおいたら、
setSmallIcon(R.drawable.<拡張子抜きのファイル名>)
または
setSmallIcon(R.mipmap.<拡張子抜きのファイル名>)
というものが指定できるようになっているはずなので、これを指定すればiconを変更できます。
(例えば: setSmallIcon(R.mipmap.icon))

投稿2015/09/12 09:06

taptappun

総合スコア69

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問