I am writing an andrid program to save sms from certain number to a
sdcard, however for some reason the sdcard is not writable. I have the
write permissions set up and the program recieves the sms and knows
when it is from the right number. However the program always fails to
write to the sdcard. I HAVE ALL the write permissions set up on the
sdcard, however DDMS says the sdcard is not writable d--rwxr-x? Does
anyone have any idea how to fix this problem???? As a note in the
beginning when I just tried to create an activity to write a text file
to sdcard it worked.

    package com.fsckcar.sms;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;

public class smsweb extends BroadcastReceiver {
    private static final String TAG = null;
        private static final byte[][] pdus = null;

        /** Called when the activity is first created. */
    @SuppressWarnings("null")
        @Override
    public void onReceive(Context context, Intent intent)
    {
        //---get the SMS message passed in---
        Bundle bundle = intent.getExtras();
        android.telephony.SmsMessage[] msgs = null;
        String str = "";
        String textnumber = "";
        String gvnumber = "";
        String smstime ="";


        if (bundle != null)
        {
                for (int i=0; i<msgs.length; i++){

                        msgs[i] =
android.telephony.SmsMessage.createFromPdu((byte[])pdus[i]);
            str += "SMS from " + msgs[i].getOriginatingAddress();
            textnumber = msgs[i].getOriginatingAddress();
            long stime = msgs[i].getTimestampMillis();
            smstime = Long.toString(stime);
            gvnumber = "+12345678";
            str += " :";

            str += msgs[i].getMessageBody().toString();
            str += "\n";

        }
                if (gvnumber.equals(textnumber))

        {
                        long time = System.currentTimeMillis();
                        String systemtime = Long.toString(time);
                        Toast.makeText(context, "this was a success "+ 
systemtime +
":"+ smstime, Toast.LENGTH_SHORT).show();

                        try {
            File root = Environment.getExternalStorageDirectory();
            if (root.canWrite()){

                File dir = new File (root.getAbsolutePath() + "/
smsweb");
                dir.mkdirs();
                File gpxfile = new File(dir, "website.html");
                FileWriter gpxwriter = new FileWriter(gpxfile);
                BufferedWriter out = new BufferedWriter(gpxwriter);

                out.append("hello");
                out.flush();
                out.close();
            }
        } catch (IOException e) {
            Log.e(TAG, "Could not write file " + e.getMessage());
        }}}

    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to