2010-07-22 63 views
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); 
    } 
}); 
} 
} 

回答

5

您好,当我在我的 Android模拟器发送短信,它进入 内容提供商:内容://短信/发送 吧?

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

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

That content provider is not part of the Android SDK.

+0

那么什么样的内容,存在于所有的设备和所使用的是建议我用所有SMS客户端应用程序,因为这一次我提到是不是框架的一部分提供。我应该将哪个URI传递给query()方法? – rogcg 2010-07-23 01:25:11

+0

@psyhclo:没有“内容提供者存在于所有设备中,并且被所有的SMS客户端应用程序使用”,而不是为桌面编写的每个电子邮件应用程序都使用Outlook API。每个电子邮件应用程序(如果它具有一个API)都有其自己的API。同样,每个SMS客户端应用程序(如果它具有一个API)都有其自己的API。 – CommonsWare 2010-07-23 01:53:42

+0

那么,我打算做什么?如果我按照这样的方式放弃,我的应用程序将面临严重问题。对?我该怎么办? – rogcg 2010-07-23 01:57:04