public void onClick(View v) {
    if (v.getId() == R.id.browse) {
      boolean mExternalStorageAvailable = false;
      String state = Environment.getExternalStorageState();

      if (Environment.MEDIA_MOUNTED.equals(state)
          || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        mExternalStorageAvailable = true;
      } else {
        mExternalStorageAvailable = false;
      }

      if (mExternalStorageAvailable) {
        System.out.println(Environment.getExternalStorageDirectory().toString());
        Log.d(TAG, Environment.getExternalStorageDirectory().toString());

        mPath = new File(Environment.getExternalStorageDirectory().toString());
        Log.d(TAG, mPath.toString());
        mFileList = mPath.list();
        onCreateDialog(AWS_APP_FILE_SELECT_DIALOG);
      }
    } else if (v.getId() == R.id.upload) {
      /* Switch to File List view */
      Intent i = new Intent(getApplicationContext(), AwsAppGetFileListActivity.class);
      startActivity(i);
    }
  }
예제 #2
0
    public void scanForExistingVideosAndImport() {
      boolean mExternalStorageAvailable = false;
      boolean mExternalStorageWriteable = false;
      File rootfolder = Environment.getExternalStorageDirectory();

      String state = Environment.getExternalStorageState();
      if (Environment.MEDIA_MOUNTED.equals(state)) {
        mExternalStorageAvailable = mExternalStorageWriteable = true;
      } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
      } else {
        mExternalStorageAvailable = mExternalStorageWriteable = false;
      }

      // OK, start
      if (mExternalStorageAvailable) {
        Log.d(
            TAG,
            "Starting import. OUR Directory path is : "
                + Environment.getExternalStorageDirectory().getAbsolutePath()
                + res.getString(R.string.rootSDcardFolder));
        directoryScanRecurse(rootfolder);
      }

      Log.d(TAG, " Import FINISHED !");
    }
  /** Checks if the application has external storage available and readable. */
  public static boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();

    return (state != null)
        && (Environment.MEDIA_MOUNTED.equals(state)
            || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state));
  }
예제 #4
0
  private void openIfRequired() throws IOException {
    String state = Environment.getExternalStorageState();
    if (mSerializer == null) {
      String fileName = mReportFile;
      if (mMultiFile) {
        fileName = fileName.replace("$(suite)", "test");
      }
      if (mReportDir == null) {
        if (Environment.MEDIA_MOUNTED.equals(state)
            && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
          File f = mContext.getExternalFilesDir("testng");
          mOutputStream = new FileOutputStream(new File(f, fileName));
        } else {
          mOutputStream = mTargetContext.openFileOutput(fileName, 0);
        }
      } else {
        mOutputStream = new FileOutputStream(new File(mReportDir, fileName));
      }

      mSerializer = Xml.newSerializer();
      mSerializer.setOutput(mOutputStream, ENCODING_UTF_8);
      mSerializer.startDocument(ENCODING_UTF_8, true);
      if (!mMultiFile) {
        mSerializer.startTag("", TAG_SUITES);
      }
    }
  }
 // verificar que se pueda leer desde la memoria externa
 public static boolean isExternalStorageReadOnly() {
   String extStorageState = Environment.getExternalStorageState();
   if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) {
     return true;
   }
   return false;
 }
예제 #6
0
  private File file_location(String ntag) {

    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      // We can read and write the media
      mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      // We can only read the media
      mExternalStorageAvailable = true;
      mExternalStorageWriteable = false;
    } else {
      mExternalStorageAvailable = mExternalStorageWriteable = false;
    }

    if (mExternalStorageAvailable && mExternalStorageWriteable) {
      String ftag = dtf.format(new Date());
      // return new File(Environment.getExternalStorageDirectory(), ftag+ntag);
      return new File(getExternalFilesDir(null), ftag + ntag);
    } else {
      mLV.addtext("No external Storage.");
      return null;
    }
  }
  /**
   * Method to check if external storage is available and writable.
   *
   * @return true if available and writable
   */
  public static boolean isExternalStorageAvailable() {

    boolean externalStorageAvailable = false;
    boolean externalStorageWriteable = false;

    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      // We can read and write the media
      externalStorageAvailable = externalStorageWriteable = true;
      if (FrameworkContext.INFO) Log.i(TAG, "Media is available and writeable.");
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      // We can only read the media
      externalStorageAvailable = true;
      externalStorageWriteable = false;
      if (FrameworkContext.INFO) Log.i(TAG, "Media readonly.");
    } else {
      // Something else is wrong. It may be one of many other states, but
      // all we need to know is we can neither read nor write.
      externalStorageAvailable = externalStorageWriteable = false;
      if (FrameworkContext.INFO) Log.i(TAG, "Media neither read or write.");
    }

    if (externalStorageAvailable && externalStorageWriteable) return true;
    else return false;
  }
예제 #8
0
 public boolean isExternalStorageReadable() {
   String state = Environment.getExternalStorageState();
   if (Environment.MEDIA_MOUNTED.equals(state)
       || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
     return true;
   }
   return false;
 }
예제 #9
0
 /*package*/ static boolean isExternalStorageReady() {
   String state = Environment.getExternalStorageState();
   boolean isReady =
       (Environment.MEDIA_MOUNTED.equals(state)
           || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state));
   if (LOG) Log.v(TAG, "external storage state = " + state);
   if (LOG) Log.v(TAG, "external storage is ready = " + String.valueOf(isReady));
   return isReady;
 }
 /* Checks if external storage is available to at least read */
 public boolean isExternalStorageReadable() {
   String state = Environment.getExternalStorageState();
   if (Environment.MEDIA_MOUNTED.equals(state)
       || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
     Log.d("FileWriter", "External Readable");
     return true;
   }
   Log.d("FileWriter", "External Not Readable");
   return false;
 }
예제 #11
0
 public void checkExternalStorage() {
   String state = Environment.getExternalStorageState();
   if (Environment.MEDIA_MOUNTED.equals(state)) {
     // ok
   } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
     AccessibleToast.makeText(this, R.string.sd_mounted_ro, Toast.LENGTH_LONG).show();
   } else {
     AccessibleToast.makeText(this, R.string.sd_unmounted, Toast.LENGTH_LONG).show();
   }
 }
예제 #12
0
  private boolean hasStorage() {
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      boolean writable = checkFsWritable();
      return writable;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      return true;
    }
    return false;
  }
예제 #13
0
  public static boolean isStorageWritable() {
    boolean mExternalStorageWriteable = false;

    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) mExternalStorageWriteable = true;
    else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) mExternalStorageWriteable = false;
    else mExternalStorageWriteable = false;

    return mExternalStorageWriteable;
  }
예제 #14
0
파일: Utility.java 프로젝트: Gaju/Glamvoir
  /** @return True if the external storage is available. False otherwise. */
  public static boolean checkAvailable() {

    // Retrieving the external storage state
    String state = Environment.getExternalStorageState();

    // Check if available
    if (Environment.MEDIA_MOUNTED.equals(state)
        || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      return true;
    }
    return false;
  }
예제 #15
0
 public void updateExternalStorageState() {
   String state = Environment.getExternalStorageState();
   if (Environment.MEDIA_MOUNTED.equals(state)) {
     mExternalStorageAvailable = mExternalStorageWriteable = true;
   } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
     mExternalStorageAvailable = true;
     mExternalStorageWriteable = false;
   } else {
     mExternalStorageAvailable = mExternalStorageWriteable = false;
   }
   //	    handleExternalStorageState(mExternalStorageAvailable,mExternalStorageWriteable);
 }
예제 #16
0
 /**
  * 获取sd卡路径
  *
  * @return
  */
 public static String getSdcardAbsPath() {
   String sdDir = null;
   String state = Environment.getExternalStorageState();
   LogHelper.println(state);
   if (Environment.MEDIA_MOUNTED.equals(state)) {
     sdDir = Environment.getExternalStorageDirectory() + "";
   } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
   } else if (Environment.MEDIA_REMOVED.equals(state)) {
   } else {
   }
   return sdDir;
 }
  public static boolean externalStorageAvailabe(boolean needToWrite) {
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      // Write and read
      return true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) && !needToWrite) {
      // Only read
      return true;
    }

    return false;
  }
예제 #18
0
 /**
  * 检查SD卡状态是否就绪
  *
  * @return
  */
 public static boolean checkExternalStorage() {
   String state = Environment.getExternalStorageState();
   boolean mExternalStorageAvailable, mExternalStorageWriteable;
   if (Environment.MEDIA_MOUNTED.equals(state)) {
     mExternalStorageAvailable = mExternalStorageWriteable = true;
   } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
     mExternalStorageAvailable = true;
     mExternalStorageWriteable = false;
   } else {
     mExternalStorageAvailable = mExternalStorageWriteable = false;
   }
   return mExternalStorageAvailable && mExternalStorageWriteable;
 }
예제 #19
0
 public static boolean hasStorage(boolean requireWriteAccess) {
   String state = Environment.getExternalStorageState();
   if (Environment.MEDIA_MOUNTED.equals(state)) {
     if (requireWriteAccess) {
       boolean writable = checkFsWritable();
       return writable;
     } else {
       return true;
     }
   } else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
     return true;
   }
   return false;
 }
예제 #20
0
 /** ************************************************************************************** */
 public void verificarSD() {
   String state = Environment.getExternalStorageState();
   if (Environment.MEDIA_MOUNTED.equals(state)) {
     // SD can read and write to disk
     mExternalStorageAvailable = mExternalStorageWriteable = true;
   } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
     // SD read only
     mExternalStorageAvailable = true;
     mExternalStorageWriteable = false;
   } else {
     // Is there something wrong with the disk or device does not exist
     // we can not do anything.
     mExternalStorageAvailable = mExternalStorageWriteable = false;
   }
 }
  private void checkExternalMedia() {
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      // Can read and write the media
      mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      // Can only read the media
      mExternalStorageAvailable = true;
      mExternalStorageWriteable = false;
    } else {
      // Can't read or write
      mExternalStorageAvailable = mExternalStorageWriteable = false;
    }
  }
예제 #22
0
  private ArrayList<String> getFilenames() {
    String state = Environment.getExternalStorageState();

    if (!(Environment.MEDIA_MOUNTED.equals(state)
        || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))) return null;

    File fileDir = new File(MainActivity.getDocumentsFolderPath()); // device/sdcard
    ArrayList<String> fileList = new ArrayList<String>();
    File[] files = fileDir.listFiles();
    Arrays.sort(files); // listfiles does not have an order...
    if (files.length == 0) return null;
    else {
      for (int i = 0; i < files.length; i++) fileList.add(files[i].getName());
    }

    return fileList;
  }
예제 #23
0
  private void checkExternalMedia() {
    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      // Can read and write the media
      mExternalStorageAvailable = mExternalStorageWriteable = true;
      //			Toast.makeText(context, "Storage readable.", Toast.LENGTH_SHORT).show();
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      // Can only read the media
      mExternalStorageAvailable = true;
      mExternalStorageWriteable = false;
    } else {
      // Can't read or write
      mExternalStorageAvailable = mExternalStorageWriteable = false;
    }
  }
  public boolean isExternalStorageWriteable() {
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      // We can read and write the media
      mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      // We can only read the media
      mExternalStorageWriteable = false;
    } else {
      // Something else is wrong. It may be one of many other states, but all we need
      //  to know is we can neither read nor write
      mExternalStorageWriteable = false;
    }
    Log.d(TAG, "isExternalStorageWriteable: " + mExternalStorageWriteable);
    return mExternalStorageWriteable;
  }
  /*
   * returns false if external storage is not avaliable
   * (if its mounted, missing, read-only, etc)
   * from: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
   */
  private boolean storageIsReady() {
    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      // We can read and write the media
      mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      // We can only read the media
      mExternalStorageAvailable = true;
      mExternalStorageWriteable = false;
    } else {
      // Something else is wrong. It may be one of many other states, but all we need
      //  to know is we can neither read nor write
      mExternalStorageAvailable = mExternalStorageWriteable = false;
    }
    return mExternalStorageAvailable && mExternalStorageWriteable;
  }
