When I send an SMS on my Android emulator, it goes to the content provider:
content://sms/sent
right?
So I wanted to get the last sent SMS from the content provider. So I used this Uri as you can see above and I used the method query, with the Content Resolver Object. And I got the cursor, and used the movetofirst() method, so I would have the last sent SMS. Check the code below.
package com.sys;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.net.Uri;
import android.database.Cursor;
public class SMS extends Activity {
Button btnVerSms;
EditText txtFinal;
final Uri CONTENT_URI = Uri.parse("content://sms/sent");
/** Called when the activity is first created. */
@Override
public void onCreate(Bundl开发者_StackOverflow社区e savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnVerSms= (Button)findViewById(R.id.btnVerSms);
txtFinal = (EditText)findViewById(R.id.txtFinal);
btnVerSms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Cursor cursor = getContentResolver().query(CONTENT_URI, null, null, null, null);
String body = null;
if(cursor.moveToFirst()){
body = cursor.getString(cursor.getColumnIndexOrThrow("body")).toString();
}
txtFinal.setText(body);
}
});
}
}
Hello, when I send an SMS on my Android emulator, it goes to the content provider: content://sms/sent right?
Not necessarily. You assume that content provider exists on all devices and is used by all SMS client applications. Those are not valid assumptions.
So I wanted to get the last sent SMS from the content provider.
That content provider is not part of the Android SDK.
精彩评论