[英]Make images and folder invisble to Gallery saved on SDcard?
嗨,我想讓圖像對 android 畫廊或任何第三方畫廊應用程序不可見,圖像將放在 SD 卡上的特定文件夾中。
例如,我有以下代碼將圖像保存到名為 myimages 的文件夾中。 我只希望存儲在 myimages 文件夾中的圖像對任何圖庫應用程序不可見,並且只有我自己的應用程序可以訪問這些圖像。
void saveBitmap(Bitmap bmp)
{
FileOutputStream os;
String dirName = "/mvc/mvc/myiamges/";
try {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)){
String root = Environment.getExternalStorageDirectory()
.toString();
File dir = new File (root + dirName);
boolean created=dir.mkdirs();
//File file = new File(this.getExternalFilesDir(null),
// this.dirName+fileName);
//this function give null pointer exception so im
//using other one
File file = new File(dir, "aeg2.png");
os = new FileOutputStream(file);
}else{
os = openFileOutput("aeg2.png", MODE_PRIVATE);
}
bmp.compress(CompressFormat.PNG, 100, os);
os.flush();
os.close();
}catch(Exception e){
e.printStackTrace();
}
}
是的,用你想要的任何擴展名保存它,甚至沒有擴展名。
在您的應用程序中,只需將其作為普通圖像文件讀取即可。
在名為“.nomedia”的圖像存儲文件夾中創建一個空文件<-注意初始點。 此文件夾內的所有媒體文件都不會顯示在畫廊瀏覽器中。
使用自定義擴展名重命名這些文件,例如 filename.extension.customextension
像 hello.avi.topsecret。
當您需要文件准備好模式播放時,將其重命名為正確的擴展名,播放並重命名。
這應該對你有用。
要么
使用點“.”作為文件夾名稱的前綴。
查看這些鏈接以獲取更多信息:
http://www.makeuseof.com/tag/hide-private-picture-folders-gallery-android/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.