android電話代碼
『壹』 手機卡如何查看電話號碼-手機卡如何查看手機號碼
手機卡查看手機號碼的方法如下:
通過手機設置查看:
- 打開手機主屏幕,找到並點擊「設置」圖標。
- 在設置界面中,向下滑動並找到「關於手機」或類似的選項,點擊進入。
- 在關於手機界面中,找到「狀態」或「SIM卡狀態」的選項,點擊進入。
- 在SIM卡狀態界面中,即可找到自己的手機號碼。
通過撥號鍵盤查看(僅部分Android手機適用):
- 打開手機主屏幕,找到並點擊「電話」或「撥號」圖標。
- 在撥號鍵盤中,輸入代碼*#62#。
- 點擊撥號按鈕,等待手機反饋,手機將會顯示手機號碼。
通過簡訊查看(僅蘋果手機適用):
- 打開手機主屏幕,找到並點擊「信息」圖標。
- 在信息界面中,新建一條簡訊,收件人號碼輸入123。
- 在簡訊正文中隨意輸入一些內容,然後點擊發送。
- 手機會發送一條簡訊給123,並在一段時間後收到一條返回信息,其中包含手機號碼。
聯系運營商客服查看:
- 如果以上方法均無法查看手機號碼,可以聯系運營商客服。
- 不同運營商的客服聯系方式可能不同,可以撥打相應的客服熱線(如10086等)進行查詢。
- 提供必要的個人信息,客服人員可以幫助查找手機號碼。
請注意,以上方法適用於大多數情況,但不同品牌和型號的手機可能會有所差別。如果無法通過以上方法查看手機號碼,建議直接聯系運營商客服獲取幫助。
『貳』 android怎麼實現自動接聽和掛斷電話功能
android 實現來電自動接聽和自動掛斷的方法:
第一步:准備應用環境需要的系統包和aidl文件。
(1)在應用中創建包:android.telephony
將android系統框架下的\framework\telephony\java\android\telephony目錄中的NeighboringCellInfo.aidl文件復制到上面創建的包(android.telephony )中;
(2)在應用中創建包:com.android.internal.telephony
將android系統框架下的\framework\telephony\java\com\android\internal\telephony目錄中的ITelephony.aidl文件復制到上面創建的包(com.android.internal.telephony )中。
第二步:創建一個獲取ITelephony的方法
PhoneUtils.java
package com.zhouzijing.android.demo;
import java.lang.reflect.Method;
import com.android.internal.telephony.ITelephony;
import android.telephony.TelephonyManager;
public class PhoneUtils {
/**
* 根據傳入的TelephonyManager來取得系統的ITelephony實例.
* @param telephony
* @return 系統的ITelephony實例
* @throws Exception
*/
public static ITelephony getITelephony(TelephonyManager telephony) throws Exception {
Method getITelephonyMethod = telephony.getClass().getDeclaredMethod("getITelephony");
getITelephonyMethod.setAccessible(true);//私有化函數也能使用
return (ITelephony)getITelephonyMethod.invoke(telephony);
}
}
第三步:創建電話廣播攔截器
MyPhoneBroadcastReceiver.java
package com.zhouzijing.android.demo;
import com.android.internal.telephony.ITelephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
public class MyPhoneBroadcastReceiver extends BroadcastReceiver {
private final static String TAG = MyPhone.TAG;
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i(TAG, "[Broadcast]"+action);
//呼入電話
if(action.equals(MyPhone.B_PHONE_STATE)){
Log.i(TAG, "[Broadcast]PHONE_STATE");
doReceivePhone(context,intent);
}
}
/**
* 處理電話廣播.
* @param context
* @param intent
*/
public void doReceivePhone(Context context, Intent intent) {
String phoneNumber = intent.getStringExtra(
TelephonyManager.EXTRA_INCOMING_NUMBER);
TelephonyManager telephony = (TelephonyManager)context.getSystemService(
Context.TELEPHONY_SERVICE);
int state = telephony.getCallState();
switch(state){
case TelephonyManager.CALL_STATE_RINGING:
Log.i(TAG, "[Broadcast]等待接電話="+phoneNumber);
try {
ITelephony iTelephony = PhoneUtils.getITelephony(telephony);
iTelephony.answerRingingCall();//自動接通電話
//iTelephony.endCall();//自動掛斷電話
} catch (Exception e) {
Log.e(TAG, "[Broadcast]Exception="+e.getMessage(), e);
}
break;
case TelephonyManager.CALL_STATE_IDLE:
Log.i(TAG, "[Broadcast]電話掛斷="+phoneNumber);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.i(TAG, "[Broadcast]通話中="+phoneNumber);
break;
}
}
}
第四部:注冊電話廣播攔截器
MyPhone.java
package com.zhouzijing.android.demo;
import android.app.Activity;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
public class MyPhone extends Activity {
public final static String TAG = "MyPhone";
public final static String B_PHONE_STATE = TelephonyManager.ACTION_PHONE_STATE_CHANGED;
private MyPhoneBroadcastReceiver mBroadcastReceiver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_phone);
}
//按鈕1-注冊廣播
public void registerThis(View v) {
Log.i(TAG, "registerThis");
mBroadcastReceiver = new MyPhoneBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(B_PHONE_STATE);
intentFilter.setPriority(Integer.MAX_VALUE);
registerReceiver(mBroadcastReceiver, intentFilter);
}
//按鈕2-撤銷廣播
public void unregisterThis(View v) {
Log.i(TAG, "unregisterThis");
unregisterReceiver(mBroadcastReceiver);
}
}
第5步:在AndroidManifest.xml配置許可權
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
其中:
iTelephony.answerRingingCall();//自動接通電話
必須有許可權 android.permission.MODIFY_PHONE_STATE
iTelephony.endCall();//自動掛斷電話
必須有許可權 android.permission.CALL_PHONE。
『叄』 100分 Android怎麼調用打電話而不顯示系統的通話界面
1、 用反射調用 「com.android.internal.telephony.PhoneFactory」,「com.android.internal.telephony.CallManager」,「com.android.internal.telephony.Phone」中的方法。
代碼如下:
public void Call(String number, Context context) {
try {
final Class<?> phoneFactoryClass = Class.forName("com.android.internal.telephony.PhoneFactory");
Method makeDefaultPhonesMethod = phoneFactoryClass.getDeclaredMethod("makeDefaultPhones", Context.class);
makeDefaultPhonesMethod.invoke(null, context);
Method getDefaultPhone = phoneFactoryClass.getDeclaredMethod("getDefaultPhone");
Object phone = getDefaultPhone.invoke(getDefaultPhone);
final Class<?> callManagerClass = Class.forName("com.android.internal.telephony.CallManager");
Method getInstanceMethod = callManagerClass.getDeclaredMethod("getInstance");
Object callManager = getInstanceMethod.invoke(getInstanceMethod);
final Class<?> phoneClass = Class.forName("com.android.internal.telephony.Phone");
Method registerPhoneMethod = callManagerClass.getDeclaredMethod("registerPhone", phoneClass);
registerPhoneMethod.invoke(callManager, phone);
Method maybeGetMethod = callManagerClass.getDeclaredMethod("getDefaultPhone");
Object phone1 = maybeGetMethod.invoke(callManager);
Method dial = phoneClass.getDeclaredMethod("dial", String.class);
dial.invoke(phone1, number);
} catch (ClassNotFoundException e) {
String string = e.getCause().toString();
Log.e("CallTest" ,string);
} catch (Exception e) {
String string = e.getCause().toString();
Log.e("CallTest" ,string);
}
}
2、在manifest中加如下許可權
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.callphone"
android:sharedUserId="android.uid.system"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name= "andoird.permission.CALL_PHONE"/>
<uses-permission android:name= "andoird.permission.CALL_PRIVILEGED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL"/>
3、將生成的apk用系統簽名,不同的OS有不同的簽名,例如我用的是
java -jar signapk.jar platform.x509.pem platform.pk8 Callphone_unsigned.apk Callphone_signed.apk。其中platform.x509.pem platform.pk8在不同的OS中不同。
備註:用sharedUserId和系統簽名後,程序才有許可權運行。同理,程序不能調試,只能log跟蹤。