send Badge To Huawei - Android Hardware

Android examples for Hardware:Vendor

Description

send Badge To Huawei

Demo Code


import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.Vibrator;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;

public class Main{
    private static void sendBadgeToHuawei(int number) {
        Context context = App.getInstance();

        Bundle localBundle = new Bundle();
        localBundle.putString("package", context.getPackageName());
        localBundle.putString("class", getLauncherClassName(context));
        localBundle.putInt("badgenumber", number);
        try {/*from w  w w .ja v  a  2s  . c  o m*/
            context.getContentResolver()
                    .call(Uri
                            .parse("content://com.huawei.android.launcher.settings/badge/"),
                            "change_badge", null, localBundle);
        } catch (Exception e) {
        }
    }
    public static String getLauncherClassName(Context context) {

        PackageManager pm = context.getPackageManager();

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> resolveInfos = pm
                .queryIntentActivities(intent, 0);
        for (ResolveInfo resolveInfo : resolveInfos) {
            String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
            if (pkgName.equalsIgnoreCase(context.getPackageName())) {
                String className = resolveInfo.activityInfo.name;
                return className;
            }
        }
        return null;
    }
}

Related Tutorials