How to read the message content of a new in coming message in android?

前端 未结 5 1202
深忆病人
深忆病人 2020-12-04 20:42

I want to read the message body of a new incoming SMS in android, programmatically.

I tried something but that doesn\'t return any contents:

5条回答
  •  庸人自扰
    2020-12-04 21:06

    Here in this example i'll demonstrate you that how to read the recent received(incoming) sms from inbox and to show it in textview.

     fstmsgBtn.setOnClickListener(new OnClickListener()
    
        { public void onClick(View v) 
        {
            Uri my_uri = Uri.parse("content://sms/inbox");          
            Cursor readFstSms =v.getContext().getContentResolver().query(my_uri, null, null ,null,null); 
            if(readFstSms.moveToFirst()) 
            {
               String  msg_body =  c.getString(c.getColumnIndexOrThrow("body")).toString();
               //String sender_number = c.getString(c.getColumnIndexOrThrow("address")).toString();
               readtxt.setText(msg_body);
            }
            readFstSms.close();
        }
        });
    

提交回复
热议问题