Mettre fin à un appel entrant
bonjour,
j'ai un BroadcastReceiver. Jusque là rien de bien compliqué. Je voudrais pouvoir mettre fin à un appel entrant. J'ai lu pas mal de chose mais je n'ai pas réussi à les faire fonctionner. j'utilise android-studio pour le dev. Si quelqu'un peut m'aider
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.widget.Toast;
import android.view.KeyEvent;
public class AutoReceiverIncomingCall extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String extraState =intent.getStringExtra(TelephonyManager.EXTRA_STATE); //Getting Extra State
if (extraState.equals(TelephonyManager.EXTRA_STATE_RINGING)) //Checking Phone State (Ringing or Not)
{
//If the Phone is Ringing getting the Incoming number/
String incomingNumber =intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (incomingNumber.contentEquals("+33"))
{
//---answer the call---
// Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
//buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
//Context().sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
//
Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
i.putExtra(Intent.EXTRA_KEY_EVENT,new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(i, "android.permission.CALL_PRIVILEGED");
// i = new Intent(Intent.ACTION_MEDIA_BUTTON);
// i.putExtra(Intent.EXTRA_KEY_EVENT,new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_HEADSETHOOK));
//context.sendOrderedBroadcast(i, null);
//sendKeys(KeyEvent.KEYCODE_ENDCALL);
//
//setResultData(null);
Toast.makeText(context, "NEW_OUTGOING_CALL intercepted to number 123-123-1234 - aborting call",
Toast.LENGTH_LONG).show();
}
}
return;
} |
le manifest
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ui.myapplication6.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" /><!-- Permission for Reading Phone State -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!-- Registering Receiver with PHONE_STATE -->
<receiver
class="com.ui.myapplication6.AutoReceiverIncomingCall"
android:name="com.ui.myapplication6.AutoReceiverIncomingCall" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<action android:name="android.intent.action.MEDIA_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest> |