Watch This Now!

Android getting SMS body from inbox

1 posts
Thanks Meter: 0
By rgreso, Junior Member on 12th March 2014, 10:30 AM
Post Reply Subscribe to Thread Email Thread
I want to get body of SMS when I click on one. I have tried an approach simmilar to contact picker. Here is my code :

public class Decrypt extends Fragment {
Button loadButton;
EditText smsDisplay;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.decrypt, null);
// Button loadButton=(Button)v.findViewById(
loadButton=(Button)v.findViewById( ;
smsDisplay=(EditText)v.findViewById( oad);
loadButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

Intent sendIntent = new Intent(Intent.ACTION_VIEW);


return v;


public void onActivityResult(int requestCode, int resultCode, Intent data) {
// if (resultCode == Activity.RESULT_OK) {
Uri ur = data.getData();
Cursor c = getActivity().getContentResolver().query(ur, null, null, null, null);
if (c.moveToFirst()) {
String s = c.getString(c.getColumnIndex("body"));
Toast.makeText(getActivity(), s, Toast.LENGTH_LONG).show();
}catch(Exception e){
// }

It opens a Inbox like when I open original sms app in anroid, but when I click on one message it doesnt copy body of that sms in my edittext. Please couul you look at my code and find mistake?

Thanks a lot for your time
Last edited by rgreso; 12th March 2014 at 10:38 AM.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes