Get local time zone on Android without SIM - android

For my app functionality, I need to have a correct time set on a device. For example, I use AlarmManager to do some action at 7:00 AM. It's a tablet with Wi-Fi connection. Network-provided time works well, time & date can be set automatically over Wi-Fi, but time zone not. The device may appear in different time zones. How to solve this problem? Do I need to ask the user to set the proper time zone on the first launch of the app or it can be synced another way?

Related

How to set up reliable alarms while developing an application for Android Marshmallow or upper?

In the last year I have bought 4 different Android phones and all of them had got failures with the calendar notifications. Sometimes the notification for an event was shown and sometimes wasn't shown at all. I investigated a lot and found a problem in the "Calendar Storage" app, a Content Provider that is in the application framework layer. Notifications stop to be always shown as of the version 6.0.1. That's the reason why I want to develop my own calendar app that is not based on the Calendar Provider so that I can have reliable notifications again.
In the past, when we developed a reminder based app we used AlarmManager class and the method setExact() for make the application able to show a notification or anything else at a given date and time in the future. But in Marshmallow and upper it mustn't work because of the annoying doze mode.
They invented the method setExactAndAllowWhileIdle() in Marshmallow supposedly for setting alarms that can bypass the doze mode. But it says that it doesn't let you to put more than one alarm within 15 minutes. In a reminder based app that is a foolishness as the user MUST be able to put as many reminders as he wants and as close in the time line as he wants.
So my question is, how can I make my app to show reminder notifications at a given time in a way that always works regardless of the doze mode and so that I can have as many notifications as I want and as close in time as I want?
Thank you.
There's always the option of white listing your app so doze will still let it run the old way.
Another official way of making it work is sending an fcm notification, but you'd need a server to do the job.
Short from that I'm afraid the next official answer involves exact alarms.
If it's an option for you there is a chance you can start a service with STICKY. I'd expect the phone to never go into doze properly even if the service thread is blocked forever (it may help to assign it to a different process in the manifest so your ui never freezes). Putting a periodic old style Java timer to fire a callback at the right time may accomplish what you need.

Security of an Android application

I am developing an Android application and I am planning to release this build in “Open Beta” on the Google Play Store.
I want to implement the app security logic which can ensure that the beta build won't work after certain date dd/MM/YYYY.
Currently, I can think of two approaches for this logic:
Retrieve current date from the device (using Android code to retrieve system’s time)
Issue: User can change the device date to hack the security system
Use time server to check the current date

Issue: My application don’t need internet connection and hence it will be bad user experience if I am asking for internet connection at the start of the app
I have following questions:
What alternate approaches (other then checking dates) can be used to ensure that the app won’t work after date dd/MM/YYYY?
How can I detect that the user has changed device date manually?
Other approaches to find current date even if device is offline?
EDIT:
The beta build has all the premium features free and hence I don't want beta build to work after date dd/MM/YYYY.
NEW QUESTION:
I have implemented the code to check the real date using time server at the start of the application. What possible hacks can be done by users to access app after the date dd/MM/YYYY?
Thank you in advance.
Agreed you don't wish the device to be dependent on the internet. At some point however, the device will be online (A human will never leave his/her device offline since the installation of your app). At that point you check the time stamp and proceed from there. You could disable the app or perform any action. Many apps exhibit this behavior to run an action when and only when the net is connected.
Other than the net and device clock the only other final solution you have is to run a background timer from the moment the app is installed. Good luck
The new Permissions model includes "Internet" as default (you don't need to request it specifically anymore).
If you don't want to use internet you can use following idea. Get current timestamp when running application first time and save it preferences or in external storage. check current time stamp with saved timestamp every time user launches application. please check for negative values to prevent user setting previous dates.
You can check the date, and at the time that the date exceeds the deadline, you can save a variable in preferences, so that when you enter the application, even if they change the date, the application will detect that date been exceeded.

How to set time and date for power on/ power off of an Android device

I am developing an app that should power off nad on the device (an Android TV) at specified days of week, at a certain hour. Alarms work on time intervals; how do I set an absolute date and time for a certain action? Is it possible?

Unique timezone for each reminder

What i want to know is, is there any app in android which allows me to set a time of different time zone for a reminder. For example i need to get an alert at 2:00pm London time in my phone without changing my phone's time zone.

How to prevent user changing system date/time (in Android)?

I have googled, but I can find no advice to prevent user change system date/time in android.
We are developing an Enterprise Application, we would like to prevent the user of the device to be able to set time settings. In other words, we want to set a policy which defines, that user cant change date and time in android device.
Are there any recommendations to do this?
Thanks.
Here is a third alternative that should significantly save on battery life:
Register a BroadCast Receiver for when the time gets changed by the user. Then disable the app until the device time is checked against network-time or server-time.
Those Broadcast Receivers exist. I just checked now with this app called Internal Broadcast Monitor I just found on Google Play.
Here is the interesting part below where I changed both the time and the date:
And below is the part where I changed the time zone:
.
Since there is no policy support for this in the device administrator framework, you can't. File a feature request, it might get added in a next version.
I don't know of any way that you can change the default behavior of the device.
You can however prevent your application from running if the system time differs from the network time. Or you could use the network time in your app instead of system time.
The answer to this post explains how to access the network time.
How can I get the "network" time, (from the "Automatic" setting called "Use network-provided values"), NOT the time on the phone?
you can save current time to db when application start and check every 1 minutes if current time not equal to db time+60 set system time to db time+60.

Categories

Resources