Tas*_*zbi 6 android android-camera android-camera-intent
我在Android中使用相机,我是Android相机的新手.我从这里开始关注教程
每当我在android清单中添加外部存储权限时,相机会将其保存在默认目录中,而不会询问我,我想将其保存在我在sd卡中创建的文件夹中.我搜索了很多但找不到任何有用的链接.请帮助,任何帮助将不胜感激.谢谢 :)
您可以在 onActivityResult 中添加此代码。这会将您的图像存储在名为“YourFolderName”的文件夹中
String extr = Environment.getExternalStorageDirectory().toString()
+ File.separator + "YourFolderName";
File myPath = new File(extr, fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
bitMap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(context.getContentResolver(),
bitMap, myPath.getPath(), fileName);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
还需要在Manifest上设置权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8344 次 |
| 最近记录: |