daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Apr 17th, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private String storeImage(Bitmap bitmap,String fileName){
  2.         String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/FilterImages";
  3.         File dir = new File(dirPath);
  4.         if(!dir.exists()){
  5.             dir.mkdir();
  6.         }
  7.         File file = new File(dirPath,fileName);
  8.         try{
  9.             FileOutputStream fileOutputStream = new FileOutputStream(file);
  10.             bitmap.compress(Bitmap.CompressFormat.PNG,100,fileOutputStream);
  11.             fileOutputStream.flush();
  12.             fileOutputStream.close();
  13.             //Toast.makeText(this, "Saved: " + file, Toast.LENGTH_SHORT).show();
  14.         } catch (FileNotFoundException e) {
  15.             e.printStackTrace();
  16.         } catch (IOException e) {
  17.             e.printStackTrace();
  18.         }
  19.         String filePath = dirPath + "/" + fileName;
  20.         return filePath;
  21.     }
  22.  
  23.     public void copyFileOrDir(String path) {
  24.         AssetManager assetManager = this.getAssets();
  25.         String assets[] = null;
  26.         try {
  27.             assets = assetManager.list(path);
  28.             if (assets.length == 0) {
  29.                 copyFile(path);
  30.             } else {
  31.  
  32.                 String fullPath = "data/data/" + this.getPackageName() + "/" + path;
  33.                 Log.i("INFO","Copying to : " + fullPath);
  34.                 File dir = new File(fullPath);
  35.                 if (!dir.exists())
  36.                     dir.mkdir();
  37.                 for (int i = 0; i < assets.length; ++i) {
  38.                     copyFileOrDir(path + "/" + assets[i]);
  39.                 }
  40.             }
  41.         } catch (IOException ex) {
  42.             Log.i("INFO", "I/O Exception");
  43.         }
  44.     }
  45.     private void copyFile(String filename) {
  46.         AssetManager assetManager = this.getAssets();
  47.  
  48.         InputStream in = null;
  49.         OutputStream out = null;
  50.         try {
  51.             in = assetManager.open(filename);
  52.             String newFileName = "/data/data/" + this.getPackageName() + "/" + filename;
  53.             Log.i("INFO","File Name: " + filename);
  54.             out = new FileOutputStream(newFileName);
  55.  
  56.             byte[] buffer = new byte[1024];
  57.             int read;
  58.             while ((read = in.read(buffer)) != -1) {
  59.                 out.write(buffer, 0, read);
  60.             }
  61.             in.close();
  62.             in = null;
  63.             out.flush();
  64.             out.close();
  65.             out = null;
  66.         } catch (Exception e) {
  67.             Log.i("INFO", "Catch: " + e.getMessage());
  68.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top