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

时间:2010-07-22 19:19:43

标签: android listview sms android-contentprovider

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

content://sms/sent

正确?

所以我想从内容提供商处获取最后发送的短信。所以我使用了这个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);
    }
});
}
}

1 个答案:

答案 0 :(得分:5)

  

您好,当我发送短信时,我的   Android模拟器,它去了   内容提供者:content:// sms / sent   正确?

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

  

所以我想收到最后发送的短信   来自内容提供商。

That content provider is not part of the Android SDK.

相关问题