android 4.0以上系统如何实现自动接听电话
我用网上的代码如下:[code]
synchronized void autoAnswerCall(){
Context context = TApplication.nowApplication;
try
{
//插耳机
Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent1.putExtra("state", 1);
localIntent1.putExtra("microphone", 1);
localIntent1.putExtra("name", "Headset");
context.sendOrderedBroadcast(localIntent1, "android.permission.CALL_PRIVILEGED");
//按下耳机按钮
Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);
localIntent2.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent1);
context.sendOrderedBroadcast(localIntent2, "android.permission.CALL_PRIVILEGED");
//放开耳机按钮
Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
localIntent3.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent2);
context.sendOrderedBroadcast(localIntent3, "android.permission.CALL_PRIVILEGED");
//拔出耳机
Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent4.putExtra("state", 0);
localIntent4.putExtra("microphone", 1);
localIntent4.putExtra("name", "Headset");
context.sendOrderedBroadcast(localIntent4, "android.permission.CALL_PRIVILEGED");
}catch (Exception e){
e.printStackTrace();
}
}
[/code]
实现了在模拟机和真机的android2.3系统上的自动接听功能,在模拟机上android4.0系统的也可以,但是在真机android4.0上就不行了(三星19300 4.1系统 和 小米 4.0系统 都不行),
求高手指教如何在真机4.0上实现自动接听功能呀??????(用aidl反射是不行的) android 自动接听 --------------------编程问答-------------------- 你可以使用Telephony manager来接听电话,因此你应该在Broadcast receiver添加以下代码:
if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
{
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Class c = null;
c = Class.forName(telephony.getClass().getName());
Method m = null;
m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.answerRingingCall();
}
--------------------编程问答-------------------- @csdn_ask
这个方法不行呀,在4.0上会报权限错误 --------------------编程问答-------------------- 是啊,普通应用程序没权限接电话的,只有挂电话的权限。否则随便一个应用就能搞到你手机通信功能崩溃了。 --------------------编程问答-------------------- 帖子不要沉呀,即使实现不了,有权威说法吗, 技术大牛们????等待回复中 --------------------编程问答-------------------- 无解呀!android 手机就是这么易做图 你换个手机 试试 说不定又好了 debug代码仔细看看吧 !只能这样了 --------------------编程问答-------------------- 这个方法不行呀,在4.0上会报权限错误 --------------------编程问答--------------------
你说的是反射那个方法还是我上面代码的方法????你在什么机子上测试的??? --------------------编程问答-------------------- 帖子不要沉呀,有知道的朋友吗,给个权威的说法????急急急。。。。 --------------------编程问答-------------------- 我也遇到了这种问题 --------------------编程问答-------------------- 同求 在部分手机上是可以的 在htc上又不行 擦 --------------------编程问答--------------------
你在manifest文件中添加下面的权限了吗?
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" /> --------------------编程问答-------------------- 这些权限都已经加上了
--------------------编程问答-------------------- 帖子不要沉呀,求助。。。。。 --------------------编程问答-------------------- 和你寻求同样的问你,帮顶 --------------------编程问答-------------------- 顶!!求解!遇到同样问题,也是4.0好使,4.1就不行!不知道4.1到底在监听多媒体按键时,咋操作的。
没找到源码。。
希望高手指点! --------------------编程问答-------------------- 也在痛苦中, 求解啊!! --------------------编程问答-------------------- 不要考虑了,谷歌开始限制底层危险api了。 --------------------编程问答-------------------- 那要是root以后呢,可以办到吗? --------------------编程问答-------------------- LZ 有实现这个功能呢 在4.1的机子上,你说的那个方法在4.1上有个权限被弄到系统应用权限了。是不是只有内置到rom下了? --------------------编程问答-------------------- 没有呢,一直郁闷中 --------------------编程问答-------------------- 自动接听电话需要android:sharedUserId="android.uid.system"
并且需要当前系统的签名,如果是想做通用的是不可能的。这一块没有权限。 --------------------编程问答-------------------- 我觉得如果想实现的话,那就弄到底层去啦,自己去开发个系统,自己做API
我是小白,别问我,我什么都不知道 --------------------编程问答-------------------- 问题解决了,谢谢大家的帮助关心 --------------------编程问答-------------------- 怎么解决的,分享一下撒 --------------------编程问答-------------------- 做这个功能之前,楼主必须得先报告你这么做的目的是什么。 --------------------编程问答-------------------- 我在琢磨通过广播记录电话时长,4.0版本有限制,郁闷。 --------------------编程问答-------------------- 这个需要较高的权限。好像光在Manifest文件中声明是不够的。
必须获取root权限,或者直接把程序安装到系统目录下即可。 --------------------编程问答-------------------- 各位同胞们,都研究的怎么样啦?我也开始步你们的后尘了,一路的纠结啊,求解。。。。。 --------------------编程问答-------------------- 这类高危操作,从android4.0开始会逐渐不灵的,4.2更严格 --------------------编程问答-------------------- sharedUserId="android.uid.system" + 必须获取root权限 --------------------编程问答-------------------- 同问哪,进来看看 --------------------编程问答--------------------
LZ不厚道啊,问题解决了也不说下咋解决的 --------------------编程问答-------------------- 真是不厚道啊.楼主 --------------------编程问答-------------------- 除 --------------------编程问答--------------------
这是不好意思哦,这段时间一直在忙,忙的晕头转向的,忘记贴出来了
代码如下:
/**--------------------编程问答-------------------- 最近一段时间忙的晕头转向的,忘记吧解决的方法贴出来了,大牛们们给瞧瞧看看,是否可以改进
* 该方法可以用于4.1的接听
*/
public void autoAnswerPhone() {
try {
ITelephony itelephony = getITelephony(mTelephonyManager);
//itelephony.silenceRinger();
itelephony.answerRingingCall();
} catch (Exception e) {
e.printStackTrace();
try {
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
intent = new Intent("android.intent.action.MEDIA_BUTTON");
keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent1.putExtra("state", 1);
localIntent1.putExtra("microphone", 1);
localIntent1.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent1,"android.permission.CALL_PRIVILEGED");
Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent2.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent1);
TApplication.nowApplication.sendOrderedBroadcast(localIntent2,"android.permission.CALL_PRIVILEGED");
Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent3.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent2);
TApplication.nowApplication.sendOrderedBroadcast(localIntent3,"android.permission.CALL_PRIVILEGED");
Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent4.putExtra("state", 0);
localIntent4.putExtra("microphone", 1);
localIntent4.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent4,"android.permission.CALL_PRIVILEGED");
} catch (Exception e2) {
e2.printStackTrace();
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
}
}
}
--------------------编程问答-------------------- 有机会试试,不知道是否还需要系统签名了 --------------------编程问答-------------------- TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
/**
* 该方法可以用于4.1的接听
*/
public void autoAnswerPhone() {
try {
ITelephony itelephony = getITelephony(mTelephonyManager);
//itelephony.silenceRinger();
itelephony.answerRingingCall();
} catch (Exception e) {
e.printStackTrace();
try {
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
intent = new Intent("android.intent.action.MEDIA_BUTTON");
keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent1.putExtra("state", 1);
localIntent1.putExtra("microphone", 1);
localIntent1.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent1,"android.permission.CALL_PRIVILEGED");
Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent2.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent1);
TApplication.nowApplication.sendOrderedBroadcast(localIntent2,"android.permission.CALL_PRIVILEGED");
Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent3.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent2);
TApplication.nowApplication.sendOrderedBroadcast(localIntent3,"android.permission.CALL_PRIVILEGED");
Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent4.putExtra("state", 0);
localIntent4.putExtra("microphone", 1);
localIntent4.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent4,"android.permission.CALL_PRIVILEGED");
} catch (Exception e2) {
e2.printStackTrace();
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
}
}
}
这一句,我怎么出错啊问题在:TApplication.nowApplication --------------------编程问答-------------------- 能不能把你的工程源码发一下啊,我的QQ:286606889 --------------------编程问答--------------------
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
这一句,我怎么出错啊问题在:TApplication.nowApplication
这是一个Context对象,你换成其他的就可以了 --------------------编程问答-------------------- 请问下楼主,你做的挂断电话反射的方法 在小米上也行么 我怎么endCall在小米上不行啊 提示说 call_phone这个权限访问不到 --------------------编程问答--------------------
请问下楼主,你做的挂断电话反射的方法 在小米上也行么 我怎么endCall在小米上不行啊 提示说 call_phone这个权限访问不到
是不是只用这一个方法就接起了所有电话??
最近一段时间忙的晕头转向的,忘记吧解决的方法贴出来了,大牛们们给瞧瞧看看,是否可以改进
/**
* 该方法可以用于4.1的接听
*/
public void autoAnswerPhone() {
try {
ITelephony itelephony = getITelephony(mTelephonyManager);
//itelephony.silenceRinger();
itelephony.answerRingingCall();
} catch (Exception e) {
e.printStackTrace();
try {
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
intent = new Intent("android.intent.action.MEDIA_BUTTON");
keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent1.putExtra("state", 1);
localIntent1.putExtra("microphone", 1);
localIntent1.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent1,"android.permission.CALL_PRIVILEGED");
Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent2.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent1);
TApplication.nowApplication.sendOrderedBroadcast(localIntent2,"android.permission.CALL_PRIVILEGED");
Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent3.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent2);
TApplication.nowApplication.sendOrderedBroadcast(localIntent3,"android.permission.CALL_PRIVILEGED");
Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent4.putExtra("state", 0);
localIntent4.putExtra("microphone", 1);
localIntent4.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent4,"android.permission.CALL_PRIVILEGED");
} catch (Exception e2) {
e2.printStackTrace();
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
}
}
}
最近一段时间忙的晕头转向的,忘记吧解决的方法贴出来了,大牛们们给瞧瞧看看,是否可以改进
/**
* 该方法可以用于4.1的接听
*/
public void autoAnswerPhone() {
try {
ITelephony itelephony = getITelephony(mTelephonyManager);
//itelephony.silenceRinger();
itelephony.answerRingingCall();
} catch (Exception e) {
e.printStackTrace();
try {
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
intent = new Intent("android.intent.action.MEDIA_BUTTON");
keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent1.putExtra("state", 1);
localIntent1.putExtra("microphone", 1);
localIntent1.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent1,"android.permission.CALL_PRIVILEGED");
Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent2.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent1);
TApplication.nowApplication.sendOrderedBroadcast(localIntent2,"android.permission.CALL_PRIVILEGED");
Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent3.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent2);
TApplication.nowApplication.sendOrderedBroadcast(localIntent3,"android.permission.CALL_PRIVILEGED");
Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent4.putExtra("state", 0);
localIntent4.putExtra("microphone", 1);
localIntent4.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent4,"android.permission.CALL_PRIVILEGED");
} catch (Exception e2) {
e2.printStackTrace();
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
}
}
}
我在三星手机上测试,4.1.2系统,还是接不起电话啊。
--------------------编程问答--------------------
最近一段时间忙的晕头转向的,忘记吧解决的方法贴出来了,大牛们们给瞧瞧看看,是否可以改进
/**
* 该方法可以用于4.1的接听
*/
public void autoAnswerPhone() {
try {
ITelephony itelephony = getITelephony(mTelephonyManager);
//itelephony.silenceRinger();
itelephony.answerRingingCall();
} catch (Exception e) {
e.printStackTrace();
try {
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
intent = new Intent("android.intent.action.MEDIA_BUTTON");
keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent1.putExtra("state", 1);
localIntent1.putExtra("microphone", 1);
localIntent1.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent1,"android.permission.CALL_PRIVILEGED");
Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent2.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent1);
TApplication.nowApplication.sendOrderedBroadcast(localIntent2,"android.permission.CALL_PRIVILEGED");
Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent3.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent2);
TApplication.nowApplication.sendOrderedBroadcast(localIntent3,"android.permission.CALL_PRIVILEGED");
Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent4.putExtra("state", 0);
localIntent4.putExtra("microphone", 1);
localIntent4.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent4,"android.permission.CALL_PRIVILEGED");
} catch (Exception e2) {
e2.printStackTrace();
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
}
}
}
我在三星手机上测试,4.1.2系统,还是接不起电话啊。
你那是三星什么手机?是三星原来的4.12系统吗?我在note2 4.12上可以 --------------------编程问答-------------------- 我是三星i9300,刷机成4.12,我又测了一下,好像会被lbe拦截,关掉后就可以了,不过在索尼的4.12上还是不行,有时候还会变成直接挂断电话,那是怎么回事? --------------------编程问答--------------------
我是三星i9300,刷机成4.12,我又测了一下,好像会被lbe拦截,关掉后就可以了,不过在索尼的4.12上还是不行,有时候还会变成直接挂断电话,那是怎么回事?
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
就可以了,前面的不需要。 --------------------编程问答--------------------
挂掉是因为前面拦截异常造成的 有很多手机上都会出现偶尔接听会挂断的情况 所以可以直接使用
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
就可以了,前面的不需要。
前面的不需要是指哪里前面不需要?我这也出现了偶尔会挂断的情况 --------------------编程问答-------------------- LZ您好 我是android 小白 请问ITelephony itelephony = getITelephony(mTelephonyManager) 中的mTelephonyManager 是什么参数?然后这个函数的功能是手机接到来电的时候不需划屏就可以直接接电话么?(就是电话一来不需要什么操作 直接就通话了) --------------------编程问答-------------------- 有没有大神能告诉我 getITelephony 这个函数是干嘛的 --------------------编程问答-------------------- TApplication.nowApplication是什么意思啊 --------------------编程问答--------------------
问题解决了,谢谢大家的帮助关心
LZ不厚道啊,问题解决了也不说下咋解决的
这是不好意思哦,这段时间一直在忙,忙的晕头转向的,忘记贴出来了
代码如下:
/**
* 该方法可以用于4.1的接听
*/
public void autoAnswerPhone() {
try {
ITelephony itelephony = getITelephony(mTelephonyManager);
//itelephony.silenceRinger();
itelephony.answerRingingCall();
} catch (Exception e) {
e.printStackTrace();
try {
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
intent = new Intent("android.intent.action.MEDIA_BUTTON");
keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
intent.putExtra("android.intent.extra.KEY_EVENT",keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(intent,"android.permission.CALL_PRIVILEGED");
Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent1.putExtra("state", 1);
localIntent1.putExtra("microphone", 1);
localIntent1.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent1,"android.permission.CALL_PRIVILEGED");
Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent2.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent1);
TApplication.nowApplication.sendOrderedBroadcast(localIntent2,"android.permission.CALL_PRIVILEGED");
Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_HEADSETHOOK);
localIntent3.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent2);
TApplication.nowApplication.sendOrderedBroadcast(localIntent3,"android.permission.CALL_PRIVILEGED");
Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG);
localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
localIntent4.putExtra("state", 0);
localIntent4.putExtra("microphone", 1);
localIntent4.putExtra("name", "Headset");
TApplication.nowApplication.sendOrderedBroadcast(localIntent4,"android.permission.CALL_PRIVILEGED");
} catch (Exception e2) {
e2.printStackTrace();
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
}
}
}
TApplication.nowApplication是什么啊 --------------------编程问答--------------------
TApplication.nowApplication是什么意思啊
这是一个Context对象,你换成其他的就可以了 --------------------编程问答-------------------- 直接使用这个就可以了,测试在三星s4 android4.2上也可以。
但是有的手机上会自动挂断,求高手解决!!!
/**
* 自动接听电话
*/
private void autoAnswercall(){
Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);
meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT,keyEvent);
TApplication.nowApplication.sendOrderedBroadcast(meidaButtonIntent, null);
}
补充:移动开发 , Android