① 安卓手機如何設置電源鍵掛斷電話
若使用vivo手機,可以進入設置--(應用與許可權)--(系統應用設置)--電話--開啟「按電源鍵掛斷來電」,不支持通話中掛斷電話。
溫馨提示:開啟後,來電時第一次按電源鍵,可將來電置為靜音,第二次按電源鍵,可將來電掛斷,沒有此開關則代表不支持此功能。
② 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。
③ android中 我現在手機正在通話中 突然有電話打入 我想把前面通話中的電話掛斷 接後面打入電話怎麼實現啊
很簡單啊,在屏幕最上方向下劃,出現正在通話的選項,選擇,然後掛掉,接現在的通話,就可以了
④ android如何掛斷電話
用反射aidl調用系統@hide的方法,網上有相關代碼
⑤ Android中提供了3種電話狀態,但是好像沒有給出電話的接通狀態的判斷,怎麼判斷撥打和接聽電話是否接通
android源碼裡面是有以下狀態的:
IDLE,//待機,沒有連接
ACTIVE,//通話
HOLDING,//掛斷通話
DIALING,//響鈴
ALERTING,//提醒
INCOMING,//來電
WAITING,//等待接通
DISCONNECTED,//連接斷開後
DISCONNECTING;//連接斷開工程中
你要去看源碼裡面的
⑥ 安卓智能機為什麼撥打電話就自己掛斷了
安卓智能機撥打電話出現自己掛斷現象的原因有以下幾種可能:
1、手機信號不佳。通信雙方中的一方位置處於信號盲區時就會產生因無信號導致手機自動掛斷的情況,針對這類情況,需要到信息較強的地方去打接電話;
⑦ ITelephony.aidl 在android studio中的使用
aidl文件的包名必須和aidl目錄下java的包名一致。
先看下你的ITelephony.aidl文件的包名是不是com.android.internal.telephony;
aidl文件放在aidl目錄下, 和java目錄同級
最後要手動的build ---- make這個mole 成功後, 才會生成Java文件,生成的文件位於build/generated/source/aidl那邊, 你的工程目錄里是看不到的, 不過可以使用了。