List of usage examples for android.os Environment getExternalStorageState
public static String getExternalStorageState()
From source file:com.polyvi.xface.extension.camera.XCameraExt.java
private Cursor queryImgDB() { Uri contentUri = null;/* w w w. j a v a2 s . c om*/ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { contentUri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else { contentUri = android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI; } return mExtensionContext.getSystemContext().getContext().getContentResolver().query(contentUri, new String[] { MediaStore.Images.Media._ID }, null, null, null); }
From source file:com.teleca.jamendo.activity.HomeActivity.java
/** * Fills ListView with clickable menu items *//*from w ww . j a v a2s . c o m*/ private void fillHomeListView() { mBrowseJamendoPurpleAdapter = new PurpleAdapter(this); mMyLibraryPurpleAdapter = new PurpleAdapter(this); ArrayList<PurpleEntry> browseListEntry = new ArrayList<PurpleEntry>(); ArrayList<PurpleEntry> libraryListEntry = new ArrayList<PurpleEntry>(); // BROWSE JAMENDO browseListEntry.add(new PurpleEntry(R.drawable.list_search, R.string.search, new PurpleListener() { @Override public void performAction() { SearchActivity.launch(HomeActivity.this); } })); browseListEntry.add(new PurpleEntry(R.drawable.list_radio, R.string.radio, new PurpleListener() { @Override public void performAction() { RadioActivity.launch(HomeActivity.this); } })); browseListEntry.add(new PurpleEntry(R.drawable.list_top, R.string.most_listened, new PurpleListener() { @Override public void performAction() { new Top100Task(HomeActivity.this, R.string.loading_top100, R.string.top100_fail).execute(); } })); // MY LIBRARY libraryListEntry.add(new PurpleEntry(R.drawable.list_playlist, R.string.playlists, new PurpleListener() { @Override public void performAction() { BrowsePlaylistActivity.launch(HomeActivity.this, Mode.Normal); } })); // check if we have personalized client then add starred albums final String userName = PreferenceManager.getDefaultSharedPreferences(this).getString("user_name", null); if (userName != null && userName.length() > 0) { libraryListEntry.add(new PurpleEntry(R.drawable.list_cd, R.string.albums, new PurpleListener() { @Override public void performAction() { StarredAlbumsActivity.launch(HomeActivity.this, userName); } })); } /* following needs jamendo authorization (not documented yet on the wiki) * listEntry.add(new PurpleEntry(R.drawable.list_mail, "Inbox")); */ // show this list item only if the SD Card is present if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { libraryListEntry.add(new PurpleEntry(R.drawable.list_download, R.string.download, new PurpleListener() { @Override public void performAction() { DownloadActivity.launch(HomeActivity.this); } })); } // listEntry.add(new PurpleEntry(R.drawable.list_star, R.string.favorites, new PurpleListener(){ // // @Override // public void performAction() { // Playlist playlist = new DatabaseImpl(HomeActivity.this).getFavorites(); // JamendroidApplication.getInstance().getPlayerEngine().openPlaylist(playlist); // PlaylistActivity.launch(HomeActivity.this, true); // } // // })); // attach list data to adapters mBrowseJamendoPurpleAdapter.setList(browseListEntry); mMyLibraryPurpleAdapter.setList(libraryListEntry); // separate adapters on one list SeparatedListAdapter separatedAdapter = new SeparatedListAdapter(this); separatedAdapter.addSection(getString(R.string.browse_jamendo), mBrowseJamendoPurpleAdapter); separatedAdapter.addSection(getString(R.string.my_library), mMyLibraryPurpleAdapter); mHomeListView.setAdapter(separatedAdapter); mHomeListView.setOnItemClickListener(mHomeItemClickListener); }
From source file:babybear.akbquiz.ConfigActivity.java
/** * ?/*from w w w . j a v a 2 s .c o m*/ */ private void init() { ToggleButton bgm_toggle = (ToggleButton) findViewById(R.id.bgm_switch); ToggleButton sound_toggle = (ToggleButton) findViewById(R.id.sound_switch); ToggleButton vibration_toggle = (ToggleButton) findViewById(R.id.config_vibration_switch); SeekBar bgm_vol = (SeekBar) findViewById(R.id.bgm_volume); SeekBar sound_vol = (SeekBar) findViewById(R.id.sound_volume); Button config_playlist = (Button) findViewById(R.id.config_playlist); bgm_toggle.setChecked(sp_cfg.getBoolean(Database.KEY_switch_bg, true)); sound_toggle.setChecked(sp_cfg.getBoolean(Database.KEY_switch_sound, true)); vibration_toggle.setChecked(sp_cfg.getBoolean(Database.KEY_switch_vibration, true)); bgm_vol.setProgress(sp_cfg.getInt(Database.KEY_vol_bg, 10)); sound_vol.setProgress(sp_cfg.getInt(Database.KEY_vol_sound, 10)); // ? loopmode = sp_cfg.getInt(Database.KEY_bgm_loopmode, BgMusic.MODE_LOOP); switch (loopmode) { case BgMusic.MODE_LOOP: ((Button) findViewById(R.id.config_loopmode)).setText(R.string.config_loop); case BgMusic.MODE_RANDOM: ((Button) findViewById(R.id.config_loopmode)).setText(R.string.config_random); case BgMusic.MODE_SINGLE: ((Button) findViewById(R.id.config_loopmode)).setText(R.string.config_single); } // ? if (sp_cfg.getBoolean(Database.KEY_use_custom_background, false)) { cfgflipper.setBackgroundDrawable(Drawable.createFromPath(customBgImage.getPath())); } OnClickListener clickListener = new OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.bgm_switch: boolean isBgOn = ((ToggleButton) v).isChecked(); cfgEditor.putBoolean(Database.KEY_switch_bg, isBgOn); Message msg = new Message(); msg.what = isBgOn ? 1 : 0; msg.arg1 = BgMusic.BGHandler.SWITCH_CHANGE; BgMusic.bgHandler.sendMessage(msg); break; case R.id.sound_switch: boolean isSoundOn = ((ToggleButton) v).isChecked(); cfgEditor.putBoolean(Database.KEY_switch_sound, isSoundOn); MainMenu.se.setSwitch(isSoundOn); break; case R.id.config_vibration_switch: boolean isVibOn = ((ToggleButton) v).isChecked(); cfgEditor.putBoolean(Database.KEY_switch_vibration, isVibOn); break; case R.id.config_playlist: if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { if (!isPlaylistChanged) { loadPlaylistEditor(); } cfgflipper.showNext(); } else { Toast.makeText(ConfigActivity.this, R.string.sdcard_unavailable, Toast.LENGTH_SHORT).show(); } break; case R.id.config_ranking: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=" + getPackageName())); startActivity(intent); break; case R.id.config_back: cfgEditor.commit(); finish(); break; case R.id.config_musiclist_back: case R.id.config_playlist_back: cfgflipper.showPrevious(); break; case R.id.config_update: verCode = getVerCode(ConfigActivity.this); verName = getVerName(ConfigActivity.this); if (getServerVer()) { if (newVerCode > verCode) { doNewVersionUpdate(); // } else { notNewVersionShow(); // ??? } } break; case R.id.config_loopmode: changeLoopMode(); break; case R.id.config_quiz_submit: Intent intent1 = new Intent(ConfigActivity.this, CollectQuiz.class); startActivity(intent1); break; case R.id.config_change_bgimage: customBgImage(); break; case R.id.config_restore_bgimage: restoreBgImage(); break; case R.id.call_calendar_editor: Intent calendar = new Intent(ConfigActivity.this, CalendarEditor.class); startActivity(calendar); break; case R.id.who_are_we: if (aboutFHS == null) { aboutFHS = (new AlertDialog.Builder(ConfigActivity.this)).setTitle(R.string.who_are_we) .setMessage(R.string.about_fhs).setIcon(R.drawable.fhs_logo_48) .setPositiveButton(android.R.string.ok, null).create(); } aboutFHS.show(); break; case R.id.licence: if (license == null) { license = (new AlertDialog.Builder(ConfigActivity.this)).setTitle(R.string.license_title) .setIcon(android.R.drawable.stat_sys_warning).setMessage(R.string.license) .setPositiveButton(android.R.string.ok, null).create(); } license.show(); break; } } }; bgm_toggle.setOnClickListener(clickListener); sound_toggle.setOnClickListener(clickListener); vibration_toggle.setOnClickListener(clickListener); config_playlist.setOnClickListener(clickListener); ((Button) findViewById(R.id.config_back)).setOnClickListener(clickListener); ((Button) findViewById(R.id.config_musiclist_back)).setOnClickListener(clickListener); ((Button) findViewById(R.id.config_playlist_back)).setOnClickListener(clickListener); ((Button) findViewById(R.id.config_update)).setOnClickListener(clickListener); ((Button) findViewById(R.id.config_quiz_submit)).setOnClickListener(clickListener); ((Button) findViewById(R.id.config_ranking)).setOnClickListener(clickListener); ((Button) findViewById(R.id.config_loopmode)).setOnClickListener(clickListener); ((Button) findViewById(R.id.config_change_bgimage)).setOnClickListener(clickListener); ((Button) findViewById(R.id.config_restore_bgimage)).setOnClickListener(clickListener); ((Button) findViewById(R.id.call_calendar_editor)).setOnClickListener(clickListener); ((Button) findViewById(R.id.who_are_we)).setOnClickListener(clickListener); ((Button) findViewById(R.id.licence)).setOnClickListener(clickListener); OnSeekBarChangeListener l_seekbar = new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { switch (arg0.getId()) { case R.id.bgm_volume: cfgEditor.putInt(Database.KEY_vol_bg, arg1); Message msg = new Message(); msg.what = arg1; msg.arg1 = BgMusic.BGHandler.VOL_CHANGE; BgMusic.bgHandler.sendMessage(msg); break; case R.id.sound_volume: cfgEditor.putInt(Database.KEY_vol_sound, arg1); MainMenu.se.setVolume(arg1); break; } } @Override public void onStartTrackingTouch(SeekBar arg0) { } @Override public void onStopTrackingTouch(SeekBar arg0) { } }; bgm_vol.setOnSeekBarChangeListener(l_seekbar); sound_vol.setOnSeekBarChangeListener(l_seekbar); }
From source file:com.example.android.bluetoothlegatt.BluetoothLeService.java
private boolean writeCacheToFile() { /*StringBuilder hexBuilder = new StringBuilder(); for (int i = 0; i < cacheData2.size(); i++) { byte[] item = cacheData2.get(i);/*from ww w . j a va 2s .com*/ for(byte byteChar : item) hexBuilder.append(String.format("%02X ", byteChar)); //?? add \n to line end?? hexBuilder.append("\n"); } //?? add 2 \n to message end. hexBuilder.append("\n\n");*/ // save cache data, and clear. if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File sdCardDir = Environment.getExternalStorageDirectory();//?SDCard try { File saveFile1 = new File(sdCardDir, "ble_byte.txt"); File saveFile2 = new File(sdCardDir, "ble_asci.txt"); FileOutputStream fout1 = new FileOutputStream(saveFile1, true); FileOutputStream fout2 = new FileOutputStream(saveFile2, true); //FileOutputStream fout1 = openFileOutput("out_byte", MODE_APPEND); //FileOutputStream fout2 = openFileOutput("out_asci", MODE_APPEND); for (int i = 0; i < cacheData2.size(); i++) { byte[] item = cacheData2.get(i); StringBuilder hexBuilder = new StringBuilder(); for (byte byteChar : item) hexBuilder.append(String.format("%02X ", byteChar)); fout1.write(hexBuilder.toString().getBytes()); fout1.write("\n".getBytes()); fout2.write(item); } fout1.write("\n\n".getBytes()); fout2.write("\n\n".getBytes()); fout1.close(); fout2.close(); } catch (Exception e) { Log.e(TAG, "error:" + e); e.printStackTrace(); return false; } } else { Log.e(TAG, "sd card fail!"); } return true; }
From source file:com.akop.bach.ImageCache.java
private File getImageFile(String imageUrl) { if (imageUrl == null || mSdImageDir == null) return null; if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) return null; if (!mSdImageDir.exists() && !mSdImageDir.mkdirs()) return null; return new File(mSdImageDir, Uri.parse(imageUrl).getLastPathSegment()); }
From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); final Resources res = getResources(); final String externalStorageState = Environment.getExternalStorageState(); menu.findItem(R.id.wallet_options_exchange_rates) .setVisible(res.getBoolean(R.bool.show_exchange_rates_option)); menu.findItem(R.id.wallet_options_import_keys) .setEnabled(Environment.MEDIA_MOUNTED.equals(externalStorageState) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(externalStorageState)); menu.findItem(R.id.wallet_options_export_keys) .setEnabled(Environment.MEDIA_MOUNTED.equals(externalStorageState)); return true;//from ww w . j a v a 2 s.c o m }
From source file:com.cordova.photo.CameraLauncher.java
private String getTempDirectoryPath() { File cache = null;/*from w ww . j a va2s.com*/ // SD Card Mounted if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + activity.getPackageName() + "/cache/"); } // Use internal storage else { cache = activity.getCacheDir(); } // Create the cache directory if it doesn't exist cache.mkdirs(); return cache.getAbsolutePath(); }
From source file:com.androidzeitgeist.dashwatch.common.IOUtil.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static File getBestAvailableFilesRoot(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // In KitKat we can query multiple devices. // TODO: optimize for stability instead of picking first one File[] roots = context.getExternalFilesDirs(null); if (roots != null) { for (File root : roots) { if (root == null) { continue; }//from www . j ava 2 s. c o m if (Environment.MEDIA_MOUNTED.equals(Environment.getStorageState(root))) { return root; } } } } else if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { // Pre-KitKat, only one external storage device was addressable return context.getExternalFilesDir(null); } // Worst case, resort to internal storage return context.getFilesDir(); }
From source file:com.bloc.blocparty.TimelineFragment.java
/** Create a File for saving an image or video */ private File getOutputMediaFile(int type) { // To be safe, you should check that the SDCard is mounted if (Environment.getExternalStorageState() != null) { // this works for Android 2.2 and above File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "AndroidCameraTestsFolder"); // This location works best if you want the created images to be // shared // between applications and persist after your app has been // uninstalled. // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; }/*from w ww .j a v a 2 s. c o m*/ } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mFileName = "IMG_" + timeStamp + ".jpg"; mediaFile = new File(mediaStorageDir.getPath() + File.separator + mFileName); } else if (type == MEDIA_TYPE_VIDEO) { mFileName = "VID_" + timeStamp + ".mp4"; mediaFile = new File(mediaStorageDir.getPath() + File.separator + mFileName); } else { return null; } return mediaFile; } return null; }