YGPS/src/com/mediatek/ygps/YgpsActivity.java
private void saveNMEALog() {
        if (NMEALOG_SD) {
            if (Environment.getExternalStorageState().equals(
                    Environment.MEDIA_MOUNTED)) {
                String strTime = DATE_FORMAT.format(new Date(System
                        .currentTimeMillis()));
                File file = new File(Environment.getExternalStorageDirectory(),
                        NMEA_LOG_PREX + strTime + NMEA_LOG_SUFX);
                FileOutputStream fileOutputStream = null;
                boolean flag = true;
                try {
                    if (!file.createNewFile()) {
                        Toast.makeText(this, R.string.toast_create_file_failed,
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                    fileOutputStream = new FileOutputStream(file);
                    String nmea = ((TextView) findViewById(R.id.tv_nmea_log))
                            .getText().toString();
                    if (0 == nmea.getBytes().length) {
                        Toast.makeText(this, R.string.toast_no_log,
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                    fileOutputStream.write(nmea.getBytes(), 0,
                            nmea.getBytes().length);
                    fileOutputStream.flush();
                    fileOutputStream.close();
                } catch (NotFoundException e) {
                    Log.v("@M_" + TAG, "Save nmealog NotFoundException: "
                            + e.getMessage());
                    flag = false;
                } catch (IOException e) {
                    Log.v("@M_" + TAG, "Save nmealog IOException: " + e.getMessage());
                    flag = false;
                } finally {
                    if (null != fileOutputStream) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e) {
                            Log.v("@M_" + TAG, "Save nmealog exception in finally: "
                                    + e.getMessage());
                            flag = false;
                        }
                    }
                }
                if (flag) {
                    Log.v("@M_" + TAG, "Save Nmealog to file Finished");
                    Toast.makeText(
                                    this,
                                    String
                                            .format(
                                                    getString(R.string.toast_save_log_succeed_to),
                                                    Environment
                                                            .getExternalStorageDirectory()
                                                            .getAbsolutePath()),
                                    Toast.LENGTH_LONG).show();
                } else {
                    Log.w("@M_" + TAG, "Save Nmealog Failed");
                    Toast.makeText(this, R.string.toast_save_log_failed,
                            Toast.LENGTH_LONG).show();
                }
            } else {
                Log.v("@M_" + TAG, "saveNMEALog function: No SD card");
                Toast.makeText(this, (R.string.no_sdcard), Toast.LENGTH_LONG)
                        .show();
            }
        } else {
            String strTime = DATE_FORMAT.format(new Date(System
                    .currentTimeMillis()));
            File nmeaPath = new File(NMEALOG_PATH);
            if (!nmeaPath.exists()) {
                nmeaPath.mkdirs();
            }
            File file = new File(nmeaPath, NMEA_LOG_PREX + strTime
                    + NMEA_LOG_SUFX);
            if (file != null) {
                FileOutputStream outs = null;
                boolean flag = true;
                try {
                    file.createNewFile();
                    outs = new FileOutputStream(file);
                    String nmea = ((TextView) findViewById(R.id.tv_nmea_log))
                            .getText().toString();
                    if (0 == nmea.getBytes().length) {
                        Toast.makeText(this, R.string.toast_no_log,
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                    outs.write(nmea.getBytes(), 0, nmea.getBytes().length);
                    outs.flush();
                } catch (IOException e) {
                    Log.v("@M_" + TAG, "Save nmealog IOException: " + e.getMessage());
                    flag = false;
                } finally {
                    if (null != outs) {
                        try {
                            outs.close();
                        } catch (IOException e) {
                            Log.v("@M_" + TAG, "Save nmealog exception in finally: "
                                    + e.getMessage());
                            flag = false;
                        }
                    }
                }
                if (flag) {
                    Log.v("@M_" + TAG, "Save Nmealog to file Finished");
                    Toast
                            .makeText(
                                    this,
                                    String
                                            .format(
                                                    getString(R.string.toast_save_log_succeed_to),
                                                    NMEALOG_PATH),
                                    Toast.LENGTH_LONG).show();
                } else {
                    Log.w("@M_" + TAG, "Save NmeaLog failed!");
                    Toast.makeText(this, R.string.toast_save_log_failed,
                            Toast.LENGTH_LONG).show();
                }
            }
        }

    }
/**
     * Save NMEA log to file.
     */
Save NMEA log to file.
Save NMEA log to file .
private void saveNMEALog() {
        if (NMEALOG_SD) {
            if (Environment.getExternalStorageState().equals(
                    Environment.MEDIA_MOUNTED)) {
                String strTime = DATE_FORMAT.format(new Date(System
                        .currentTimeMillis()));
                File file = new File(Environment.getExternalStorageDirectory(),
                        NMEA_LOG_PREX + strTime + NMEA_LOG_SUFX);
                FileOutputStream fileOutputStream = null;
                boolean flag = true;
                try {
                    if (!file.createNewFile()) {
                        Toast.makeText(this, R.string.toast_create_file_failed,
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                    fileOutputStream = new FileOutputStream(file);
                    String nmea = ((TextView) findViewById(R.id.tv_nmea_log))
                            .getText().toString();
                    if (0 == nmea.getBytes().length) {
                        Toast.makeText(this, R.string.toast_no_log,
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                    fileOutputStream.write(nmea.getBytes(), 0,
                            nmea.getBytes().length);
                    fileOutputStream.flush();
                    fileOutputStream.close();
                } catch (NotFoundException e) {
                    Log.v("@M_" + TAG, "Save nmealog NotFoundException: "
                            + e.getMessage());
                    flag = false;
                } catch (IOException e) {
                    Log.v("@M_" + TAG, "Save nmealog IOException: " + e.getMessage());
                    flag = false;
                } finally {
                    if (null != fileOutputStream) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e) {
                            Log.v("@M_" + TAG, "Save nmealog exception in finally: "
                                    + e.getMessage());
                            flag = false;
                        }
                    }
                }
                if (flag) {
                    Log.v("@M_" + TAG, "Save Nmealog to file Finished");
                    Toast.makeText(
                                    this,
                                    String
                                            .format(
                                                    getString(R.string.toast_save_log_succeed_to),
                                                    Environment
                                                            .getExternalStorageDirectory()
                                                            .getAbsolutePath()),
                                    Toast.LENGTH_LONG).show();
                } else {
                    Log.w("@M_" + TAG, "Save Nmealog Failed");
                    Toast.makeText(this, R.string.toast_save_log_failed,
                            Toast.LENGTH_LONG).show();
                }
            } else {
                Log.v("@M_" + TAG, "saveNMEALog function: No SD card");
                Toast.makeText(this, (R.string.no_sdcard), Toast.LENGTH_LONG)
                        .show();
            }
        } else {
            String strTime = DATE_FORMAT.format(new Date(System
                    .currentTimeMillis()));
            File nmeaPath = new File(NMEALOG_PATH);
            if (!nmeaPath.exists()) {
                nmeaPath.mkdirs();
            }
            File file = new File(nmeaPath, NMEA_LOG_PREX + strTime
                    + NMEA_LOG_SUFX);
            if (file != null) {
                FileOutputStream outs = null;
                boolean flag = true;
                try {
                    file.createNewFile();
                    outs = new FileOutputStream(file);
                    String nmea = ((TextView) findViewById(R.id.tv_nmea_log))
                            .getText().toString();
                    if (0 == nmea.getBytes().length) {
                        Toast.makeText(this, R.string.toast_no_log,
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                    outs.write(nmea.getBytes(), 0, nmea.getBytes().length);
                    outs.flush();
                } catch (IOException e) {
                    Log.v("@M_" + TAG, "Save nmealog IOException: " + e.getMessage());
                    flag = false;
                } finally {
                    if (null != outs) {
                        try {
                            outs.close();
                        } catch (IOException e) {
                            Log.v("@M_" + TAG, "Save nmealog exception in finally: "
                                    + e.getMessage());
                            flag = false;
                        }
                    }
                }
                if (flag) {
                    Log.v("@M_" + TAG, "Save Nmealog to file Finished");
                    Toast
                            .makeText(
                                    this,
                                    String
                                            .format(
                                                    getString(R.string.toast_save_log_succeed_to),
                                                    NMEALOG_PATH),
                                    Toast.LENGTH_LONG).show();
                } else {
                    Log.w("@M_" + TAG, "Save NmeaLog failed!");
                    Toast.makeText(this, R.string.toast_save_log_failed,
                            Toast.LENGTH_LONG).show();
                }
            }
        }
    }
private void saveNMEALog ( ) { if ( NMEALOG_SD ) { if ( Environment . getExternalStorageState ( ) . equals ( Environment . MEDIA_MOUNTED ) ) { String strTime = DATE_FORMAT . format ( new Date ( System . currentTimeMillis ( ) ) ) ; File file = new File ( Environment . getExternalStorageDirectory ( ) , NMEA_LOG_PREX + strTime + NMEA_LOG_SUFX ) ; FileOutputStream fileOutputStream = null ; boolean flag = true ; try { if ( ! file . createNewFile ( ) ) { Toast . makeText ( this , R . string . toast_create_file_failed , Toast . LENGTH_LONG ) . show ( ) ; return ; } fileOutputStream = new FileOutputStream ( file ) ; String nmea = ( ( TextView ) findViewById ( R . id . tv_nmea_log ) ) . getText ( ) . toString ( ) ; if ( 0 == nmea . getBytes ( ) . length ) { Toast . makeText ( this , R . string . toast_no_log , Toast . LENGTH_LONG ) . show ( ) ; return ; } fileOutputStream . write ( nmea . getBytes ( ) , 0 , nmea . getBytes ( ) . length ) ; fileOutputStream . flush ( ) ; fileOutputStream . close ( ) ; } catch ( NotFoundException e ) { Log . v ( "@M_" + TAG , "Save nmealog NotFoundException: " + e . getMessage ( ) ) ; flag = false ; } catch ( IOException e ) { Log . v ( "@M_" + TAG , "Save nmealog IOException: " + e . getMessage ( ) ) ; flag = false ; } finally { if ( null != fileOutputStream ) { try { fileOutputStream . close ( ) ; } catch ( IOException e ) { Log . v ( "@M_" + TAG , "Save nmealog exception in finally: " + e . getMessage ( ) ) ; flag = false ; } } } if ( flag ) { Log . v ( "@M_" + TAG , "Save Nmealog to file Finished" ) ; Toast . makeText ( this , String . format ( getString ( R . string . toast_save_log_succeed_to ) , Environment . getExternalStorageDirectory ( ) . getAbsolutePath ( ) ) , Toast . LENGTH_LONG ) . show ( ) ; } else { Log . w ( "@M_" + TAG , "Save Nmealog Failed" ) ; Toast . makeText ( this , R . string . toast_save_log_failed , Toast . LENGTH_LONG ) . show ( ) ; } } else { Log . v ( "@M_" + TAG , "saveNMEALog function: No SD card" ) ; Toast . makeText ( this , ( R . string . no_sdcard ) , Toast . LENGTH_LONG ) . show ( ) ; } } else { String strTime = DATE_FORMAT . format ( new Date ( System . currentTimeMillis ( ) ) ) ; File nmeaPath = new File ( NMEALOG_PATH ) ; if ( ! nmeaPath . exists ( ) ) { nmeaPath . mkdirs ( ) ; } File file = new File ( nmeaPath , NMEA_LOG_PREX + strTime + NMEA_LOG_SUFX ) ; if ( file != null ) { FileOutputStream outs = null ; boolean flag = true ; try { file . createNewFile ( ) ; outs = new FileOutputStream ( file ) ; String nmea = ( ( TextView ) findViewById ( R . id . tv_nmea_log ) ) . getText ( ) . toString ( ) ; if ( 0 == nmea . getBytes ( ) . length ) { Toast . makeText ( this , R . string . toast_no_log , Toast . LENGTH_LONG ) . show ( ) ; return ; } outs . write ( nmea . getBytes ( ) , 0 , nmea . getBytes ( ) . length ) ; outs . flush ( ) ; } catch ( IOException e ) { Log . v ( "@M_" + TAG , "Save nmealog IOException: " + e . getMessage ( ) ) ; flag = false ; } finally { if ( null != outs ) { try { outs . close ( ) ; } catch ( IOException e ) { Log . v ( "@M_" + TAG , "Save nmealog exception in finally: " + e . getMessage ( ) ) ; flag = false ; } } } if ( flag ) { Log . v ( "@M_" + TAG , "Save Nmealog to file Finished" ) ; Toast . makeText ( this , String . format ( getString ( R . string . toast_save_log_succeed_to ) , NMEALOG_PATH ) , Toast . LENGTH_LONG ) . show ( ) ; } else { Log . w ( "@M_" + TAG , "Save NmeaLog failed!" ) ; Toast . makeText ( this , R . string . toast_save_log_failed , Toast . LENGTH_LONG ) . show ( ) ; } } } }
Save NMEA log to file.
Save NMEA log to file .