android


saving a picture in a place where the gallery will not be able to access it


how to put a picture in the internal memory of the app?
this was my question , it involved putting a picture in the app, I want to be more specific.
What I needed was that the Gallery wouldn't be able to let me view the picture after it has been saved on the device
here is the code:
public class Add_Comment_Picture extends AppCompatActivity {
static final int CAM_REQUEST = 1;
ImageView imageView;
ImageButton button;
private static final int REQUEST_CODE = 1;
String mCurrentPhotoPath;
static final int REQUEST_TAKE_PHOTO = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add__comment__picture);
// ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
button = (ImageButton) findViewById(R.id.imageButtonCamera);
imageView = (ImageView) findViewById(R.id.imageView);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = getFile();
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(camera_intent, CAM_REQUEST);
}
});
}
private String createFileName(){
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
return "JPEG_" + timeStamp + "_.jpg";
}
#Override
protected void onStart() {
super.onStart();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int hasWritePermission = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
int hasReadPermission = checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
int hasCameraPermission = checkSelfPermission(Manifest.permission.CAMERA);
List<String> permissions = new ArrayList<String>();
if (hasWritePermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (hasReadPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
}
if (hasCameraPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.CAMERA);
}
if (!permissions.isEmpty()) {
requestPermissions(permissions.toArray(new String[permissions.size()]), 111);
}
}
}
private File getFile()
{
//File folder = new File("sdcard/camera_app");
File folder = new File("sdcard/data/data/com.yuvaleliav1gmail.foodchain/photos");
if (!folder.exists())
{
folder.mkdir();
}
mCurrentPhotoPath = createFileName();
File image_file = new File(folder,mCurrentPhotoPath);
mCurrentPhotoPath = "sdcard/data/data/com.yuvaleliav1gmail.foodchain/photos/" + mCurrentPhotoPath;
return image_file;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// String path = mCurrentPhotoPath;
imageView.setImageDrawable(Drawable.createFromPath(mCurrentPhotoPath));
super.onActivityResult(requestCode, resultCode, data);
}
#Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case 111: {
for (int i = 0; i < permissions.length; i++) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
System.out.println("Permissions --> " + "Permission Granted: " + permissions[i]);
} else if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
System.out.println("Permissions --> " + "Permission Denied: " + permissions[i]);
}
}
}
break;
default: {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
}
You have two options:
Place the file in a folder with a dot at the beginning, for example .myimages
create an empty file called .nomedia inside the folder with the picture
Simply create a folder with a name that starts with a dot, for example: AppName/.Images. Now save the image into that folder, gallery wont have access to the images in the folder AppName/.Images.

Related Links

Handing static variables in android
Custom ListView confusion with Fragments
Does explicit requestfocus call needs a explicit clearfocus call for that view?
Random outputing unintended images
AutoSize Text in Homescreen Widget
How to start skype with Android browser
How open an other activity apps with my application?
Adobe Native Extension Android layout xml not accessible
open source image filter library like Instagram? [closed]
OnItemClickListener With OnItemLongClickListener
How get a text after close dialog
PhoneGap Build for windows phone and other platforms
Swipe tabs below ActionBar with based on Fragments
Linux Kernel wait_for_completion_timeout not wakeup by complete
Viewing a PDF file in Android
How does the OnTouch event behave?

Categories

HOME
shell
asp.net-web-api
beautifulsoup
search
paraview
case
3d
socket.io
knitr
gradient
nsbundle
alsa
cq5
babeljs
tvos
data-visualization
mql5
google-schemas
redis-sentinel
angular-dart
feathersjs
vuejs
swagger-2.0
charles
babel
visual-studio-extensions
php-mysqlidb
qliksense
short-url
google-api-client
ckfinder
interbase
appirater
openmdao
finagle
mustache
mockjax
testbed
memory-address
spring-security4
android-sugarorm
getpixel
fossil
imx6
lubridate
xcode7.3
plr
chronicle-map
openal
magic-draw
wpas
skin
flac
trigger.io
ampps
rmongo
flex-monkey
myspace
i386
ng-grid
respondcms
uiactionsheet
beanstalk
iokit
jdi
django-urls
amiga
node-serialport
jquery-forms-plugin
android-broadcast
user-permissions
appserver
tweenlite
grails-domain-class
live555
malformedurlexception
tinyxml
gae-quotas
multiautocompletetextview
multitasking
visual-studio-express
observium
diem
video-codecs
device-width
jquery-blockui
vfs
kqueue
virtualpathprovider
collectionviewsource
objective-j
uideviceorientation
updatesourcetrigger
drupal-fivestar
message-passing
zen
echo3
silverlight-oob
online-storage
leader

Resources

Encrypt Message