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跟踪。