开发者

Android SMS Intent Problem

I'm trying to open the System SMS application with a sms body that is taken from a database.

I'm using Cursor to retrieve titles and messages from a SQLite database. I have a smsButton which will be clicked. When clicked, it will create the sms intent.

My problem is with the body of the message. I want the body to be the msg_content which is retrieved from the database. I tried to have a reference to it but I believe I failed.

here is my last attempt, trying to have a TextView that will take the id of the msg_content layout :

//First: DataBase Retrieving :
//fetch a msg from table `t` with id `id`
Cursor cursor = myDbHelper.fetchMessage(t, id); 
String[] columns = {cursor.getColumnName(1), cursor.getColumnName(2)}; 
int[开发者_开发问答] columnsLayouts = {R.id.title, R.id.msg_content}; //the columns styles
ca = new SimpleCursorAdapter(this.getBaseContext(), R.layout.msg_items_layout, cursor,columns , columnsLayouts);
lv = (ListView) findViewById(android.R.id.list); 
lv.setAdapter(ca);

//Here is MY PROBLEM :
TextView msgText = (TextView) findViewById(R.id.msg_content); //same Id as the msg_content column above
smsButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String uri= "smsto:";
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
            intent.putExtra("sms_body", msgText.getText());
            intent.putExtra("compose_mode", true);
            startActivity(intent);
        }
    });

Any way to reference the string of the content ?


You are calling findViewById() on an activity... to get data out of database?

You should be using your Cursor to get at your information.

Since you did not bother to provide the actual source code (just a couple of dis-contiguous snippets, AFAICT), it is difficult to give you concrete advice. Taking a random stab at an answer, I would delete smsButton, and instead listen for ListView item clicks (e.g., onListItemClick() if you are implementing a ListActivity), then use the supplied position to move to the right spot in the Cursor and read out the data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