Can write files to server in the emulator but not the device?
<p>So I've run into a peculiar problem.  I am trying to write a data file to the device.  I developed the app in eclipse under 2.2, my device is 2.3.3, so I made the emulator run at 2.3.3, it writes files fine. Why does this not work on the device?  It also is coded to copy the database file on the device to a php server.  On the server the file is essentially empty, i pulled the db file from the device as well and it's empty.  The only time it works is on the emulator, i get a legit file on the server and when i pull the database it's got data in it.  I'm so lost.  If you want to see some code then ask, I would have posted some but with 40+ classes I really don't know where to begin.
Thanks in advance.</p>

<p>Here is code relating to the database creation</p>

<pre><code>import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DbHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "database";
private static final int DATABASE_VERSION = 1;

// Database creation sql statement
private static final String DATABASE_CREATE = "create table database (_id integer      primary key autoincrement," +
    "name text not null);";

public DbHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Method is called during creation of the database
@Override
public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
}

// Method is called during an upgrade of the database, e.g. if you increase
// the database version
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion,
        int newVersion) {
    Log.w(DbHelper.class.getName(),
            "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all   old data");
    database.execSQL("DROP TABLE IF EXISTS database");
    onCreate(database);
}
 }
</code></pre>

<p>here is the adapter..</p>

<pre><code>import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class DbAdapter {

// Database fields
public static final String KEY_ROWID = "_id";
public static final String KEY_NAME = "name";

static final String DATABASE_TABLE = "database";
private Context context;
private SQLiteDatabase database;
private DbHelper dbHelper;


public DbAdapter(Context ctx) {
    context = ctx;

}

public SQLiteDatabase openToRead() throws SQLException {
    dbHelper = new DbHelper(context);
    database = dbHelper.getReadableDatabase();

    return database;
}

public SQLiteDatabase open() throws SQLException {
    dbHelper = new DbHelper(context);
    database = dbHelper.getWritableDatabase();

    return database;
}

public void close() {
    dbHelper.close();
}

//  
/**
 * Create a new todo If the todo is successfully created return the new
 * rowId for that note, otherwise return a -1 to indicate failure.
 */

public long createRow(String name) {
    ContentValues initialValues = createContentValues(name);

    return database.insert(DATABASE_TABLE, null, initialValues);
}


/**
 * Update the todo
 */

public boolean updateRows(long rowId, 
        String name) {

    ContentValues updateValues = createContentValues(
            name);

    return database.update(DATABASE_TABLE, updateValues, KEY_ROWID + "="
            + rowId, null) &gt; 0;
}


/**
 * Deletes todo
 */

public boolean deleteRow(long rowId) {
    return database.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) &gt; 0;
}


/**
 * Return a Cursor over the list of all todo in the database
 * 
 * @return Cursor over all notes
 */

public Cursor fetchAllRows() {
    return database.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_NAME}, null, null, null,
            null, null);
}


/**
 * Return a Cursor positioned at the defined todo
 */

public Cursor fetchRow(long rowId) throws SQLException {
    Cursor mCursor = database.query(true, DATABASE_TABLE, new String[] {
            KEY_ROWID ,KEY_NAME},
            KEY_ROWID + "=" + rowId, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

/**fetches keyword**/
public Cursor fetchKeyword(String keyword, String column, String[] columns) throws SQLException {


    Cursor mCursor = database.query(DATABASE_TABLE, columns, column + "='" + keyword + "'", 
            null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

private ContentValues createContentValues(String name){

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, name);
    return values;
}

//returns (an) entire column(s), all rows
public Cursor fetchColumns(String[] colnames) {
    Cursor mCursor = database.query(DATABASE_TABLE, colnames, null, 
            null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}
</code></pre>

<p>}</p>

<p>Ok, I've Isolated it to these three classes.. below is the class that creates the entry and uploads it to the server.  as far as i can tell the database isn't being created the right way.. as in there are no tables in the file</p>

<pre><code>public class CreateName extends Activity{

//variables
private DbAdapter mDbHelper;
EditText textField;
TextView txtEnter2;
TextView txtEnter;
Button btnSubmit;
Context context;
SharedPreferences prefs;
SharedPreferences.Editor spe;
SQLiteDatabase db;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.submit);

    //constructors
    context = getApplicationContext();
    prefs = PreferenceManager.getDefaultSharedPreferences(context);
    spe = prefs.edit();


    init();
    listen();
}

public void checker() {
    Intent i = new Intent(this, MoveForward.class);
    startActivity(i);
}

private void listen() {
    btnSubmit.setOnClickListener(new Button.OnClickListener()
    { 
        public void onClick (View v)
        { 
            mDbHelper = new DbAdapter(context);
            String words = textField.getText().toString();
            Log.v(words, words);
            mDbHelper.open();
            mDbHelper.createRow(words);
            mDbHelper.close();
            spe.putString("name", words);
            spe.commit();

            PHPBuddy buddy = new PHPBuddy();
            try {
                buddy.uploadFile("database");
            } catch (Exception e) {
                // ask the user to retry
                e.printStackTrace();
            }
            checker();

        }
    }
    );      
}

private void init() {

    textField = (EditText)findViewById(R.id.edtTxt);
    txtEnter2 = (TextView)findViewById(R.id.txtEnter2);
    txtEnter = (TextView)findViewById(R.id.txtEnter);
    btnSubmit =(Button)findViewById(R.id.btnSubmit);
    txtEnter.setText("Enter your proper name");
    txtEnter2.setText("ex: John Smith");




}
</code></pre>

<p>}</p>

<p>Maybe there is a cursor or db i'm forgetting to close?</p>

<p>Here is more code..</p>

<pre><code>    public class SBMain extends Activity {

Button btnSpinner;
String[] items;
String text;
Spinner s;
Intent i, j;
int activity;
SharedPreferences prefs;
SharedPreferences.Editor spe;
SQLiteDatabase db;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.spinnerscreen);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    spe = prefs.edit();
    init();
    fillSpinner();

    btnSpinner.setOnClickListener(new Button.OnClickListener()
    { 
        public void onClick (View v)
        { 

            Cursor cc = (Cursor)(s.getSelectedItem());
            if (cc != null) {
                text = cc.getString(cc.getColumnIndex("name"));
            }
            checker();
        }
    });

}

