如何从intent获取所有额外值

时间:2011-08-01 05:31:11

标签: android

这是我的代码

     Log.i("sdfgsdf", time.toGMTString());
        String SENT = "SMS_SENT";
        Intent y=  new Intent(SENT);
        y.putExtra("number", phoneNumber);
        y.putExtra("time", time.toString());

        String DELIVERED = "SMS_DELIVERED";
        int FLAG_UPDATE_CURRENT =(0x08000000) ;
        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
        y, FLAG_UPDATE_CURRENT);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
        new Intent(DELIVERED), FLAG_UPDATE_CURRENT);

        //---when the SMS has been sent---
        r=  new BroadcastReceiver(){
            @Override
             public void onReceive(Context arg0, Intent arg1) {

                switch (getResultCode())
                {

                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS sent"+arg1.getStringExtra("number"), 
                                Toast.LENGTH_SHORT).show();
                        Constant.DB = Compose.this.openOrCreateDatabase("Indigo",MODE_PRIVATE, null);
                        Constant.DB.execSQL("UPDATE Message SET IsMsgSent='true' where DateAndTime='" + arg1.getStringExtra("time") + "' and ContactNumber='"+arg1.getStringExtra("number")+"'");
                        Constant.DB.execSQL("UPDATE Message SET FolderId='5' where DateAndTime='" + arg1.getStringExtra("time") + "' and ContactNumber='"+arg1.getStringExtra("number")+"'");
                        Constant.DB.close();
                      //  unregisterReceiver(r);
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure"+arg1.getStringExtra("number"), 
                                Toast.LENGTH_SHORT).show();
                        Constant.DB = Compose.this.openOrCreateDatabase("Indigo",MODE_PRIVATE, null);
                        Constant.DB.execSQL("UPDATE Message SET IsMsgSent='false' where DateAndTime='" + arg1.getStringExtra("time") + "' and ContactNumber='"+arg1.getStringExtra("number")+"'");
                        Constant.DB.close();
                       // unregisterReceiver(r);
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service"+arg1.getStringExtra("number"), 
                                Toast.LENGTH_SHORT).show();
                        Constant.DB = Compose.this.openOrCreateDatabase("Indigo",MODE_PRIVATE, null);
                        Constant.DB.execSQL("UPDATE Message SET IsMsgSent='false' where DateAndTime='" + arg1.getStringExtra("time") + "' and ContactNumber='"+arg1.getStringExtra("number")+"'");
                        Constant.DB.close();
                       // unregisterReceiver(r);
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU"+arg1.getStringExtra("number"), 
                                Toast.LENGTH_SHORT).show();
                        Constant.DB = Compose.this.openOrCreateDatabase("Indigo",MODE_PRIVATE, null);
                        Constant.DB.execSQL("UPDATE Message SET IsMsgSent='false' where DateAndTime='" + arg1.getStringExtra("time") + "' and ContactNumber='"+arg1.getStringExtra("number")+"'");
                        Constant.DB.close();
                      //  unregisterReceiver(r);
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off"+arg1.getStringExtra("number"), 
                        Toast.LENGTH_SHORT).show();
                        Constant.DB = Compose.this.openOrCreateDatabase("Indigo",MODE_PRIVATE, null);
                        Constant.DB.execSQL("UPDATE Message SET IsMsgSent='false' where DateAndTime='" + arg1.getStringExtra("time") + "' and ContactNumber='"+arg1.getStringExtra("number")+"'");
                        Constant.DB.close();
                      //  unregisterReceiver(r);
                        break;
                }

            }

        };
        registerReceiver(r, new IntentFilter(SENT));

        //---when the SMS has been delivered---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(getBaseContext(), "SMS not delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;                        
                }
            }
        }, new IntentFilter(DELIVERED));        

        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);        

当我使用for循环发送多个短信时,我只获得了最后发送的sms.how的额外内容以获得所有额外内容..?

3 个答案:

答案 0 :(得分:9)

调用意图的地方就像这样做

    Bundle bundle = new Bundle();
bundle.putString("RetailerName", keyword);
bundle.putString("positon", aString);
intent.putExtras(bundle);

接收意图所在地获取此类数据

  Bundle bundle = this.getIntent().getExtras();
  String RetailerName = bundle.getString("retailerName");

答案 1 :(得分:9)

这应该获得所有值

module.exports = function(db, DataTypes) {
  var Wallet = db.define('Wallet', {
    id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      allowNull: false,
      primaryKey: true
    },
    pin: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    money: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: 0
    },
    createdAt: DataTypes.DATE,
    updatedAt: DataTypes.DATE
  }, {
    tableName: 'Wallet',
    classMethods:{
           associate : function( models ) {
                Wallet.belongsTo( models.User,{ foreignKey : 'id_user'});
            }
    }
  });

答案 2 :(得分:1)

在接收器中

Bundle bundle=intent.getExtras();