Android 如何获得短信跟踪的短信正文?
我想将消息放入字符串并拆分消息。但我无法将“body”表示的消息转换为字符串。请告诉我您是否知道如何将消息正文放入字符串中。这是我的示例代码Android 如何获得短信跟踪的短信正文?,android,string,sms,smsmanager,Android,String,Sms,Smsmanager,我想将消息放入字符串并拆分消息。但我无法将“body”表示的消息转换为字符串。请告诉我您是否知道如何将消息正文放入字符串中。这是我的示例代码 protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.fulldetail); lst=(ListView)findViewById(R.id.rldlist1
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.fulldetail);
lst=(ListView)findViewById(R.id.rldlist1);
Uri in = Uri.parse("content://sms/inbox");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(in, new String[]{"_id", "address", "body"}, "address = 'eZ Reload'", null, null);
adapter = new SimpleCursorAdapter(this, R.layout.rowsms, c, new String[]
{"address", "body"}, new int[]{R.id.lblreloadbody, R.id.lblreloadno});
lst.setAdapter(adapter)
您可以使用
String body=sms.getMessageBody().toString()代码>查看此代码:
// Get the SMS map from Intent
Bundle extras = intent.getExtras();
String messages = "";
if ( extras != null )
{
// Get received SMS array
Object[] smsExtra = (Object[]) extras.get( SMS_EXTRA_NAME );
// Get ContentResolver object for pushing encrypted SMS to the incoming folder
ContentResolver contentResolver = context.getContentResolver();
for ( int i = 0; i < smsExtra.length; ++i )
{
SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
String body = sms.getMessageBody().toString();
String address = sms.getOriginatingAddress();
messages += "SMS from " + address + " :\n";
messages += body + "\n";
// Here you can add any your code to work with incoming SMS
// I added encrypting of all received SMS
putSmsToDatabase( contentResolver, sms );
}
// Display SMS message
Toast.makeText( context, messages, Toast.LENGTH_SHORT ).show();
}
//从Intent获取SMS映射
Bundle extras=intent.getExtras();
字符串消息=”;
如果(附加值!=null)
{
//获取接收到的SMS阵列
Object[]smsExtra=(Object[])extras.get(SMS\u EXTRA\u NAME);
//获取ContentResolver对象,用于将加密短信推送到传入文件夹
ContentResolver ContentResolver=context.getContentResolver();
对于(int i=0;i
更多信息请访问: