日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android auto answer,Incoming call auto answer in android 4.0.3

發(fā)布時間:2023/12/4 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android auto answer,Incoming call auto answer in android 4.0.3 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

問題

I am working in Android technology last 1 years. Currently I want develop an application incoming call auto answer in Android 4.0.3 but in this version I am not getting any solution or can't find any api for this (ITelephony.aidl). Please suggest me.

回答1:

Its working code.

First find out that its incoming call using Phone state Broadcast Receiver.

filter.addAction("android.intent.action.PHONE_STATE");

mContext.registerReceiver(myCallReceiver, filter);

and then in onReceive(Context context, Intent intent) call answerPhoneHeadsethook() function.

private void answerPhoneHeadsethook(Context context) {

// Simulate a press of the headset button to pick up the call

Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);

buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(

KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));

context.sendOrderedBroadcast(buttonDown,

"android.permission.CALL_PRIVILEGED");

// froyo and beyond trigger on buttonUp instead of buttonDown

Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);

buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(

KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));

context.sendOrderedBroadcast(buttonUp,

"android.permission.CALL_PRIVILEGED");

}

回答2:

In order to answer or reject a phone call MODIFY_PHONE_STATE permission is needed. Unfortunately since 2.3 and onwards it is only available for system apps. (more info here)

A workaround to answer the call (originally from here):

Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);

KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_HEADSETHOOK);

i.putExtra(Intent.EXTRA_KEY_EVENT, event );

context.sendOrderedBroadcast(i, null);

回答3:

This works from Android 2.2 to 4.0 and now after adding the try catch to the last line it works for 4.1.2 and 4.2 Frankly speaking dont know how it works but it works for me.

Log.d(tag, "InSecond Method Ans Call");

// froyo and beyond trigger on buttonUp instead of buttonDown

Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);

buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(

KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));

sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");

Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);

headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);

headSetUnPluggedintent.putExtra("state", 0);

headSetUnPluggedintent.putExtra("name", "Headset");

try {

sendOrderedBroadcast(headSetUnPluggedintent, null);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

This is working for me in Android 4.1.2 as well as i have tested on 4.2

This still gives an exception which is handled.

來源:https://stackoverflow.com/questions/11648587/incoming-call-auto-answer-in-android-4-0-3

總結(jié)

以上是生活随笔為你收集整理的android auto answer,Incoming call auto answer in android 4.0.3的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。