| | |
| | | package com.lcjian.library.util.common; |
| | | |
| | | import android.Manifest; |
| | | import android.app.Application; |
| | | import android.content.Context; |
| | | import android.content.pm.PackageInfo; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Build; |
| | | import android.provider.Settings; |
| | | import android.telephony.TelephonyManager; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import androidx.core.app.ActivityCompat; |
| | | |
| | | import static android.content.Context.TELEPHONY_SERVICE; |
| | | |
| | |
| | | return installedPackages; |
| | | } |
| | | |
| | | public static synchronized List<PackageInfo> getInstalledPackages(Context context) { |
| | | PackageManager pManager = context.getPackageManager(); |
| | | //获取手机内所有应用 |
| | | installedPackages = pManager.getInstalledPackages(0); |
| | | return installedPackages; |
| | | } |
| | | |
| | | |
| | | public static synchronized List<String> getInstalledPackageNamesCache(Context context) { |
| | | List<PackageInfo> list = getInstalledPackagesCache(context); |
| | |
| | | } |
| | | |
| | | public static synchronized String getImeiCache(Context context) { |
| | | if(imei!=null){ |
| | | if (imei != null) { |
| | | return imei; |
| | | } |
| | | |
| | | TelephonyManager manager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE); |
| | | try { |
| | | imei = manager.getDeviceId(); |
| | | }catch(Exception e){ |
| | | |
| | | if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { |
| | | return null; |
| | | } |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| | | imei = manager.getImei(); |
| | | }else{ |
| | | imei = manager.getDeviceId(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | imei = imei == null ? "" : imei; |
| | | return imei; |
| | | } |
| | | |
| | | public static synchronized String getAndroidIdCache(Context context){ |
| | | if(android_id!=null){ |
| | | public static synchronized String getAndroidIdCache(Context context) { |
| | | if (android_id != null) { |
| | | return android_id; |
| | | } |
| | | try { |
| | | android_id = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); |
| | | }catch(Exception e){ |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | android_id = android_id == null ? "" : android_id; |
| | |
| | | } |
| | | |
| | | |
| | | public static synchronized String getImsiCache(Context context){ |
| | | if(imsi!=null){ |
| | | public static synchronized String getImsiCache(Context context) { |
| | | if (imsi != null) { |
| | | return imsi; |
| | | } |
| | | TelephonyManager mTelephonyMgr = (TelephonyManager) context |
| | | .getSystemService(Context.TELEPHONY_SERVICE); |
| | | try { |
| | | imsi = mTelephonyMgr.getSubscriberId(); |
| | | }catch(Exception e){ |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | imsi = imsi == null ? "" : imsi; |