add xiaomi launcher support
This commit is contained in:
parent
4ad8a6ffe8
commit
84f95fcbe9
|
|
@ -6,7 +6,7 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
applicationId "me.leolin.shortcutbadger.example"
|
||||
minSdkVersion 14
|
||||
minSdkVersion 10
|
||||
targetSdkVersion 19
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public abstract class ShortcutBadger {
|
|||
BADGERS.add(SamsungHomeBadger.class);
|
||||
BADGERS.add(SolidHomeBadger.class);
|
||||
BADGERS.add(SonyHomeBadger.class);
|
||||
BADGERS.add(XiaomiHomeBadger.class);
|
||||
}
|
||||
|
||||
private static final String MESSAGE_NOT_SUPPORT_BADGE_COUNT = "ShortBadger is currently not support the badgeCount \"%d\"";
|
||||
|
|
@ -95,6 +96,10 @@ public abstract class ShortcutBadger {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) {
|
||||
mShortcutBadger = new XiaomiHomeBadger(context);
|
||||
return mShortcutBadger;
|
||||
}
|
||||
|
||||
for (Class<? extends ShortcutBadger> badger : BADGERS) {
|
||||
Constructor<? extends ShortcutBadger> constructor = badger.getConstructor(Context.class);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import java.util.List;
|
|||
* @author Leo Lin
|
||||
*/
|
||||
public class AndroidHomeBadger extends ShortcutBadger {
|
||||
private static final String CONTENT_URI = "content://com.android.launcher.settings/favorites?notify=true";
|
||||
private static final String CONTENT_URI = "content://com.android.launcher2.settings/favorites?notify=true";
|
||||
|
||||
public AndroidHomeBadger(Context context) {
|
||||
super(context);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package me.leolin.shortcutbadger.impl;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import me.leolin.shortcutbadger.ShortcutBadgeException;
|
||||
import me.leolin.shortcutbadger.ShortcutBadger;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author leolin
|
||||
*/
|
||||
public class XiaomiHomeBadger extends ShortcutBadger {
|
||||
|
||||
public static final String INTENT_ACTION = "android.intent.action.APPLICATION_MESSAGE_UPDATE";
|
||||
public static final String EXTRA_UPDATE_APP_COMPONENT_NAME = "android.intent.extra.update_application_component_name";
|
||||
public static final String EXTRA_UPDATE_APP_MSG_TEXT = "android.intent.extra.update_application_message_text";
|
||||
|
||||
public XiaomiHomeBadger(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeBadge(int badgeCount) throws ShortcutBadgeException {
|
||||
try {
|
||||
Class miuiNotificationClass = Class.forName("android.app.MiuiNotification");
|
||||
Object miuiNotification = miuiNotificationClass.newInstance();
|
||||
Field field = miuiNotification.getClass().getDeclaredField("messageCount");
|
||||
field.setAccessible(true);
|
||||
field.set(miuiNotification, String.valueOf(badgeCount == 0 ? "" : badgeCount));
|
||||
} catch (Exception e) {
|
||||
Intent localIntent = new Intent(
|
||||
INTENT_ACTION);
|
||||
localIntent.putExtra(EXTRA_UPDATE_APP_COMPONENT_NAME, getContextPackageName() + "/" + getEntryActivityName());
|
||||
localIntent.putExtra(EXTRA_UPDATE_APP_MSG_TEXT, String.valueOf(badgeCount == 0 ? "" : badgeCount));
|
||||
mContext.sendBroadcast(localIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSupportLaunchers() {
|
||||
return Arrays.asList("com.miui.miuilite","com.miui.miuihome","com.miui.miuihome2");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue