欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

怎么在Android中獲取手機的SIM卡信息

今天就跟大家聊聊有關怎么在Android中獲取手機的SIM卡信息,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

成都創(chuàng)新互聯從2013年成立,是專業(yè)互聯網技術服務公司,擁有項目成都網站建設、網站制作網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元華容做網站,已為上家服務,為華容各地企業(yè)和個人服務,聯系電話:18982081108

Android 獲取本機手機號(適用于雙卡雙待手機)

直接上代碼:

import java.lang.reflect.InvocationTargetException; 
import java.lang.reflect.Method; 
import java.util.List; 

import android.app.Activity; 
import android.content.Context; 
import android.content.SharedPreferences; 
import android.content.SharedPreferences.Editor; 
import android.os.Bundle; 
import android.preference.PreferenceManager; 
import android.telephony.CellInfo; 
import android.telephony.TelephonyManager; 
import android.view.Menu; 
import android.widget.TextView; 

public class MainActivity extends Activity 
{ 

 private TextView tv; 
 private TextView tv2; 
 // /////////////////////////////////// 
 static String  ISDOUBLE; 
 static String  SIMCARD; 
 static String  SIMCARD_1; 
 static String  SIMCARD_2; 
 static boolean  isDouble; 

 // ////////////////////////////////// 

 @Override 
 protected void onCreate(Bundle savedInstanceState) 
 { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.activity_main); 

  tv = (TextView) findViewById(R.id.text); 
  tv2 = (TextView) findViewById(R.id.text2); 

  tv2.setText("不知道哪個卡可用!"); 

  getNumber(); 

 } 

 private void getNumber() 
 { 
  TelephonyManager tm = (TelephonyManager) this.getSystemService(this.TELEPHONY_SERVICE); 
  String phoneNumber1 = tm.getLine1Number(); 

  // String phoneNumber2 = tm.getGroupIdLevel1(); 

  initIsDoubleTelephone(this); 
  if (isDouble) 
  { 
   // tv.setText("這是雙卡手機!"); 
   tv.setText("本機號碼是:" + " " + phoneNumber1 + " " + "這是雙卡手機!"); 
  } else 
  { 
   // tv.setText("這是單卡手機"); 
   tv.setText("本機號碼是:" + " " + phoneNumber1 + " " + "這是單卡手機"); 
  } 

 } 

 public void initIsDoubleTelephone(Context context) 
 { 
  isDouble = true; 
  Method method = null; 
  Object result_0 = null; 
  Object result_1 = null; 
  TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
  try 
  { 
   // 只要在反射getSimStateGemini 這個函數時報了錯就是單卡手機(這是我自己的經驗,不一定全正確) 
   method = TelephonyManager.class.getMethod("getSimStateGemini", new Class[] 
   { int.class }); 
   // 獲取SIM卡1 
   result_0 = method.invoke(tm, new Object[] 
   { new Integer(0) }); 
   // 獲取SIM卡2 
   result_1 = method.invoke(tm, new Object[] 
   { new Integer(1) }); 
  } catch (SecurityException e) 
  { 
   isDouble = false; 
   e.printStackTrace(); 
   // System.out.println("1_ISSINGLETELEPHONE:"+e.toString()); 
  } catch (NoSuchMethodException e) 
  { 
   isDouble = false; 
   e.printStackTrace(); 
   // System.out.println("2_ISSINGLETELEPHONE:"+e.toString()); 
  } catch (IllegalArgumentException e) 
  { 
   isDouble = false; 
   e.printStackTrace(); 
  } catch (IllegalAccessException e) 
  { 
   isDouble = false; 
   e.printStackTrace(); 
  } catch (InvocationTargetException e) 
  { 
   isDouble = false; 
   e.printStackTrace(); 
  } catch (Exception e) 
  { 
   isDouble = false; 
   e.printStackTrace(); 
   // System.out.println("3_ISSINGLETELEPHONE:"+e.toString()); 
  } 
  SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 
  Editor editor = sp.edit(); 
  if (isDouble) 
  { 
   // 保存為雙卡手機 
   editor.putBoolean(ISDOUBLE, true); 
   // 保存雙卡是否可用 
   // 如下判斷哪個卡可用.雙卡都可以用 
   if (result_0.toString().equals("5") && result_1.toString().equals("5")) 
   { 
    if (!sp.getString(SIMCARD, "2").equals("0") && !sp.getString(SIMCARD, "2").equals("1")) 
    { 
     editor.putString(SIMCARD, "0"); 
    } 
    editor.putBoolean(SIMCARD_1, true); 
    editor.putBoolean(SIMCARD_2, true); 

    tv2.setText("雙卡可用"); 

   } else if (!result_0.toString().equals("5") && result_1.toString().equals("5")) 
   {// 卡二可用 
    if (!sp.getString(SIMCARD, "2").equals("0") && !sp.getString(SIMCARD, "2").equals("1")) 
    { 
     editor.putString(SIMCARD, "1"); 
    } 
    editor.putBoolean(SIMCARD_1, false); 
    editor.putBoolean(SIMCARD_2, true); 

    tv2.setText("卡二可用"); 

   } else if (result_0.toString().equals("5") && !result_1.toString().equals("5")) 
   {// 卡一可用 
    if (!sp.getString(SIMCARD, "2").equals("0") && !sp.getString(SIMCARD, "2").equals("1")) 
    { 
     editor.putString(SIMCARD, "0"); 
    } 
    editor.putBoolean(SIMCARD_1, true); 
    editor.putBoolean(SIMCARD_2, false); 

    tv2.setText("卡一可用"); 

   } else 
   {// 兩個卡都不可用(飛行模式會出現這種種情況) 
    editor.putBoolean(SIMCARD_1, false); 
    editor.putBoolean(SIMCARD_2, false); 

    tv2.setText("飛行模式"); 
   } 
  } else 
  { 
   // 保存為單卡手機 
   editor.putString(SIMCARD, "0"); 
   editor.putBoolean(ISDOUBLE, false); 
  } 
  editor.commit(); 
 } 

 @Override 
 public boolean onCreateOptionsMenu(Menu menu) 
 { 
  // Inflate the menu; this adds items to the action bar if it is present. 
  getMenuInflater().inflate(R.menu.main, menu); 
  return true; 
 } 

}

