All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yy.httpproxy.util.ServiceCheckUtil Maven / Gradle / Ivy

There is a newer version: 1.1.28
Show newest version
package com.yy.httpproxy.util;

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

import com.yy.httpproxy.service.ConnectionService;
import com.yy.httpproxy.util.Log;

import java.util.List;

public class ServiceCheckUtil {

    public static boolean isBroadcastReceiverAvailable(Context context, Class className) {
        final PackageManager packageManager = context.getPackageManager();
        try {
            final Intent intent = new Intent(context, className);
            List resolveInfo =
                    packageManager.queryBroadcastReceivers(intent,
                            0);
            Log.d("ServiceCheckUtil", "isBroadcastReceiverAvailable " + className + " " + resolveInfo.size());
            return resolveInfo.size() > 0;
        } catch (Exception e) {
            return false;
        }
    }

    public static boolean isIntentServiceAvailable(Context context, Class className) {
        final PackageManager packageManager = context.getPackageManager();
        try {
            final Intent intent = new Intent(context, className);
            List resolveInfo =
                    packageManager.queryIntentServices(intent,
                            0);
            Log.d("ServiceCheckUtil", "isIntentServiceAvailable " + className + " " + resolveInfo.size());
            return resolveInfo.size() > 0;
        } catch (Exception e) {
            return false;
        }
    }

    public static String getPushProcessName(Context context) {
        final PackageManager packageManager = context.getPackageManager();
        try {
            final Intent intent = new Intent(context, ConnectionService.class);
            List resolveInfo =
                    packageManager.queryIntentServices(intent,
                            0);
            if (resolveInfo.size() > 0) {
                String processName = resolveInfo.get(0).serviceInfo.processName;
                Log.d("ServiceCheckUtil", "ConnectionService process " + processName);
                return processName;
            }
            return "";
        } catch (Exception e) {
            return "";
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy