2016-05-16 289 views
0

我目前可以使用Es文件浏览器将图像保存到我的应用程序中以共享Windows文件夹。如何使用es文件管理器保存图像

但我想知道的是,如何消除选择文件夹并在代码中指定它的过程?

public void SaveToNetwork() { 
    Intent shareIntent = new Intent(Android.Content.Intent.ActionSend); 

    shareIntent.SetType("*/*"); 
    shareIntent.PutExtra(Android.Content.Intent.ExtraStream, Android.Net.Uri.FromFile(new File(App._dir, App._file.Name))); 

    shareIntent.SetPackage("com.estrongs.android.pop"); 

    StartActivity(shareIntent); 
} 

我不想使用文件资源管理器。我只想直接将它保存到文件夹,或者至少将默认选定的文件夹更改为正确的文件夹。

+0

Android提供文件级和outpustream类为此目的http://developer.android.com/reference/java/io/File.html http://developer.android.com/reference/java/io/OutputStream.html –

回答

0

Android提供File类和outpustream类用于此目的以下是收到
位图,并将其保存到指定的文件夹,然后你的图像添加到库内容提供商的示例代码

private String savePic(Bitmap bitmapImage) { 
      try { 

       //bitmapImage=drawView.getmCanvasBitmap(); 

       File dir = new File(
         Environment 
           .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), 
         "youfoldername"); 

       dir.mkdir(); 
       Calendar c = Calendar.getInstance(); 
       if (dir.isDirectory()) { 
        String path = dir.getAbsolutePath() + "/youfilename" 
          + c.getTimeInMillis() + ".Jpg"; 
        FileOutputStream fos = new FileOutputStream(path); 
        // Use the compress method on the BitMap object to write image 
        // to 
        // the OutputStream 

        bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); 
        fos.close(); 


        ContentValues values = new ContentValues(); 
        values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis()); 
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); 
        values.put(MediaStore.MediaColumns.DATA, path); 
        getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 
        Intent intent = new Intent(Intent.ACTION_SEND); 
        intent.setType("image/Jpg"); 
        intent.putExtra(android.content.Intent.EXTRA_STREAM, 
          Uri.parse("file://" + path)); 
        startActivity(intent); 

        return path; 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
      return ""; 
     } 
+0

这不工作时,我想要保存到网络上的共享Windows文件夹 – Matt