Android獲取手機(jī)號(hào)碼和運(yùn)營(yíng)商信息的方法
本文實(shí)例講述了Android獲取手機(jī)號(hào)碼和運(yùn)營(yíng)商信息的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
/**
* class name:AndroidUtilActivity<BR>
* class description:show get sim card info activity<BR>
* PS:注意權(quán)限 <BR>
* Date:2012-3-12<BR>
* @version 1.00
* @author CODYY)peijiangping
*/
public class AndroidUtilActivity extends Activity {
private Button button_getSIMInfo;
private TextView number;
private TextView privoid;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button_getSIMInfo = (Button) this.findViewById(R.id.getSIMInfo);
number = (TextView) this.findViewById(R.id.textView1);
privoid = (TextView) this.findViewById(R.id.textView2);
button_getSIMInfo.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
if (v == button_getSIMInfo) {
SIMCardInfo siminfo = new SIMCardInfo(AndroidUtilActivity.this);
System.out.println(siminfo.getProvidersName());
System.out.println(siminfo.getNativePhoneNumber());
number.setText(siminfo.getNativePhoneNumber());
privoid.setText(siminfo.getProvidersName());
}
}
}
}
import android.content.Context;
import android.telephony.TelephonyManager;
/**
* class name:SIMCardInfo<BR>
* class description:讀取Sim卡信息<BR>
* PS: 必須在加入各種權(quán)限 <BR>
* Date:2012-3-12<BR>
*
* @version 1.00
* @author CODYY)peijiangping
*/
public class SIMCardInfo {
/**
* TelephonyManager提供設(shè)備上獲取通訊服務(wù)信息的入口。 應(yīng)用程序可以使用這個(gè)類方法確定的電信服務(wù)商和國(guó)家 以及某些類型的用戶訪問(wèn)信息。
* 應(yīng)用程序也可以注冊(cè)一個(gè)監(jiān)聽器到電話收狀態(tài)的變化。不需要直接實(shí)例化這個(gè)類
* 使用Context.getSystemService(Context.TELEPHONY_SERVICE)來(lái)獲取這個(gè)類的實(shí)例。
*/
private TelephonyManager telephonyManager;
/**
* 國(guó)際移動(dòng)用戶識(shí)別碼
*/
private String IMSI;
public SIMCardInfo(Context context) {
telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
}
/**
* Role:獲取當(dāng)前設(shè)置的電話號(hào)碼
* <BR>Date:2012-3-12
* <BR>@author CODYY)peijiangping
*/
public String getNativePhoneNumber() {
String NativePhoneNumber=null;
NativePhoneNumber=telephonyManager.getLine1Number();
return NativePhoneNumber;
}
/**
* Role:Telecom service providers獲取手機(jī)服務(wù)商信息 <BR>
* 需要加入權(quán)限<uses-permission
* android:name="android.permission.READ_PHONE_STATE"/> <BR>
* Date:2012-3-12 <BR>
*
* @author CODYY)peijiangping
*/
public String getProvidersName() {
String ProvidersName = null;
// 返回唯一的用戶ID;就是這張卡的編號(hào)神馬的
IMSI = telephonyManager.getSubscriberId();
// IMSI號(hào)前面3位460是國(guó)家,緊接著后面2位00 02是中國(guó)移動(dòng),01是中國(guó)聯(lián)通,03是中國(guó)電信。
System.out.println(IMSI);
if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
ProvidersName = "中國(guó)移動(dòng)";
} else if (IMSI.startsWith("46001")) {
ProvidersName = "中國(guó)聯(lián)通";
} else if (IMSI.startsWith("46003")) {
ProvidersName = "中國(guó)電信";
}
return ProvidersName;
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:gravity="center">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="@+id/getSIMInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="獲取手機(jī)號(hào)" />
希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
- Android中自定義的dialog中的EditText無(wú)法彈出輸入法解決方案
- Android 設(shè)置Edittext獲取焦點(diǎn)并彈出軟鍵盤
- Android EditText禁止輸入空格和特殊字符
- Android之EditText控制禁止輸入空格和回車
- Android實(shí)現(xiàn)通訊錄效果——獲取手機(jī)號(hào)碼和姓名
- Android中手機(jī)號(hào)、車牌號(hào)正則表達(dá)式大全
- android獲取當(dāng)前手機(jī)號(hào)示例程序
- Android實(shí)現(xiàn) EditText輸入手機(jī)號(hào)空格功能
相關(guān)文章
Android使用ViewStub實(shí)現(xiàn)布局優(yōu)化方法示例
這篇文章主要為大家介紹了Android使用ViewStub實(shí)現(xiàn)布局優(yōu)化方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08
Android中傳遞對(duì)象的三種方法的實(shí)現(xiàn)
本篇文章主要介紹了Android中傳遞對(duì)象的三種方法的實(shí)現(xiàn),可以通過(guò)Bundle、Intent或者JSON字符串,有興趣的可以了解一下。2017-02-02
Android編程之動(dòng)態(tài)壁紙實(shí)例分析
這篇文章主要介紹了Android編程之動(dòng)態(tài)壁紙實(shí)現(xiàn)方法,以實(shí)例形式分析了Android動(dòng)態(tài)壁紙的原理與實(shí)現(xiàn)步驟,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12
Android仿IOS ViewPager滑動(dòng)進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了Android仿IOS ViewPager滑動(dòng)進(jìn)度條的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
Android連接服務(wù)器端的Socket的實(shí)例代碼
這篇文章主要介紹了Android連接服務(wù)器端的Socket的實(shí)例代碼,需要的朋友可以參考下2017-05-05
實(shí)現(xiàn)Android studio設(shè)置自動(dòng)導(dǎo)包及自動(dòng)導(dǎo)包快捷鍵
這篇文章主要介紹了實(shí)現(xiàn)Android studio設(shè)置自動(dòng)導(dǎo)包及自動(dòng)導(dǎo)包快捷鍵的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android使用MulticastSocket實(shí)現(xiàn)多點(diǎn)廣播圖片
這篇文章主要為大家詳細(xì)介紹了Android使用MulticastSocket實(shí)現(xiàn)多點(diǎn)廣播圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01

