Android create notification automatically - java

I want to create a notification in my app , when data downloaded from API changes.
Example:
I want to create a notification when a Twitch streamer start
streaming.
I want to create a notification when a Twitter user posts a new
tweet.
I want to create a notification when a YouTube user uploads a new
video.
How can I do this? Periodically download data and check changes? How do I create this task if the application is destroyed or the device is restarted? How do I do it so I do not discharge the device's battery too much?
I know how to download data and how create a notification, but I don't now how to create the described task.

the best practice here is using push notification.
all you have to do is registering you app with one of the well known providers of the service like FireBase Cloud Messaging and then configure your app's server to send notifications to the Cloud Messaging service which will handle the delivering of your notification
and you won't have to worry about battery usage because they use google play services to keep a connection open and they even display the notification themselves.
they provide many other features you can use and they are optimized in the best possible way.
you don't have to reinvent the wheel

Related

How to send a chat message to microsoft teams user from an external system upon event?

I need help with Microsoft teams integration. I have an system from which I want to send chat message to a particular user in MS teams upon an event in my system. How do I go about implementing this. The teams graph api documentation is not looking clear to me. Like it has body but no head and tail. I'm confused on where to start for this. I understand I need to use Graph API's create/send chat api to send messages but it says I need to configure a delegate user for this? How do I send messages on behalf of a external system? Can I can use Teams Java sdk based application? Or I need to create a bot? But I think it's for one-2-one conversation is it? I only want to send a one way message from external system to user. Someone with experience in this pls help me on a good approach for this.
All I want is to send chat message from external system to a user in teams.
You cannot use Graph API in this scenario if you want it on behalf of External system. The API is only available when you are having delegated permission.
Other option would be to create a Notification only bot. In this case please keep in mind that the bot needs to be installed in Teams of user you want to send notification. You can use this graph API to install bot in user's Teams- Install app for User.
Once it is installed you need to have user's Conversation.Id and ServiceUrl (maybe store it in database for all users). When you are done with everything you can send Proactive messages.

How to send downtime message from services to use it in mobile app

I am developing services/api's which are being used in mobile application. Mobile app calling those services and binding the data.
I want to write services in a way so that if donwtime/maintenance is going on mobile app should bind to a particular screen.
How can I develop this structure across the services, How can I do that?
Maybe you can create an API which can provide details like if service is up or not.
On launch of your mobile app, in loading screen or splash screen, you can check if your service is up or not!
Based on the the response, you can show respective screen on mobile.
If your new service also not responding, you can set timeout on mobile app to show generic error!

Send requests to Google Assistant from Java

We have developed a Google Action with Dialogflow that responds to personalized requests from users and performs some tasks that require a certain amount of time, usually several minutes.
Our goal is to announce the result of the tasks using the "Broadcast" feature of Google Assistant, but we can't find a way to send the command to Google Assistant.
Our agent receives the user's request and launches a Java application that executes the task, so it is the Java application that must communicate with Google Assistant when the process is finished.
From the Java application we can communicate with the agent using Dialogflow RPC API, but not with Google Assistant.
Is there any way to send the request to Google Assistant from the Java app? or... since we can communicate with our Google Action Agent... how could we send the request through the agent?
In other words, could the agent communicate with google assistant to use any of its features, for example, "Broadcast ..."?
We have checked Google Assistant SDK as alternative, but we are confused about it.
Please, excuse me for my bad English.
Any help would be appreciated. Thanks!
The "Broadcast" feature is not available to user-developed Actions, and probably not a good scheme to use in any event - if users will need to wait for a while for an answer, they probably don't want the answer suddenly announced when they're not expecting it.
Actions are typically meant to be conversational, rather than taking a while to reply with the answer, which is why there is a 5 second limit on how long the fulfillment has to do processing. If you do need to take a while, you have a few options available to you:
First is that you can use some other method outside of the Assistant to deliver the answer - possibly using something like Firebase Cloud Messaging or sending email to the user.
Similarly, you might be able to use notifications. In this scenario, your Java program would send a notification through the Assistant to the user when the information is available and store the result. The user can then activate the notification to continue the conversation and get the result. This has the advantage that the answer isn't just blurted out, possibly when the user isn't ready for it, but does have a downside that speakers don't (yet) support notifications.
You can also look into using a Media Response to set up a way for you to poll for new messages periodically. Under this scheme, you would fire off the Java program which would get the result and then store this in a way your fulfillment server can access. In your reply to the user saying you're working on the results, you would include a Media Response for some audio that plays for, say, 15 seconds. When the audio finishes, your Action will be called again and you can check to see if the result is available. If so, you send the result and continue or end the conversation. Otherwise, just send a Media Response.

How to trigger wifi state change using a background service in android?

I have an application where I want to upload some data as soon as the wifi is turned-on even if the application is not running. I think this can be done using android background services. Please help me uploading the data using background services when the app is not running or suggest me some other way to achieve this.
Thanks in advance!!
To be more eloborate, implement following
Create a Started service (service which is started using startService() instead of bindService().
Implement onStartCommand() callback of this service. In this callback method check if there is any data to be uploaded (if this data is created by an activity, it is wise to use a DB table to queue the data to be uploaded and service picks up data from that DB). Check WIFI connectivity and if available upload the data.
Now you need to trigger this service whenever WIFI is available. Here you 2 ways to imeplemnt
Method 1 : register in your application manifest file to be notified of WIFI connectivity changes refer this link . registered broadcast receiver would be called when WIFI state changes. from the broadcast receiver start your service if WIFI is available
Method 2 : using AlarmManager launch you service periodically (say every 10 minutes). refer this link. This method would be beneficial if data to be uploaded gets generated once in a while.
Hope this is helpful. Let me know if you have any questions.
You must use an unbounded service, who is completely independent for the activity (for more details check this ). After starting service monitor your internet connection using ConnectivityManager. Use this like example. Have Fun.

Google Cloud Messaging single request

I've been searching over the web but I can't seem to find some straight answer.
I've got an application developed and now I need to add it notifications. My issue is that I need each device to be unique and send each one of them a different notification. (I don't mean ONE UNIQUE notification) but I mean to send some users a notification and others don't.
How can this be done?
As a part of the GCM infrastructure, you will need to have your own web application that will allow individual instances of your app to register. When this happens, your Android application will pass to the web application a registration ID along with any additional information that you can use to identify the device. Once you have this information stored, you can pick and choose which device should receive your notification.
See: Architectural Overview section in the http://developer.android.com/google/gcm/gcm.html

Categories

Resources