1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| public class MainActivity extends Activity { private final static String lancherActivityClassName = Welcome.class.getName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.common_listview_layout); }
@Override protected void onResume() { super.onResume(); sendBadgeNumber(); } private void sendBadgeNumber() { String number = "35"; if (TextUtils.isEmpty(number)) { number = ""; } else { int numInt = Integer.valueOf(number); number = String.valueOf(Math.max(0, Math.min(numInt, 99))); }
if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) { sendToXiaoMi(number); } else if (Build.MANUFACTURER.equalsIgnoreCase("samsung")) { sendToSony(number); } else if (Build.MANUFACTURER.toLowerCase().contains("sony")) { sendToSamsumg(number); } else { Toast.makeText(this, "Not Support", Toast.LENGTH_LONG).show(); } } private void sendToXiaoMi(String number) { try { Class miuiNotificationClass = Class.forName("android.app.MiuiNotification"); Object miuiNotification = miuiNotificationClass.newInstance(); Field field = miuiNotification.getClass().getDeclaredField("messageCount"); field.setAccessible(true); field.set(miuiNotification, number); } catch (Exception e) { e.printStackTrace(); Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE"); localIntent.putExtra("android.intent.extra.update_application_component_name",getPackageName() + "/"+ lancherActivityClassName ); localIntent.putExtra("android.intent.extra.update_application_message_text",number); sendBroadcast(localIntent); }
} private void sendToSony(String number) { boolean isShow = true; if ("0".equals(number)) { isShow = false; } Intent localIntent = new Intent(); localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE",isShow); localIntent.setAction("com.sonyericsson.home.action.UPDATE_BADGE"); localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME",lancherActivityClassName ); localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", number); localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME",getPackageName()); sendBroadcast(localIntent);
Toast.makeText(this, "Sony," + "isSendOk", Toast.LENGTH_LONG).show(); }
private void sendToSamsumg(String number) { Intent localIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); localIntent.putExtra("badge_count", number); localIntent.putExtra("badge_count_package_name", getPackageName()); localIntent.putExtra("badge_count_class_name",lancherActivityClassName ); sendBroadcast(localIntent); Toast.makeText(this, "Samsumg," + "isSendOk", Toast.LENGTH_LONG).show(); } }
|