예제 #26
0
  public void saveBitmap() {
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      saveToSdcard();
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      Toast.makeText(
              this.context,
              getResources().getString(R.string.tip_sdcard_is_read_only),
              Toast.LENGTH_SHORT)
          .show();
    } else {
      Toast.makeText(
              this.context,
              getResources().getString(R.string.tip_sdcard_is_not_available),
              Toast.LENGTH_SHORT)
          .show();
    }
  }
 public int getExternalStorageState() {
   /*
    * EXTERNAL_STORAGE_ERROR: 0
    * EXTERNAL_STORAGE_READABLE_ONLY: 1
    * EXTERNAL_STORAGE_WRITEABLE: 2
    */
   String state = Environment.getExternalStorageState();
   if (Environment.MEDIA_MOUNTED.equals(state)) {
     // We can read and write the media
     return EXTERNAL_STORAGE_READABLE_WRITEABLE;
   } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
     // We can only read the media
     return EXTERNAL_STORAGE_READABLE_ONLY;
   } else {
     // Something else is wrong. It may be one of many other states, but all we need
     //  to know is we can neither read nor write
     return EXTERNAL_STORAGE_ERROR;
   }
 }
  private void checkStorageState() {

    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      // We can read and write the media
      isExternalStorageAvailable = isExternalStorageWriteable = true;
      if (FrameworkContext.INFO) Log.i(TAG, "Media is available and writeable.");
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      // We can only read the media
      isExternalStorageAvailable = true;
      isExternalStorageWriteable = false;
      if (FrameworkContext.INFO) Log.i(TAG, "Media readonly.");
    } else {
      // Something else is wrong. It may be one of many other states, but
      // all we need to know is we can neither read nor write.
      isExternalStorageAvailable = isExternalStorageWriteable = false;
      if (FrameworkContext.INFO) Log.i(TAG, "Media neither read or write.");
    }
  }
예제 #29
0
  // @SuppressLint("NewApi")
  protected Device initFromExternalStorageDirectory() {
    File f = Environment.getExternalStorageDirectory();
    mLabel = mMountPoint = f.getAbsolutePath();

    String state = Environment.getExternalStorageState();
    /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
      		mRemovable = Environment.isExternalStorageRemovable(); // Gingerbread weiß es genau
    else*/
    mRemovable = false; // guess, wird ggf. später korrigiert

    if (Environment.MEDIA_MOUNTED.equals(state)) {
      mAvailable = mWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
      mAvailable = true;
      mWriteable = false;
    } else {
      mAvailable = mWriteable = false;
      // nicht mRemovable=true! Unmounted kann auch heißen, dass sie per USB am PC hängt
    }
    if (mAvailable) mSize = Size.getSpace(f);
    return this;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    bar.setDisplayShowHomeEnabled(false);
    bar.setDisplayShowTitleEnabled(false);

    String state = Environment.getExternalStorageState();
    if (!(Environment.MEDIA_MOUNTED.equals(state)
        || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))) {
      setResult(-1);
      finish();
    }

    setContentView(R.layout.directory);

    list = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1);
    filter = (FileFilter) getIntent().getExtras().getParcelable("filter");
    setupUI();
    setDirView();
  }