2

I am working on android application (as a final year project in my university) which backup and restores contacts, messages, calendar, call logs etc. I started working on it yesterday and until now I am able to get the message conversations through ContentResolver like this:

private void MsgBackup(){
    try {
        Uri uri = Uri.parse("content://sms");
        //Uri uri = Uri.parse("content://mms-sms/conversations/");
        ContentResolver contentResolver = getContentResolver();

        final String[] projection = new String[]{"*"};

        Cursor SMSL = contentResolver.query(uri, projection, null, null, null);
        int msgscount = SMSL.getCount();
        msgs = new String[SMSL.getCount()][2];
        int i = 0;
        while (SMSL.moveToNext()) {
            address = SMSL.getString(SMSL.getColumnIndex("address"));
            body = SMSL.getString(SMSL.getColumnIndex("body"));

            msgs[i][0] = address;
            msgs[i][1] = body;

            i++;
        }
        SMSL.close();
//will do something here to backups msgs array


    }catch (Exception e){
        e.printStackTrace();
        Toast.makeText(getApplicationContext(),"Error Fetching messages, check permissions!",Toast.LENGTH_LONG).show();
    }
}

What I am worried about is "Restoring them". I read somewhere that it is not possible to restore messages without root access. If so, then how come the applications in the market do this job without root access?

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Imran Aslam
  • 208
  • 2
  • 15
  • 3
    Since KitKat (4.4), only the app that is selected as the user's default messaging app has write access to the message Provider. The current recommendation for backup/restore apps is to configure them to allow the user to temporarily set your app as the default for a restore, then switch back to the previous default. [This blog page](http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html?m=1) has the details and recommended workflow. [This post](http://stackoverflow.com/a/30133663) might also be of some help, as it lists the minimums required to be a default. – Mike M. Nov 14 '16 at 05:20
  • @MikeM. Thanks for your reply and help. I am working according to your recommendation and I will post the result here as soon as I am finished. – Imran Aslam Nov 14 '16 at 07:16
  • @MikeM. Thank you. I have completed work in messages backup and restore. But I have little problem that I need help with. I posted this question here but no one answered. Have a look at:http://stackoverflow.com/questions/41305513/restoring-backed-up-messages-conversations-times-are-incorrect – Imran Aslam Jan 04 '17 at 12:48

0 Answers0