send Badge To Samsung - Android Hardware

Android examples for Hardware:Vendor

Description

send Badge To Samsung

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 sendBadgeToSamsung(int number) {
        Context context = App.getInstance();
        Intent localIntent = new Intent(
                "android.intent.action.BADGE_COUNT_UPDATE");
        localIntent.putExtra("badge_count", number);//??
        localIntent.putExtra("badge_count_package_name",
                context.getPackageName());//????
        localIntent.putExtra("badge_count_class_name",
                getLauncherClassName(context)); //?????
        context.sendBroadcast(localIntent);
    }/*w  w  w  .ja v a2s. c o m*/
    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