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

com.hadoopz.MyDroidLib.util.IDroidUtils Maven / Gradle / Ivy

There is a newer version: 1.0.62
Show newest version
/*
 * Copyright 2018 jw362j.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hadoopz.MyDroidLib.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import java.util.List;
import android.telephony.TelephonyManager;

/**
 *
 * @author jw362j
 */
public class IDroidUtils {

    public static boolean isPackageExists(Context context, String packageName) {
        if (context == null || TextUtils.isEmpty(packageName)) {
            return false;
        }
        PackageManager pm = context.getPackageManager();
        List packages = pm.getInstalledApplications(0);
        for (ApplicationInfo packageInfo : packages) {
            if (packageName.equals(packageInfo.packageName)) {
                return true;
            }
        }
        return false;
    }

    public interface AppPackageWatcher {

        void onPackage(ApplicationInfo applicationInfo);
    }

    public static void loadAllPackage(Context context, AppPackageWatcher packageWatcher) {
        if (context == null || packageWatcher == null) {
            return;
        }
        PackageManager pm = context.getPackageManager();
        List appInfos = pm.getInstalledApplications(0);

        for (ApplicationInfo packageInfo : appInfos) {
            packageWatcher.onPackage(packageInfo);
        }
    }

    public static boolean ishasSimCard(Context context) {
        TelephonyManager telMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        int simState = telMgr.getSimState();
        boolean result = true;
        switch (simState) {
            case TelephonyManager.SIM_STATE_ABSENT:
                result = false; // NO SIM
                break;
            case TelephonyManager.SIM_STATE_UNKNOWN:
                result = false;// NO SIM
                break;
        }
        //Log.d(TAG, result ? "has SIM" : "NO SIM");
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy