私はAndroidのアクティブな通知を読むためのアプリを開発しています。これまで私はEXTRA_SMALL_ICONを取得することに固執するまで成功しています。私はアプリのアイコンと大きなアイコンを取得するために次のコードを使用し、両方ともうまく動作します。Android NotificationListenerService get EXTRA_SMALL_ICONは常にnullを返します
//は細かい
Drawable appIcon = null;
try {
appIcon = getPackageManager().getApplicationIcon(packageName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
//はSMALL_ICONは、次の例外をスロー取得
Bitmap smallIcon = null;
try {
smallIcon = (Bitmap) notification.extras.getParcelable(Notification.EXTRA_SMALL_ICON);
} catch (Exception e) {
e.printStackTrace();
}
を働いていない細かい
Bitmap largeIcon = null;
try {
largeIcon = (Bitmap) notification.extras.getParcelable(Notification.EXTRA_LARGE_ICON);
} catch (Exception e) {
e.printStackTrace();
}
//ワークス。
Key android.icon expected Parcelable but value was a java.lang.Integer. The default value <null> was returned.
W/Bundle: Attempt to cast generated internal exception:
java.lang.ClassCastException: java.lang.Integer cannot be cast to android.os.Parcelable
はい、私が取得しようとしている通知には小さなアイコンが設定されています。何か間違っているのですか?またはgt SMALL_ICONに他の方法がありますか?なぜ私は理解できません。
ありがとうございます!
小さなアイコンが描画可能リソースIDでないビットマップとして渡されている使用後に、この
にそれを変更してみてください。通知の作成と同じ方法です。 –