gpt4 book ai didi

android - 如何从 Intent 中获取所有额外值

转载 作者:太空狗 更新时间:2023-10-29 15:30:19 25 4
gpt4 key购买 nike

这是我的代码

     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 循环发送多条短信时,我只得到最后发送的短信的额外信息。如何获得所有额外信息..?

最佳答案

这应该得到所有的值

Bundle bundle = intent.getExtras();

for (String key : bundle.keySet()) {
Object value = bundle.get(key);
Log.d(TAG, String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}

关于android - 如何从 Intent 中获取所有额外值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6894513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com