zoukankan      html  css  js  c++  java
  • TelephonyUtil

    package com.android.demo.lileidemo.utils;

    import android.Manifest;
    import android.content.Context;
    import android.content.pm.PackageManager;
    import android.support.v4.app.ActivityCompat;
    import android.telephony.TelephonyManager;

    import com.android.demo.lileidemo.MyApplication;
    import com.android.demo.lileidemo.constant.AppConstants;
    import com.ford.sync.basics.utils.LogUtil;

    /**
    * date: 03/26/2020.
    * author: lilei.
    */
    public class TelephonyUtil {
    private static final String TAG = AppConstants.APP_TAG + "TelephonyUtil ";
    private Context mContext;
    private static volatile TelephonyUtil mInstance;
    private TelephonyManager mTelephonyManager;

    public TelephonyUtil() {
    mContext = MyApplication.getAppContext();
    mTelephonyManager = (TelephonyManager)
    mContext.getSystemService(Context.TELEPHONY_SERVICE);
    }

    /**
    * get Instance.
    *
    * @return instance.
    */
    public static TelephonyUtil getInstance() {
    if (mInstance == null) {
    synchronized (TelephonyUtil.class) {
    if (mInstance == null) {
    mInstance = new TelephonyUtil();
    }
    }
    }
    return mInstance;
    }

    public String getIccid() {
    if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
    // TODO: Consider calling
    LogUtil.e(TAG + "getIccid need permission READ_PHONE_STATE!! please check!");
    return null;
    }
    String iccid = mTelephonyManager.getSimSerialNumber();
    return iccid;
    }

    public String getImei() {
    if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
    // TODO: Consider calling
    LogUtil.e(TAG + "getIccid need permission READ_PHONE_STATE!! please check!");
    return null;
    }
    String imei = mTelephonyManager.getImei();
    return imei;
    }
    }
  • 相关阅读:
    我的WCF之旅(1):创建一个简单的WCF程序
    网页设计中颜色的搭配
    CSS HACK:全面兼容IE6/IE7/IE8/FF的CSS HACK
    UVa 1326 Jurassic Remains
    UVa 10340 All in All
    UVa 673 Parentheses Balance
    UVa 442 Matrix Chain Multiplication
    UVa 10970 Big Chocolate
    UVa 679 Dropping Balls
    UVa 133 The Dole Queue
  • 原文地址:https://www.cnblogs.com/adamli/p/13139813.html
Copyright © 2011-2022 走看看