基本上我要做的是允许用户拍照,然后在他们保存图片后,他们可以打开图库(在应用程序内)并查看图片。但是图片没有显示在画廊中。这是我迄今为止所拥有的。 这是拍摄和保存照片时目录的样子:
/storage/sdcard0/Android/data/'my app'/files/ArcFlash/study1/Transformer/trans1/trans1_time_date.png
在图片意图之后,我有onActivityResult
(我压缩图片):
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == 1)
{
if(resultCode == RESULT_OK)
{
SharedPreferences sharedPrefs = getSharedPreferences("userPrefs", Context.MODE_PRIVATE);
String path = sharedPrefs.getString("path", null);
filesToScan.add(path);//ex: /storage/sdcard0/Android/data/'my app'/files/....
Bitmap capturedImage;
if(path != null)
{
capturedImage = BitmapFactory.decodeFile(path);
//Bitmap bitmap = Bitmap.createScaledBitmap(capturedImage, 60, 60, true);
File newPic = new File(path);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(newPic);
capturedImage.compress(Bitmap.CompressFormat.JPEG, 70, fos);
fos.flush();
fos.close();
String test = "file://"+ context.getExternalFilesDir(null).toString() + "/ArcFlash/";
for(int i = 0; i < filesToScan.size(); ++i)
{
File pic = new File(filesToScan.get(i));
Uri uri = Uri.fromFile(pic);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, uri));
}
}
catch(Exception ex)
{
handler.Log(ex.getMessage(), "onActivityResult()", context);
Log.i("customException", "error compressing image: " + ex.getMessage());
}
}
}
}
}
我的filesToScan
是ArrayList<String>