开发者

Android: A Toast when OutComing call

开发者 https://www.devze.com 2023-02-01 05:08 出处:网络
i\'m trying this开发者_如何学Python code found on internet...it should show a toast for OutComing call event using a BroadcastReceiver but on my htc tattoo with Android 1.6 it doesn\'t works (it don\'

i'm trying this开发者_如何学Python code found on internet...it should show a toast for OutComing call event using a BroadcastReceiver but on my htc tattoo with Android 1.6 it doesn't works (it don't show any toast)

public class HFBroadcastOutComingRecevier extends BroadcastReceiver{
 @Override
 public void onReceive(Context context, Intent intent) {

     Toast.makeText(context, "Phone Event", Toast.LENGTH_SHORT).show();

     Bundle bundle = intent.getExtras();
     if(null == bundle)
           return;
     String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
     String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;
        Toast.makeText(context, info, Toast.LENGTH_LONG).show();
 }
}

Naturally i've registered the BroadcastReceiver on my Manifest as:

  <receiver android:name=".HFBroadcastIncomingRecevier">
   <intent-filter>
    <action android:name="android.intent.action.PHONE_STATE" />
   </intent-filter>
  </receiver>

and with this permissions:

  <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

Any idea?


Change intent filter to ACTION_NEW_OUTGOING_CALL

<receiver android:name=".YourClassName" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

And if this doesnt work also implement an intent filter in your onReceive

public void onReceive(Context context, Intent intent) 
{
    String mAction = intent.getAction();
    if(!mAction.equals("android.provider.Telephony.SMS_RECEIVED"))
        return;
    Toast.makeText(context, "Intent Received", Toast.LENGTH_LONG).show();

}

This is for incoming msg change it accordingly and an example here

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号