2

Is it possible to receive a call and turn on the speaker programmatically in android? Went through many question on stack overflow and google but was not satisfied. Even in AutoAnswer the speaker mode is not working in Jelly Bean. Any help guys?

This is what I get in logcat:

FATAL EXCEPTION: main
java.lang.SecurityException: Neither user 10212 nor current process has android.permission.MODIFY_PHONE_STATE.
    at android.os.Parcel.readException(Parcel.java:1425)
    at android.os.Parcel.readException(Parcel.java:1379)
    at com.android.internal.telephony.ITelephony$Stub$Proxy.answerRingingCall(ITelephony.java:798)
    at com.example.thu.Callclass$Calllistener.onSensorChanged(Callclass.java:144)
    at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:250)
Sparkplug
  • 485
  • 7
  • 21

1 Answers1

1

You need to add this permission to your manifest file:

    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • I have added MODIFY_PHONE_STATE permission. I think this is a system level permission that is not accessible to apps. But there are apps on the playstore that can modify Phone State!! – Sparkplug Oct 26 '13 at 18:46
  • yes. I have added this. But it is no longer accessible by apps. This is a system level permission now. What i want to now is whether there is an alternative to this? Because there are some apps in the play stor that does these tasks. – Vyshakh Oct 26 '13 at 18:51
  • 1
    @vish Yes, but it only actually _works_ on Froyo and older devices. [Since Gingerbread it no longer works except for system apps](http://stackoverflow.com/q/4715250/1068283). – Michael Hampton Oct 26 '13 at 21:30