0

SMSを受信した後に別のアクティビティにパラメーターを送信する方法を試してみましたが、エラーが表示されました

タイプ IntentのメソッドputExtra(String, boolean)は、引数 (Bundle) に適用できません

以下は私のコードです:

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 += msgs[i].getMessageBody().toString();
        }

        Intent l = new Intent(context,AgAppMenu.class);
        Bundle bundle2 = new Bundle();
        bundle.putString("msg", str);
        l.putExtra(bundle);

        l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(l);
        Toast.makeText(context, "SucessFull Login", Toast.LENGTH_SHORT).show();
4

4 に答える 4

0

文字列を直接インテントに入れることができます:

l.putExtra("msg", str);

次に、次を使用して取得します。

getIntent().getStringExtra("msg");

しかし、バンドルを使用したい場合は、ここで bundle2 を参照する必要があると思います:

Intent l = new Intent(context,AgAppMenu.class);
        Bundle bundle2 = new Bundle();
        bundle2.putString("msg", str);

    l.putExtras(bundle2);
于 2012-09-11T08:28:53.243 に答える
0

を使用してバンドルを設定する必要がありますIntent.putExtras(Bundle)

于 2012-09-11T08:30:38.237 に答える
0

バンドルを渡したい場合は使用putExtras (Bundle extras)しませんputExtra

于 2012-09-11T08:31:12.533 に答える