0

当我在我的 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);
    }
});
}
}
4

1 回答 1

5

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

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

所以我想从内容提供商那里获得最后发送的短信。

该内容提供者不是 Android SDK 的一部分。

于 2010-07-23T00:10:43.477 回答