List of usage examples for android.content ContextWrapper getExternalFilesDir
@Override
public File getExternalFilesDir(String type)
From source file:com.quinsoft.zeidon.android.AndroidUtils.java
/** * Checks to see if the targetDbName exists. If not it will be copied from emptyDbName, * which must be in the assets directory. * * @param context/*from w ww . ja v a 2 s .c o m*/ * @param emptyDbName * @param targetDbName */ public static void initializeDatabase(ContextWrapper context, String emptyDbName, String targetDbName) { context.getExternalFilesDir(null); // Create files directory if necessary. File f = new File(targetDbName); if (f.exists()) // Does DB already exist? return; Log.i("AndroidUtils.initializeDatabase", "Initializing DB by copying " + emptyDbName + " to " + f.getAbsolutePath()); InputStream ins = null; FileOutputStream fos = null; try { ins = context.getAssets().open(emptyDbName); } catch (IOException e) { throw ZeidonException.wrapException(e).prependFilename(emptyDbName); } try { fos = new FileOutputStream(f); } catch (Exception e) { IOUtils.closeQuietly(ins); throw ZeidonException.wrapException(e).prependFilename(targetDbName); } try { byte[] buffer = new byte[1024]; int size = 0; while ((size = ins.read(buffer, 0, buffer.length)) >= 0) fos.write(buffer, 0, size); } catch (IOException e) { throw ZeidonException.wrapException(e).prependFilename(emptyDbName); } finally { IOUtils.closeQuietly(ins); IOUtils.closeQuietly(fos); } }
From source file:co.dilaver.quoter.activities.ShareActivity.java
private void save() { previewLayout.setDrawingCacheEnabled(true); previewLayout.buildDrawingCache();/*from w w w . j av a 2 s . com*/ Bitmap bmp = Bitmap.createBitmap(previewLayout.getDrawingCache()); previewLayout.setDrawingCacheEnabled(false); ContextWrapper cw = new ContextWrapper(this); File directory = cw.getExternalFilesDir(null); if (!directory.exists()) { directory.mkdir(); } File image = new File(directory, "image.jpg"); FileOutputStream fos; try { fos = new FileOutputStream(image); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + image.getAbsolutePath())); shareIntent.setType("image/jpeg"); startActivity(Intent.createChooser(shareIntent, getString(R.string.str_ShareWith))); }
From source file:com.csounds.examples.tests.MultiTouchXYActivity.java
private void writeToFile(String data) { try {/*from w w w. j a v a 2s . c om*/ if (!txtfile.exists()) { Log.d("txtfile", "txtfile doesn't exist"); ContextWrapper cw = new ContextWrapper(this); File directory = cw.getExternalFilesDir(null); txtfile = new File(directory, "temp.txt"); } System.out.println("zz" + txtfile); FileOutputStream outStream = new FileOutputStream(txtfile, true); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outStream); String output = String.format(data); // BufferedWriter oFile = new BufferedWriter(new OutputStreamWriter( // new FileOutputStream("test.txt"), "UTF-16")); outputStreamWriter.append("\r\n"); outputStreamWriter.append(output); outputStreamWriter.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } }
From source file:com.csounds.examples.tests.MultiTouchXYActivity.java
public void storeRAWFilesToInternalStorage() throws IOException { InputStream in = getResources().openRawResource(R.raw.record01); if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File file = new File(this.getFilesDir(), "csoundtracks"); ContextWrapper cw = new ContextWrapper(this); File directory = cw.getExternalFilesDir(null); File wavfile = new File(directory, "record01.wav"); if (!file.mkdirs()) { Log.e("logtag", "Directory not created"); }/*from w w w . j a va 2 s .com*/ System.out.println(wavfile.getAbsolutePath()); System.out.println("wavfile" + wavfile + " directory " + directory); if (!wavfile.exists()) { Log.e("logtag", "wave file not created"); try { wavfile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } if (!wavfile.exists()) { Log.e("logtag", "wave2 file not created"); } FileOutputStream out = new FileOutputStream(wavfile); byte[] buff = new byte[1024]; int read = 0; try { while ((read = in.read(buff)) > 0) { out.write(buff, 0, read); } } finally { in.close(); out.close(); } } }