package com.zxhl.cms.utils;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

public class BadgeUtil {
    public static void updateBadge(final Context context, final int number) {
        LogUtils.i("badge = " + number);
        if (BrandUtil.isBrandHuawei()) {
            try {
                Bundle extra = new Bundle();
                extra.putString("package", "com.huiyujiaoyu.powertime");
                extra.putString("class", "com.huiyujiaoyu.powertime.ui.activity.SplashActivity");
                extra.putInt("badgenumber", number);
                context.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher.settings/badge/"), "change_badge", null, extra);
            } catch (Exception e) {
                LogUtils.i("huawei badge exception: " + e.getLocalizedMessage());
            }
        }

//        if (BrandUtil.isBrandXiaoMi()) {
           /* NotificationManager mNotificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            Notification.Builder builder = new Notification.Builder(context)
                    .setContentTitle("").setContentText("").setSmallIcon(R.drawable.ic_launcher);

            Notification notification = builder.build();
            try {
                Field field = notification.getClass().getDeclaredField("extraNotification");
                Object extraNotification = field.get(notification);
                Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
                method.invoke(extraNotification, number);
            } catch (Exception e) {
                 e.printStackTrace();
            // miui 6之前的版本
            Intent localIntent = new Intent(
                    "android.intent.action.APPLICATION_MESSAGE_UPDATE");
            localIntent.putExtra(
                    "android.intent.extra.update_application_component_name",
                    context.getPackageName() + "/" + getLauncherClassName(context));
            localIntent.putExtra(
                    "android.intent.extra.update_application_message_text", String.valueOf(count == 0 ? "" : count));
            context.sendBroadcast(localIntent);
            }
            mNotificationManager.notify(0,notification);*/
          /*  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();
                // miui6之前
                Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE");
                localIntent.putExtra("android.intent.extra.update_application_component_name", context.getPackageName() + "/." + "MainActivity");
                localIntent.putExtra("android.intent.extra.update_application_message_text", String.valueOf(number == 0 ? "" : number));
                context.sendBroadcast(localIntent);
            }*/
//        }
    }
}