當然不要忘記添加權限:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

獲取雙卡雙待手機SIM卡信息

使用反射遍歷 TelephonyManager 中的方法,通過肉眼基本能找到獲取雙卡雙待號碼的方法,最后通過反射取到 SIM 卡信息。

// 遍歷 TelephonyManager 里的方法
public void printTelephonyManagerMethodNamesForThisDevice() {
 TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 Class<?> telephonyClass;
 try {
  telephonyClass = Class.forName(telephony.getClass().getName());
  Method[] methods = telephonyClass.getMethods();
  for (int i = 0; i < methods.length; i++) {
   Log.i(TAG, "\n" + methods[i] + " declared by " + methods[i].getDeclaringClass());
  }
 } catch (ClassNotFoundException e) {
  e.printStackTrace();
 }
}
// 獲取雙卡雙待 SIM 卡序列號
public void getSubscriberId() {
 TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 Class<?> telephonyClass;
 Object result = null;
 Object result0 = null;
 Object result1 = null;
 try {
  telephonyClass = Class.forName(telephony.getClass().getName());
  Method m1 = telephonyClass.getMethod("getSubscriberId");
  Method m2 = telephonyClass.getMethod("getSubscriberId", new Class[]{int.class});
  result = m1.invoke(telephony);
  result0 = m2.invoke(telephony, 0);
  result1 = m2.invoke(telephony, 1);
 } catch (Exception e) {
  e.printStackTrace();
 }
 Log.i(TAG, " getSubscriberId : " + telephony.getSubscriberId() + "\n"
   + " result : " + result + "\n"
   + " result0 : " + result0 + "\n"
   + " result1 : " + result1 + "\n");
}

看完上述內容,你們對怎么在Android中獲取手機的SIM卡信息有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注創(chuàng)新互聯行業(yè)資訊頻道,感謝大家的支持。

文章名稱:怎么在Android中獲取手機的SIM卡信息
路徑分享:http://chinadenli.net/article14/ppccge.html

成都網站建設公司_創(chuàng)新互聯,為您提供域名注冊、云服務器、外貿網站建設網站收錄、網站改版外貿建站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

網站優(yōu)化排名
丰满少妇被猛烈撞击在线视频| 99精品国产一区二区青青| 久久久精品日韩欧美丰满| 欧美国产日韩在线综合| 久久大香蕉精品在线观看| 日韩欧美精品一区二区三区| 色偷偷偷拍视频在线观看| 成人精品一级特黄大片| 亚洲成人久久精品国产| 欧美成人精品国产成人综合| 成人免费高清在线一区二区| 丰满少妇被粗大猛烈进出视频| 国产传媒中文字幕东京热| 欧美亚洲另类久久久精品| 欧美日韩国产福利在线观看| 国产成人精品在线一区二区三区| 日韩在线一区中文字幕| 五月婷日韩中文字幕四虎| 国产老女人性生活视频| 国产男女激情在线视频| 中文字幕日韩欧美理伦片| 少妇激情在线免费观看| 99久久免费看国产精品| 国内精品伊人久久久av高清| 视频一区二区黄色线观看| 97人妻精品一区二区三区男同| 国产精品福利精品福利| 日本精品理论在线观看| 色一情一伦一区二区三| 在线观看免费午夜福利| 加勒比系列一区二区在线观看 | 欧美一区二区三区99| 一级欧美一级欧美在线播| 免费啪视频免费欧美亚洲| 亚洲欧美日韩中文字幕二欧美| 人人妻人人澡人人夜夜| 中文日韩精品视频在线| 久久99青青精品免费观看| 亚洲中文字幕亲近伦片| 欧美日韩国产免费看黄片| 一区二区三区日韩在线|