I want to create such an application in which i want to open a dialer with specified number during call.
我想要创建这样一个应用程序,在这个应用程序中,我希望在调用期间使用指定的数字打开一个拨号器。
I have successfully opened the dialer during a call with refrence of this LINK but not able to dial the number, and another issue is that code is not working above Android 2.2. is there any other way to make this working in all devices.
我已经成功地打开了拨号器,在一个电话中,有了这个链接,但是不能拨号,另一个问题是代码没有在Android 2.2之上运行。还有其他方法可以让它在所有设备中工作吗?
Code :
代码:
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephonyService;
telephonyService = (ITelephony)m.invoke(tm);
// Silence the ringer and answer the call!
telephonyService.silenceRinger();
telephonyService.answerRingingCall();
telephonyService.showCallScreen();
telephonyService.showCallScreenWithDialpad(true);
ERROR LOG:
错误日志:
01-09 17:35:41.065: W/Resources(367): Converting to string: TypedValue{t=0x10/d=0x2 a=-1}
01-09 17:38:23.446: W/System.err(367): java.lang.SecurityException: Neither user 10056 nor current process has android.permission.MODIFY_PHONE_STATE.
01-09 17:38:23.446: W/System.err(367): at android.os.Parcel.readException(Parcel.java:1322)
01-09 17:38:23.446: W/System.err(367): at android.os.Parcel.readException(Parcel.java:1276)
01-09 17:38:23.446: W/System.err(367): at com.android.internal.telephony.ITelephony$Stub$Proxy.silenceRinger(ITelephony.java:549)
01-09 17:38:23.446: W/System.err(367): at com.everysoft.autoanswer.AutoAnswerIntentService.answerPhoneAidl(AutoAnswerIntentService.java:137)
01-09 17:38:23.446: W/System.err(367): at com.everysoft.autoanswer.AutoAnswerIntentService.onHandleIntent(AutoAnswerIntentService.java:94)
01-09 17:38:23.446: W/System.err(367): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
01-09 17:38:23.446: W/System.err(367): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 17:38:23.446: W/System.err(367): at android.os.Looper.loop(Looper.java:123)
01-09 17:38:23.446: W/System.err(367): at android.os.HandlerThread.run(HandlerThread.java:60)
Manifest.xml
Manifest.xml
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
EDIT
编辑
I am able to auto answer the call in all devices but having problem with opening a dialpad only.
我可以自动回复所有设备的呼叫,但只有打开一个拨号板有问题。
5 个解决方案
#1
2
Remove this line and your code should work:
删除这一行,您的代码应该工作:
telephonyService.silenceRinger();
That is an invalid call after Android 2.2.
这是在Android 2.2之后的无效调用。
#2
2
Have you tried like bellow ?
你试过贝娄吗?
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:1231231234"));
startActivity(intent);
#3
1
Add in manifest permission MODIFY_PHONE_STATE
添加manifest权限MODIFY_PHONE_STATE。
#4
1
MODIFY_PHONE_STATE permission used by system apps only not by third party apps.
系统应用程序使用的MODIFY_PHONE_STATE权限,而不是第三方应用程序。
Instead of using answerRingingCall(), u can use key events Like:
您可以使用以下关键事件,而不是使用应答呼叫():
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");
#5
0
I thing you use the hiden library com.android.internal.telephony I add this line in the manifest
我喜欢你使用hiden图书馆com. android.internaltelephony我在清单中添加了这条线。
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
and I worked in my case I tried it in 4.4.2
在我的案例中,我用了4.4.2。
#1
2
Remove this line and your code should work:
删除这一行,您的代码应该工作:
telephonyService.silenceRinger();
That is an invalid call after Android 2.2.
这是在Android 2.2之后的无效调用。
#2
2
Have you tried like bellow ?
你试过贝娄吗?
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:1231231234"));
startActivity(intent);
#3
1
Add in manifest permission MODIFY_PHONE_STATE
添加manifest权限MODIFY_PHONE_STATE。
#4
1
MODIFY_PHONE_STATE permission used by system apps only not by third party apps.
系统应用程序使用的MODIFY_PHONE_STATE权限,而不是第三方应用程序。
Instead of using answerRingingCall(), u can use key events Like:
您可以使用以下关键事件,而不是使用应答呼叫():
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");
#5
0
I thing you use the hiden library com.android.internal.telephony I add this line in the manifest
我喜欢你使用hiden图书馆com. android.internaltelephony我在清单中添加了这条线。
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
and I worked in my case I tried it in 4.4.2
在我的案例中,我用了4.4.2。