This may be old but here is the reason why.
Don't throw the exception here:
readSMS() throws IOException
instead wrap in a a try catch block like so:
try{
ContentResolver cr = context.getContentResolver();
Uri uri = Uri.parse("content://sms/inbox");
StringBuilder smsBackup = new StringBuilder();
Cursor messagesCursor = cr.query(uri, new String[] { "_id","address","body","person"}, null,null, null);
smsBackup.append("SMS Back UP (Total Message(s)::"+messagesCursor.getCount()+") \n\n");
String name = null;
if(messagesCursor.getCount() > 0){
while(messagesCursor.moveToNext()){
name = null;
name = getName(messagesCursor.getString(messagesCursor.getColumnIndex("address")));
if(name==null)
name = "Sender : " + messagesCursor.getString(messagesCursor.getColumnIndex("address"));
smsBackup.append("Sender : "+name +"\n"+ "Message : "+messagesCursor.getString(messagesCursor.getColumnIndex("body")) + "\n\n");
}
}
messagesCursor.close();
}catch(IOException e){
//handle here, if not log it
}finally{
//can also close here if you want, need to wrap in another try block and check for null
}
Seems like the problem is the ioexception is being caught before the close()
could be called. The method is then thrown at that point and is never called. I could be wrong, I just took a quick glance at it. I hope this helps.