0
A
回答
3
Android沒有這個特殊功能。
另一種方法是在通常情況下顯示數字,但應用圖標本身無法使用。
如果你真的想打破設計準則,你可以製作一個看起來像你的應用程序圖標的小部件,並且小部件可以更好地控制它的繪製方式。一些應用程序已經發布,爲Gmail,Google Voice,標準的消息應用程序執行此操作,並且未命名爲電話應用程序,並且它們僞裝成常規應用程序圖標,因此可以。我並不真的推薦這種方法,但它是可用的。
徽章
1
1. 使用ShortcutBadger庫計數
dependencies {
compile 'me.leolin:ShortcutBadger:[email protected]'
}
2.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "1. remoteMessage.getData().size() > 0");
Log.d(TAG, "Message data payload: " + remoteMessage.getData()); // {mobile=9458074124, name=Arvind}
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
Log.d(TAG, "Message getTitle: " + remoteMessage.getNotification().getTitle());
Map<String, String> notificationData1 = remoteMessage.getData();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Log.d(TAG, sharedPreferences.getString("userid", "") + ".....id"+notificationData1.get("action"));
try {
if (notificationData1.get("actionID").equalsIgnoreCase(sharedPreferences.getString("userid", ""))) {
} else {
showNotificationForEvent(remoteMessage);
// }
}
}catch (Exception e)
{
e.printStackTrace();
}
}
}
// Show Notification for Attend,Like,Comment,Rate
private void showNotificationForEvent(RemoteMessage remoteMessage) {
Log.d(TAG, "00. showNotificationForEvent");
Map<String,String> notificationData = remoteMessage.getData();
Intent resultIntent = new Intent(this, BubblesActivity.class);
resultIntent.putExtra("action", notificationData.get("action"));
resultIntent.putExtra("actionID", notificationData.get("actionID"));
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, resultIntent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ipray_appicon)
// .setColor(ContextCompat.getColor(this, R.color.textColor))
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody()/*+Utils.getPrefrence(getApplicationContext(), Const.KEY_USER_ID)+"...id"*/)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
//Vibration // new long[] { 1000, 1000, 1000, 1000, 1000 }
notificationBuilder.setVibrate(new long[] {500,1000});
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
//This method will return true if the app is in background.
private boolean isAppIsInBackground(Context context) {
boolean isInBackground = true;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD) {
List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (String activeProcess : processInfo.pkgList) {
if (activeProcess.equals(context.getPackageName())) {
isInBackground = false;
}
}
}
}
}
else {
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if (componentInfo.getPackageName().equals(context.getPackageName())) {
isInBackground = false;
}
}
return isInBackground;
}
@Override
protected Intent zzae(Intent intent) {
//Log.e("intentdata","DataPayload zzae"+intentToString(intent));
return super.zzae(intent);
}
@Override
public boolean zzag(Intent intent) {
Log.e("intentdata","DataPayload zzag==="+intentToString(intent).toString());
Log.e("intentdata","getData====="+intent.toString());
if(intent.hasExtra("totalprayerdue"))
{
ShortcutBadger.applyCount(getApplicationContext(), Integer.parseInt(intent.getStringExtra("totalprayerdue")));
}
return super.zzag(intent);
}
@Override
public void zzm(Intent intent) {
Log.e("intentdata","DataPayload zzm"+intentToString(intent));
super.zzm(intent);
}
public static String intentToString(Intent intent) {
if (intent == null)
return "";
StringBuilder stringBuilder = new StringBuilder("action: ")
.append(intent.getAction())
.append(" data: ")
.append(intent.getDataString())
.append(" extras: ")
;
for (String key : intent.getExtras().keySet())
stringBuilder.append(key).append("=").append(intent.getExtras().get(key)).append(" ");
return stringBuilder.toString();
}
}
相關問題
- 1. 在Android手機應用程序圖標中顯示徽章
- 2. 如何在應用程序圖標或小工具中顯示徽章計數
- 3. iPhone應用程序中的應用程序圖標徽章
- 4. 在android的應用程序圖標上添加通知徽章
- 5. 徽章計數未在iOS應用程序中顯示
- 6. 如何使用Redmi上的應用程序圖標顯示徽章數量?
- 7. TideSDK - 顯示未讀數(圖標徽章)
- 8. Windows Store Js應用程序:僅在鎖屏上顯示徽章,而不在活動圖塊上顯示徽章
- 9. 在沒有APNS的應用程序中顯示Apple Alert徽章
- 10. 應用程序圖標徽章計數顯示2爲第一次安裝
- 11. 如何在我的android應用程序中的啓動器圖標上顯示徽章計數?
- 12. 應用程序圖標徽章數量不增加:Xcode中
- 13. 僅iOS徽章LocalNotification在後臺應用程序中未顯示
- 14. 在iPhone混合應用程序中顯示徽章
- 15. Android - 如何在行動欄中顯示應用程序徽標
- 16. 如何在Xamarin Forms中顯示ToolBarItem圖標的徽章計數
- 17. 應用程序徽章
- 18. 圖書館反應本機應用程序圖標徽章
- 19. 何時需要移除android應用程序上的徽章圖標計數?
- 20. 從iOS應用程序中刪除徽章應用程序圖標
- 21. 有沒有辦法將徽章添加到Android中的應用程序圖標?
- 22. 如何使用pushNotification在Phonegap中的iOS應用程序中顯示徽章?
- 23. 應用程序徽章不顯示解析推送通知
- 24. 如何在Android應用程序(如iPhone)上創建通知圖標徽章
- 25. 如何在iPhone或iPad上將圖像顯示爲應用程序徽章?
- 26. Android:爲我的應用程序內部的圖標添加徽章
- 27. 我們可以顯示像iPhone一樣的android應用程序圖標上的徽章號碼嗎?
- 28. 是否可以自定義應用程序圖標徽章:Xcode?
- 29. 當通知到達時更改應用程序圖標徽章
- 30. 不能擺脫應用程序圖標徽章號
日Thnx。但小部件只是拖放到主屏幕?它不是放置在應用程序屏幕上。 –
因此,您想在應用程序打開時在應用程序圖標上顯示徽章數量? –
是的。那可能嗎?? –