send Badge To Apex - Android Hardware

Android examples for Hardware:Vendor

Description

send Badge To Apex

Demo Code


import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

public class Main{
    private static void sendBadgeToApex(Context context,int number) {


        final String ACTION_COUNTER_CHANGED = "com.anddoes.launcher.COUNTER_CHANGED";
        final String EXTRA_NOTIFY_PACKAGE = "package";
        final String EXTRA_NOTIFY_CLASS = "class";
        final String EXTRA_NOTIFY_COUNT = "count";

        final String packageName = context.getPackageName();
        final String className = getLauncherClassName(context);

        Intent intent = new Intent(ACTION_COUNTER_CHANGED);
        intent.putExtra(EXTRA_NOTIFY_PACKAGE, packageName);
        intent.putExtra(EXTRA_NOTIFY_CLASS, className);
        intent.putExtra(EXTRA_NOTIFY_COUNT, number);
        context.sendBroadcast(intent);// w w  w . java  2s  . co  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