send Badge To Sony - Android Hardware

Android examples for Hardware:Vendor

Description

send Badge To Sony

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 sendBadgeToSony(int number) {
        Context context = App.getInstance();
        boolean isShow = true;
        if (0 >= number) {
            isShow = false;/*from w  w  w  .  j  a v a 2  s. c om*/
        }
        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",
                getLauncherClassName(context));//?????
        localIntent.putExtra(
                "com.sonyericsson.home.intent.extra.badge.MESSAGE",
                String.valueOf(number));//??
        localIntent.putExtra(
                "com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME",
                context.getPackageName());//????
        context.sendBroadcast(localIntent);
    }
    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