如何从内容提供商查询最后发送的短信?

rog*_*gcg 0 sms android listview android-contentprovider

当我在Android模拟器上发送短信时,会转到内容提供商:

content://sms/sent
Run Code Online (Sandbox Code Playgroud)

对?

所以我想从内容提供商处获取最后发送的短信.所以我使用了这个Uri,你可以在上面看到,我使用了方法查询,内容解析器对象.我得到了光标,并使用了movetofirst()方法,所以我会有最后发送的短信.检查下面的代码.

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(Bundle 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);
    }
});
}
}
Run Code Online (Sandbox Code Playgroud)

Com*_*are 5

您好,当我在我的Android模拟器上发送短信时,它会转到内容提供商:content://短信/发送对吗?

不必要.您假设内容提供程序存在于所有设备上,并由所有SMS客户端应用程序使用.这些都不是有效的假设.

所以我想从内容提供商处获取最后发送的短信.

该内容提供商不是Android SDK的一部分.