-3

I am making an application in which user downloads the image from server, and that image is opened in the default gallery.

Now due to security reasons, when my app goes into a paused state or destroy state, the path or folder where I have downloaded the files need to be deleted.

The code for it works fine, but the problem occurs when the user opens the image in the gallery, and while viewing if he/she pressed the home button, the folder or file is not being deleted.

So is there any way that I can disable or capture the home click event when the user views the file in gallery or any other any apps (office apps to view docs and excel files)?

user5071535
  • 1,312
  • 8
  • 25
  • 42
Anuj
  • 367
  • 2
  • 6
  • 18
  • 1
    "I am making a application in which user downloads the image from server and that image is opened in the default gallery.Now due to security reasons when my app goes in paused state or destroy state the path or folder where i have downloaded the files need to be deleted." -- these statements contradict each other. Your app will be paused when the user visits "the default gallery", and if you delete those images then, the user cannot view those images anymore. Perhaps you should implement the image viewing in your own app and keep the images on internal storage. – CommonsWare Jan 16 '15 at 13:15
  • See http://stackoverflow.com/questions/8881951/detect-home-button-press-in-android – barq Jan 16 '15 at 13:16
  • Yes i know sir so i haved checked the condition on paused state so as when to delete and when not. – Anuj Jan 16 '15 at 13:17

1 Answers1

0

Override below method in your activity.

 @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);           
    }

After overriding above method, now you can easily listen HOME Key press in your activity using onKeyDown() method.

  @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {     

        if(keyCode == KeyEvent.KEYCODE_HOME)
        {
           //The Code Want to Perform. 
        }
    });

try this hope it helps

Anjali
  • 1
  • 1
  • 13
  • 20