我有一个小问题。我无法让我的广播接收器显示任何 toast 消息。也许我无法以某种方式触发它,但我的发件人可以工作。我想知道它是否甚至触发。
主班
 public class Main_Activity extends Activity {
Button buttonSend;
EditText textPhoneNo;
EditText textSMS;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
   Button  buttons = (Button) findViewById(R.id.gett);
    buttonSend = (Button) findViewById(R.id.buttonSend);
    textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
    textSMS = (EditText) findViewById(R.id.editTextSMS);
    EditText edt = (EditText)findViewById(R.id.reciving);
    buttons.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
        //  EditText edt = (EditText)findViewById(R.id.reciving);
        //  SmsReceiver obj = new SmsReceiver();
        //  String test = obj.number2;
        //    edt.setText("you stupid result "+test);
        }
    });
    SmsReceiver obj = new SmsReceiver();
//  String test = obj.number2;
 //   edt.setText("you stupid result "+test);
  buttonSend.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        // TODO Auto-generated method stub
        String phoneNo = textPhoneNo.getText().toString();
        String sms = textSMS.getText().toString();
        try{
            SmsManager  smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(phoneNo, null, sms, null, null);
        }catch (Exception e)
        {
            System.out.println("Not send");
        }
    }
})  ;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
 }
短信接收器类:
  public class SmsReceiver extends BroadcastReceiver
 {
@Override
public void onReceive(Context context, Intent intent) 
{
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras();        
    SmsMessage[] msgs = null;
    String str = "";            
    if (bundle != null)
    {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                
            str += "SMS from " + msgs[i].getOriginatingAddress();                     
            str += " :";
            str += msgs[i].getMessageBody().toString();
            str += "\n";        
        }
        //---display the new SMS message---
        Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
    }                         
}
 }
主播
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="dom.example.sms_exp"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Main_Activity"
        android:label="@string/title_activity_main_" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name=".SmsReceiver" >
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
    <activity
        android:name=".SmsReceiver"
        android:label="@string/title_activity_send_activity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>
请帮忙,我明天有一个项目要提交。