How to create sms backup in android
<p>I am creating a sample of sms backup and creating csv file. It is working fine in Emulator but its is not working on my handset (samsung galaxy Note). Here is the code please suggest how it can be fixed</p>

<pre><code>while (curLog.moveToNext()) {
            Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
            cursor.moveToFirst();

            do{
               String msgData = "";
               for(int id=0;id&lt;cursor.getColumnCount();id++)
               {


                   writer.append(cursor.getString(cursor.getColumnIndexOrThrow("_id")));
                   writer.append(',');

                   writer.append(cursor.getString(cursor.getColumnIndexOrThrow("address")));
                   writer.append(',');

                   writer.append(cursor.getString(cursor.getColumnIndexOrThrow("body")));
                   writer.append(',');

                   writer.append(cursor.getString(cursor.getColumnIndexOrThrow("read")));
                   writer.append(',');


                 String SmsDate = cursor.getString(cursor.getColumnIndexOrThrow("date"));
                SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
                String dateString = formatter.format(new Date(Long.parseLong(SmsDate)));
                    writer.append(dateString);
                    writer.append(',');

                   String SmsTime = cursor.getString(cursor.getColumnIndexOrThrow("date"));
                    SimpleDateFormat format = new SimpleDateFormat("HH:mm");
                    String timeString = formatter.format(new Date(Long.parseLong(SmsTime)));
                     writer.append(timeString);
                     writer.append(',');


                    if (cursor.getString(cursor.getColumnIndexOrThrow("type")).contains("1")) 
                          writer.append("Inbox");
                     else 
                          writer.append("Sent");                        
                    writer.append('\n');
               }
            }while(cursor.moveToNext());    

        }
          writer.flush();
          writer.close();
</code></pre>