public void checker() {

    if (text .equals("Create Name")){
        i = new Intent(this, GetName.class);
        spe.putString("name", text);
        spe.commit();
        startActivity(i);

    }else{
        spe.putString("name", text);
        spe.commit();
        i = new Intent(this, MoveForward.class);
        startActivity(i);

    }

}

private void fillSpinner(){
    DbAdapter mDbHelper = new DbAdapter(this);
    mDbHelper.open();
    Cursor c = mDbHelper.fetchColumns(new String[] {"_id","name"});;

    if ( ! c.moveToFirst() ){
        c.close();

        mDbHelper.createRow("Create Name");
        mDbHelper.close();
        c = mDbHelper.fetchColumns(new String[] {"_id","name"});

    }else{
        mDbHelper.close();
    }


    // create an array to specify which fields we want to display
    String[] from = new String[]{"name"};
    // create an array of the display item we want to bind our data to
    int[] to = new int[]{android.R.id.text1};
    // create simple cursor adapter

    SimpleCursorAdapter adapter =
        new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );


    adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    // get reference to our spinner

    s.setAdapter(adapter);

}

private void init() {

    btnSpinner = (Button)findViewById(R.id.btnSpinner);
    s = (Spinner) findViewById( R.id.spinner1 );


}
</code></pre>

<p>}</p>

<p>Here is the splash activity that downloads the file</p>

<pre><code>public class Splash extends Activity{

String file_url = "http://ipaddress/xampp/uploads/";
Context context = this;
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    Thread splashThread = new Thread() {
        @Override
        public void run() {
            float percent = 0;
            try {
                int waited = 0;
                int time = 1000;
                while (waited &lt; time) {
                    sleep(100);
                    waited += 100;
                    String perc = Integer.toString(waited / time);

                }
            } catch (InterruptedException e) {
                // do nothing
            } finally {



                //if this is the apps first time running, get a list of names.
                if(isFirstRun()){
                    PHPBuddy buddy = new PHPBuddy();
                        try {
                            buddy.downloadFile("database");
                        } catch (IOException e) {
                            // TODO Auto-generated catch block 
                            e.printStackTrace();
                        }

                    //ToDo add spared prefs editor to set isfirstrun to true
                    Intent i = new Intent();
                    i.setClassName("com.project",


                    "com.project.SBMain");
                    startActivity(i);

                }else{
                    //make registered user page
                    Intent i = new Intent();
                    //ToDo add spared prefs editor to set isfrstrun to false
                    //ToDo add intent for true
                }
                finish();
            }
        }
    };
    splashThread.start();
}

public boolean isFirstRun(){

    String rb = "isfirstrun";
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor spe;
    spe = prefs.edit();
    //spe.putBoolean("isfirstrun", true);
    //boolean test = prefs.getBoolean(rb, true);
    return true;//prefs.getBoolean(rb, true);
}
</code></pre>

<p>}</p>

<p>here is the php  </p>

<pre><code>&lt;?php
$myFile = "requestslog.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, "\n\n---------------------------------------------------------------\n");
foreach($_SERVER as $h=&gt;$v)
    if(ereg('HTTP_(.+)',$h,$hp))
        fwrite($fh, "$h = $v\n");
fwrite($fh, "\r\n");
fwrite($fh, file_get_contents('php://input'));
fclose($fh);
echo "&lt;html&gt;&lt;head /&gt;&lt;body&gt;&lt;iframe src=\"$myFile\" style=\"height:100%; width:100%;\"&gt;  &lt;/iframe&gt;&lt;/body&gt;&lt;/html&gt;"
?&gt;
&lt;?php
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
move_uploaded_file ($_FILES['userfile'] ['tmp_name'], $_FILES['userfile'] ['name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
print_r($_FILES);
  }
  ?&gt;
</code></pre>
