1
我很難爲我的Android程序創建新的目錄,它不會處理到我的stream
方法中。 這裏是我的OnClick方法在MainActivity:在外部存儲API上創建新目錄23
public void savnshare(View v){
if (mBitmap == null){
return;
}
File path = new File(Environment.getExternalStorageDirectory() + "/Bill");
path.mkdirs(); //Result of 'File.mkdirs()' is ignored
Random rand = new Random();
int n = rand.nextInt(20);
String filename = "bill_"+n+".jpeg";
File file = new File(path, filename);
FileOutputStream stream;
try{
stream = new FileOutputStream(file);
mback.compress(Bitmap.CompressFormat.JPEG, 100, stream);
stream.close();
}catch (Exception e){
Toast.makeText(getApplicationContext(),"errr try again...",Toast.LENGTH_SHORT).show();
}
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("image/*");
intent.putExtra(Intent.ACTION_SENDTO, uri);
Intent.createChooser(intent, "Share via...");
startActivity(intent);
}
權限,我用:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
謝謝。
感謝它幫助很多 –