com.hadoopz.MyDroidLib.util.IDroidUtils Maven / Gradle / Ivy
/*
* 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;
}
}