Reputation: 1
This is the code i am using to read the inbox message when view button is pressed in context menu but i am unable to read messages i get only the body of the first message.
public class Smsread extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView view = new TextView(this);
Uri uri = Uri.parse("content://sms/inbox");
Cursor c= getContentResolver().query(uri, null, null ,null,null);
startManagingCursor(c);
String sms = "";
if(c.moveToFirst()){
for(int i=0;i<c.getCount();i++){
sms= c.getString(c.getColumnIndexOrThrow("body")).toString();
// sms=c.getString(c.getColumnIndexOrThrow("address")).toString();
}
c.close();
c.moveToNext();
/*
sms ="From :" + c.getString(2) + " : " + c.getString(11)+"\n";
*/
}
view.setText(sms);
setContentView(view);
}
}
Upvotes: 0
Views: 3794
Reputation: 806
Try this:
String[] sms=new String[c.getCount()];
if(c.moveToFirst()){
do{
sms= c.getString(c.getColumnIndexOrThrow("body")).toString();
} while(c.moveToNext());
}
Upvotes: 0
Reputation: 43
You must change
sms= c.getString(c.getColumnIndexOrThrow("body")).toString();
to
sms+= c.getString(c.getColumnIndexOrThrow("body")).toString();
Upvotes: 0
Reputation: 19250
Try this:
if(c.moveToFirst()){
for(int i=0;i<c.getCount();i++){
sms= c.getString(c.getColumnIndexOrThrow("body")).toString();
c.moveToNext();
}
}
You will have to move to next record for each iteration of for loop.then only,you will get all messages there.Here,in for loop,after you get String sms,you can use that sms to show up somewhere.Each time,it will grab next sms into it!
Hope you got the point!
Upvotes: 2