![](/img/trans.png)
[英]How can I open an image saved within the app with the android gallery?
[英]How can i make sure the image is not saved to gallery?
我正在開發一個允許用戶用密碼保護照片的應用程序。 到目前為止,用戶可以拍攝照片並顯示照片。 但是,所有照片都會保存到相機膠卷中。 我如何將它們保存到應用程序而不是相機膠卷中,以便它們可以是私有的,但仍然可以從其uri訪問它們(我將其保存到SharedPreferences中)?
int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 0;
Uri imageUri;
public void takePic(View view){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "filename_" +
String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra("data", imageUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
Bundle extras = data.getExtras();
Log.e("URI", imageUri.toString());
Bitmap bmp = (Bitmap) extras.get("data");
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(bmp);
}
else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
}
}
}
在文件夾中創建一個名為(.nomedia)的文件,那么該文件夾中的所有照片將不會顯示! 或將照片保存在內部存儲中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.