I am making an alarm app using androids SDK and Java in eclipse.
I have a method that is called when the alarm goes off. This method is called even when the app is closed or the phone is locked. I want this method to unlock the phone even if its password protected(is this possible?). Then when the phone is unlocked (by the method if possible) (or the user if not) i want the app to be automatically started?
Is there any thing that would do this?
I do have experience in android but i am not an expert, so i would really appreciate everything explained to my beginner level. Some sample code would really help me, and would be totally appreciated.
Thanks, Jack
The answer to this question of course depends on which version of android you wish to target, the following is an untested way that should work on API level 5 (android 2.0) and up if called from within an activity (or called on an activity):
getWindowManager().updateViewLayout(this.getCurrentFocus(), new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_APPLICATION, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON));
This code causes the current view of the activity to be displayed over the lock screen by updating the view to use the SHOW_WHEN_LOCKED and KEEP_SCREEN_ON flags.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm looking for a reliable way to let the Android user show a web site on the lock screen.
This could be done in principle in 3 ways:
Showing it on the native Android lock screen, but then they should be able to remove the native clock because my site is a world clock (you can see it at intelnav.50webs.com/world_time.html if you're interested). For all I know this can't be done.
Using a 3rd party custom lock screen that allows this. Unfortunately I couldn't find a good one, and I did some searching.
Writing a custom lock screen myself.
There are some suggestions and even sample projects for doing this, even some questions here on StackOverflow. But I'm not sure how reliable they are. There is no standard way of doing it, from what I found, since lock screen widgets were removed. But the proposed ways of building custom lock screens don't seem very reliable to me, from what I could judge from the comments I could find. So, one of my questions (sorry but the problem is somewhat complex), does anybody know of a sample project for a custom lock screen that actually has an app built by it and offered on Google Play and which actually works well on a wide range of devices ?
Could anybody help me with a suggestion for a reliable way to do what I want? Along the lines above?
Looks like I'm going to answer my own question. I'm not sure how many will be interested but you can never know.
Update sep 18: Now there is a short answer that wasn't available a year ago when I first answered it. Namely, my own WebLock app:
https://play.google.com/store/apps/details?id=com.simionescu.vlad.weblock
Below is my original answer that gives a general idea of how this can be done programmatically.
So I went into digging and looks like it can be done. It wasn't even as difficult as I feared it would be, though I wouldn't say it was very easy either.
The main points are as follows:
I wrote an app that basically puts the site on the native Android lock screen. (Actually, I already had an app and I added this functionality to it, but that's less important. The main thing is that my method requires writing an app.)
So I guess this falls somewhere between the cases 1 and 3 above. I do need an app, but it's not a full-fledged custom lock screen, as detailed below.
This of course means that the method is more general, it works with any app, not just for displaying a site.
Set FLAG_SHOW_WHEN_LOCKED for the Activity window, as shown for instance here:
How to make our own lock screen in android instead of default lock screen
But I only used this flag, the other 3 mentioned in the link I didn't need.
Launch the Activity (if it's not running already) and set it on top before the device screen goes off, that is on receipt of the ACTION_SCREEN_OFF event. This way, the app is always visible when the screen goes off so next time it starts, Android will put it in front of the lock screen. (At least if it's the standard one; from the documentation it looks like it should be working with a custom lock screen too but I didn't test it. I guess it depends on how that custom lock screen is written. Anyway, I don't necessarily want my site on a custom lock screen, if the user has one he probably won't want to see my site in front of it).
This also means that the site will appear in front if the device is switched off then on, even if it's not locked. Which is what I intended.
Automatically start the app at startup via the BOOT_COMPLETED event
Capture the standard back key (which is allowed, unlike for the home key) and make it act like the home key when it would otherwise terminate the app.
I intentionally let the home key act normally. This of course means that after pressing it (which is the way the user exits the app and enters the device) the lock screen underneath is shown. Otherwise I would have had to deal myself with password-protecting the device, which is in no way something I want to do. There are a few drawbacks with this approach but IMO they're small. For simplicity's sake I chose to do it like this.
Besides, this way my app remains reliable, which it wouldn't have if I had hijacked the home key, no matter which way.
As said, this means that this is no full-fledged custom lock screen, just a way of putting the site over the default lock screen.
(update nov. 18) There's one more important point. As described so far, such an app could have a security issue. I'm not an expert so I'm not sure if it really does, and if so how important it is, but you can never be too safe. If the user can go unchecked to any site, when on the lock screen, it means that if the phone is lost and a bad guy finds it, he could go to a site that has dangerous code that could unlock the device. I'm not sure if it really could be done but I wouldn't be surprised. So, one good advice for anybody who writes such an app would be to severely (but reasonably) restrict Web navigation while on the lock screen.
These are the main points, there are a few other implementation details but I'll leave them out for the moment.
All this looks pretty standard and reliable to me, given that it's all in the official Android documentation.
I tested it on my KitKat device, plus on 2 emulators, one also with KitKat on it, the other one with the latest and greatest. Everything seems to work fine. Including the case when the device / emulator is password protected.
So I just wrote the app and published it on Google play. It's here:
https://play.google.com/store/apps/details?id=com.a50webs.intelnav.worldtime
Which means that now there is at least an app on Google Play which has this feature. It remains to be seen how well it will behave. I'll probably have to make minor corrections in the coming weeks, but other than that it should be fine.
Also in the coming weeks, maybe a month or so, I plan to put another app that will do this generally with any site, at the user's request.
(update nov. 18) I finally wrote the app and put it on Google play. It took a little longer than planned but it's ready. It's here:
https://play.google.com/store/apps/details?id=com.simionescu.vlad.weblock&hl=en
As noted above, when on the lock screen, navigation is restricted to the same domain, so that if a bad guy finds the phone he cannot go to some malware site and unlock it.
I've made an app that has the unlock formatting that I want, but I don't know how to make it so that I can select that as the device security screen lock, or even if it is possible.
At the minute I have it so that when the phone is unlocked, the unlock app starts - however there is always a slight delay, and the app toolbar is visible at the top for a short period of time.
I've looked around for a very long time and not been able to find any resources on this other than with what I've already done, any help would be greatly appreciated.
(If it helps, the device I'm developing for is using Android 6.0.1)
Are you talking about a custom screen lock?
This may help.
https://github.com/Joisar/LockScreenApp
Okay in the LockScreenApp Activity class
every method call in the onAttachedWindow method needs to be moved to the onCreate method
I have a problem that I don't really know how to solve and also the threads here at SO haven't fully helped me.
Here's the issue: I want to have an android app that I can start whenever I want, and then, when I click on a button, I want the app to be somewhat "locked". By that I mean: after this button was pressed, the user is not able to close(see edit below) the app. Also, the app should immediately start after rebooting the device.
This lock can then be revoked by, say, entering a passcode, which makes the app run normally again.
So far I understand how to build kiosk applications. However, a kiosk application needs a particular manifest which will make it always a kiosk app, and not "on demand".
I'd greatly appreciate any hints and tips on this topic. Thank you so much!
EDIT: by "close" I really only mean completely turning the app off, not only going back to your home screen. Such that the app is always running in the background
You can programmatically lock and unlock the App in Android 5.0 http://developer.android.com/about/versions/android-5.0.html#ScreenPinning
Is it possible like in topic, I mean start camera intent and before opening that view set screen not to see rotating screen effectc? I was trying to use overridePendingTransition after startingActivityForResult, I tried also to put this overriDePendingTransition while calling onPause and OnResume. Somehow camera uses own animation. I would like to disable that animation. Is is possible? This effect doesn't affect in android 2.3.x. Does it might have connection with touchWiz?
TL:DR
As of KitKat 4.4.2 this still does not seem possible. Tested with AOSP phone app, Nexus 5 experience Phone App, Maps, AOSP Browser and Chrome.
(I would have put this in a comment, not enough rep yet. It's still an answer per-say, though not a solution to the problem)
Only thing I can say about why it's not possible is:
If you could force a transaction on the "external" intent through
your own app code, you would be basically injecting your animation
into another publisher's app, which would be a MAJOR design flaw
in the Android framework.
My guess is this will never be possible unless the OS manages such transactions in a bullet-proof way to both ends. Some AOSP branded-builds and custom Launchers can change default animations for ALL activity starts/resumes though (or even use no animations at all).
I know this question is ask number of times but wait i am asking something different.
I follow this post and able to take screen shot. but is it possible to take screen shot when my application is closed.
Supposed i set timer like after 1 hour and i close my app. Then exactly after 1 hour device need to take a screen shot whatever on a screen.
Is this possible with Background Services?
I already follow code and also did some research but is this possible?
Is it necessary to root device to take screenshot.
Please give me any hint or reference.
Thanks in advance.
Try using : call the methods in this library from service.
http://code.google.com/p/android-screenshot-library/
Android Screenshot Library (ASL) enables to programmatically capture screenshots from Android devices without requirement of having root access privileges. Instead, ASL utilizes a native service running in the background, started via the Android Debug Bridge (ADB) once per device boot.
DeveloperGuide
UPDATE:
The method mentioned in your reference will not work in that case, as it reads the view that are drawn and in application context. where as if application is closed then you cant get that context.( at-least on non rooted phone).
On rooted device you can read complete frame-buffer so no need to worry about the application context.
I did tried to use the ASL once and it worked out good for me.