I habe a app for event informations an app which sends pushmessages. Now I want to give the user the option to disable the messages for a specific time (one hour, one day ...). I know how to dissable it compleatly, but how I can set it like I want (one hour...) even if the app is closed?
Well, the simple solution would be to check if there is a time restriction is present in the same place where you notify user for event information. If there is a time restriction dont show the notification else show it
Related
I am currently developing an app that used for write some document and send them to a database. Issue is app need to get date and time automatically when form created and users can modify system date & time.
First, I search for solution on the internet, then one of the solutions is using a service that return time and later on count that time, so time can not be modified by user. This solution will not for this app because users can be in a place that do not have cell reception or internet access, so app need to work without internet access as long as sending data to remote database via internet.(date of form must be the time when form created)
Second idea is about network-provided time and time zone. If user want to change, he or she must disable those setting then modify time. I think when user want to write a form, app will check whether it is on or off. If it is of app will show an alert dialog which force them to activate those settings.
So I tested, I turned off wifi and cellular, turned off those setting, modified time and waited for a couple minutes. Then I turned on those setting and system showed correct time.
Also, after system corrected its date and time without network connection when I activated network-provided time and time zone setting, It made me think maybe app can get date from a place that user can not modify, yet I could not find information about this.
So I am looking for reliable method, and open for new ideas. If there was not I will implement second method.
Thank all of you who spared their time and read this.
And Second solustion will look like this:
private boolean isTimeZoneAutomatic(Context c) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return Settings.Global.getInt(c.getContentResolver(), Settings.Global.AUTO_TIME_ZONE, 0) == 1;
} else {
return android.provider.Settings.System.getInt(c.getContentResolver(), Settings.System.AUTO_TIME_ZONE, 0) == 1;
}
}
Do you have any suggestion?
some one suggested this but i am not able to implement it can any one can help me by providing the desired code in kotlin..
Another solution can be to call
UsageStatsManager.queryEvents
with the start of the day as first parameter and the current time as end parameter and then filter the results to check just the
UsageEvents.Event.SCREEN_INTERACTIVE UsageEvents.Event.SCREEN_NON_INTERACTIVE
events
take the timestamp of each of them and sum all the time passed between each
SCREEN_INTERACTIVE -> SCREEN_NON_INTERACTIVE
events, this would easily show how much time the screen was interactive, so screen on and the touch enabled.
There is a possibility that you'll have a SCREEN_INTERACTIVE event that doesn't have any related SCREEN_NON_INTERACTIVE, this is when the
UsageEvents.Event.DEVICE_SHUTDOWN
event happen, luckily this event is in the same list returned by the queryEvents method
remember also to declare and make the user to allow the android.permission.PACKAGE_USAGE_STATS permission as stated here
ps. i haven't used this yet but looking at the documentation it's the right thing to use, probably the one used by the android settings pps. look also to the other events in the same package, they might be helpful to what you want to accomplish
I hope this makes a bit sense, basically, I have this feature in my app for tracking calories which consists of having this page that only appears the first time you use the feature and it asks you to add personal details (so it can make the right calculations), after that you get faced with a simple page that tracks your nutrition with a button for the user to insert the meals he has eaten, this page has to save the inserted data (via firebase) and then restart from 0 each and every day.
my first problem is I don't know how I make the page that only appears one time to save personal data(to be more precise I don't know how to make only appears the first time). and the second problem is how do I make the app automatically sends the given data at the end of each day?
interface in normal state, interface when adding the meals
hopefully, this 2 images will help you get a better grasp of what am trying to explain
don't worry am not looking for someone to straight up solve it all for me, I just need some orientation about what type of things/functions I need to do to solve these 2 problems
While #Narendra_Nath's answer might work, please note that is not a bulletproof solution. Why? Because a SharedPreferences doesn't persist across app uninstalls. This means that your user can install and uninstall the app and see the page as much as they want. So if you indeed want a user to see a screen only once, then you should consider storing that data in a database. Please note that SQLite isn't also a solution because when a user uninstalls the app, everything that is stored locally is wiped out. So what's the solution?
The best way to solve this would be to store the data in the cloud, either in Cloud Firestore or in the Realtime Database. So you can set a boolean variable and always check against it.
If you however intend to implement Firebase Authentication, then another solution would be to display the screen when your users are authenticated for the first time. So even if they will try to sign in on another device, install and uninstall the app, they won't be able to see the screen again.
Regarding the second problem, you should consider using Cloud Function for Firebase. It's the most elegant solution. If you want to somehow schedule an operation, then you should consider using Cloud Scheduler, as explained in my answer in the following post:
Is it not possible to have a code in the background who will be called every 24h?
Make the page that only appears one-time -> store a value in the shared preferences "isInfoShownToUser -> false" then do a check when the app starts to check if this value is false or true. If it is false show the "take the info" page .. then turn the value to false in the shared preferences.
How do I make the app automatically send data -> Use a Workmanager implementation to send data to the server (Firebase) at a particular time ..
Or use a implementation like the first one which uploads the data to the server just once everyday
I am working on an audio stream android app and I parsed JSON object from a server to a TextView to display 'now Playing' for the song name and artist. So when the play button is clicked, the song name playing artist is displayed to the user. The problem is that I want this automatically loaded to the app view when JSON URL link is updated from the server. I don't want the user pressing pause and play to update the view from the app. How do I go about this because I don't want the user restarting the service each time a new song isPlaying to get song information.
You can either poll server in short intervals to check if song changed or open socket connection to server to make possible server initiating communication to device.
First approach in simplest form is a very bad practice, as it puts strain on both device and server to check it often enough.
However there is different way to use it, called long polling. With this, you send request to the server, and server does not respond immediately, but holds connection open until it has something to say. After getting reply instantaneously new request is created to make sure no delay is made by it.
The best approach is opening a socket connection, but not every server and program support it.
You can try libraries like SignalR (this one is for .NET mostly, but it's the first one that came to my mind) that choose which approach is the best and takes care of holding connection, reconnecting etc.
Are you fetching this JSON metadata every time the song is played? If so, that doesn't sound like a good idea. The ideal would be to add song metadata when adding a song to the playlist, then either update it periodically (once a couple of days perhaps) and save that information into a SQLite database for later retrieval.
Need a little help - this is doing my head in!
I'm the Dev of ReadItToMe, an app that reads out your messages and lets you reply by voice.
The issue I've been facing and hacking around the last year has been duplicate notifications. I'll use WhatsApp as an example.
If I get a single WhatsApp notification, happy days, it's one notification. If I get another from a different chat.. I get one group notification, the previous unread chat notification with a new post time so you can't check if it's from the past and then the new notification.
Solutions I've tried:
Keeping a list of notifications read by creating a hash code of notifications using their title, message and package name when they arrive and then removing them from the list when their dismissed (onNotificationRemoved).. But whatdya know! In the above scenario all notifications are removed and then resent so this solution is useless.
Comparing timestamps, which doesn't work as the duplicate notifications have new timestamps
Comparing keys/ids, these never change for a chat so they're not unique to a single notification of a message
Many others I've forgotten
Checking if the notification is a group to at least ignore that, doesn't work because the first notification is always a group. It's only when there's multiple notifications that the "group" is actually a group with content like "2 new messages".
Does anyone know of any way or can think of any creative solution to accurately determine (80% accuracy would do) which notifications are genuinely new and which have been previously posted?
Or is this just fundamentally broken on Android...
I had the same problem, I fixed it on this way, you can to use the "when" attribute combined with the saved-way using when:
public void onNotificationPosted(StatusBarNotification sbn) {
if (System.currentTimeMillis() - sbn.getNotification().when > 3000 ||
isInArray(sbn.getNotification().when)) {
//when != sbn.getPostTime()
//If notification is 3 seconds old, it is discarted
return;
} else {
//Else, push to the array of notifications "when-id" to compare next time
goNextPosition(sbn.getNotification().when);
}
... next part of code
}
long when
A timestamp related to this notification, in milliseconds since the epoch. Default value: Now. Choose a timestamp that will be most relevant to the user. For most finite events, this corresponds to the time the event happened (or will happen, in the case of events that have yet to occur but about which the user is being informed). Indefinite events should be timestamped according to when the activity began.
https://developer.android.com/reference/android/app/Notification.html#when
If someone has this problem, feel free to ask me, I'm sorry, I'm spanish native.
I have the same problem, duplicate push notification try this :
first : remove all duplicate application from your device, in my case i had 3 same application.
second : reinstall that application but try to change the package name, it's work for me. good luck