广播不在android中工作

时间:2013-06-18 11:43:49

标签: android

我是Android编程新手。我正在尝试使用广播接收器,但没有任何事情发生。没有发现错误:

代码:

public class ReceiveText extends BroadcastReceiver{


@SuppressWarnings("deprecation")
@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Bundle basket=intent.getExtras();
    SmsMessage[] msg=null;
    String str="";
    if(basket!=null){
        //retrieving message received
        Object[] pdus=(Object[])basket.get("pdus");
        msg=new SmsMessage[pdus.length];
        for(int i=0;i<=msg.length;i++){
            msg[i]=SmsMessage.createFromPdu((byte[]) pdus[i]);
            str+="sms from"+msg[i].getOriginatingAddress();
            str+="\n"+msg[i].getMessageBody().toString();
        }
        abortBroadcast();
    Toast.makeText(context, "broad |Cast", Toast.LENGTH_LONG).show();
    Log.d("gustav","Testing ");
}
}
 }

manifest.XML

<receiver android:name=".ReceiveText" android:enabled="true">
        <intent-filter android:priority="999">
            <action android:name="android.provider.telephony.SMS_RECEIVED"/>
        </intent-filter>
    </receiver>

0 个答案:

没有答案