List of usage examples for android.os Environment MEDIA_MOUNTED
String MEDIA_MOUNTED
To view the source code for android.os Environment MEDIA_MOUNTED.
Click Source Link
From source file:io.strider.camera.CameraLauncher.java
public void cleanCache() { File cache = null;/* w ww . j a v a 2 s. co m*/ // SD Card Mounted if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/"); } // Use internal storage else { cache = cordova.getActivity().getCacheDir(); } // Empty Cache folder if (cache.exists()) { File[] files = cache.listFiles(); for (int i = 0; i < files.length; i++) { files[i].delete(); } } }
From source file:babybear.akbquiz.ConfigActivity.java
/** * ?/* w w w . ja v a2 s. c om*/ */ 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:org.jinzora.util.DrawableManager.java
private boolean externalStorageAvailable() { String state = Environment.getExternalStorageState(); return (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)); }
From source file:com.polyvi.xface.extension.camera.XCameraExt.java
private Cursor queryImgDB() { Uri contentUri = null;/*from w w w . j a va 2s. co m*/ 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.matthewmitchell.peercoin_android_wallet.ui.WalletActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); if (!application.isLoaded()) return false; // Wallet not loaded just yet final Resources res = getResources(); final String externalStorageState = Environment.getExternalStorageState(); boolean writable = Environment.MEDIA_MOUNTED.equals(externalStorageState); boolean readOnly = Environment.MEDIA_MOUNTED_READ_ONLY.equals(externalStorageState); menu.findItem(R.id.wallet_options_exchange_rates) .setVisible(res.getBoolean(R.bool.show_exchange_rates_option)); menu.findItem(R.id.wallet_options_restore_wallet).setEnabled(writable || readOnly); menu.findItem(R.id.wallet_options_backup_wallet).setEnabled(writable); menu.findItem(R.id.wallet_options_export) .setEnabled(writable && txListAdapter != null && !txListAdapter.transactions.isEmpty()); menu.findItem(R.id.wallet_options_encrypt_keys) .setTitle(application.getWallet().isEncrypted() ? R.string.wallet_options_encrypt_keys_change : R.string.wallet_options_encrypt_keys_set); return true;/*from w w w . j a v a 2s. c o m*/ }
From source file:com.teleca.jamendo.activity.HomeActivity.java
/** * Fills ListView with clickable menu items *///from w w w .ja va2s . 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: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);/*w ww . ja v a2s .c o m*/ 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.cordova.photo.CameraLauncher.java
private String getTempDirectoryPath() { File cache = null;/*w w w . j a va 2s .c o m*/ // 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.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 w ww . jav a2s. co m*/ }