Need Help starting activity using broadcast reciever - android-activity

I am working on a senior project in pubnub android api. The example application works with toasting when a message is received. However,I want to start another activity when a message is received. Basically, It is a home alarm system where the message comes from raspberry pi. Upon receiving the message, a new activity should display where the user can enter a pin code that was used to lock the system to be able to stop the alarm. Everything works as desired only when the application is running. I can't get the new activity to show when the application is not running, even if it receives a message. How can I achieve that? I am starting the alarm activity in a runOnUiThread() then set startAlarm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|
Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP) as suggested in this post: Start Activity from a Broadcast Receiver. This does not work for me.

I would suggest you to use Google cloud messaging (as a push notification service).
When the event happens in the Raspberry you can send a message to the android device using GCM. The messaging approach is better than creating a periodic task in order to check if there are new messages.
In order to implement GCM on the android device take a look at this link:
https://developer.android.com/google/gcm/client.html
In the example they create a notification in the notification bar, but you can start a new activity instead of creating a notification. In this link you can find how to start a new activity:
http://developer.android.com/training/basics/firstapp/starting-activity.html
On the raspberry side the easiest way for sending the message to the device might be using just curl:
curl -X POST \
-H "Authorization: key= YOUR_AUTHORIZATION_KEY" \
-H "Content-Type: application/json" \
-d '{
"registration_ids": [
"YOUR_DEVICE_TOKEN"
],
"data": {
"message": "YOUR_MESSAGE"
}
}' \
https://android.googleapis.com/gcm/send

Related

I try to use laravel echo in an application in flutter, I send message to message event , but it does not appear in the project. What is the solution?

I try to use laravel echo so I apply it I am supposed to work
knowing that I try to send a massdge to the internet it appears in blade that it is working but the application does not deliver anything what should I do to play it on the app?
https://www.mediafire.com/view/db9ozz8i7gpzqll/d.jpg/file

Flutter - How can I create an Incoming Call Notification?

I'm building an app that allows users to call eachother using the agora_rtc_engine.
I'm currently stuck trying to implement a notification system that will alert users when they receive a call.
I'm using Firebase Messaging for notifications.
I have the following questions:
How would I go about replacing the default notification card with a custom one that has buttons for answering or declining the call?
How can I specify the amount of time the notification stays on screen? An incoming call rings for about 30 seconds before closing, so I would like my notification card to appear on screen for that period of time.
I've been looking at the flutter_local_notifications, but they don't have a "incoming call" notification style.
Any piece of information is highly appreciated. Thank you!
I suggest you trying to use Firebase Cloud Messaging.
Check out the "Setting the lifespan of a message" section of the official documentation:
https://firebase.google.com/docs/cloud-messaging/concept-options#ttl
There you will find an example of a cloud message with time_to_live parameter - it determines how long will the notification be active on the recipient's device.
Here is an example of a request that includes TTL (taken from the official documentation):
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data":{
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
},
"apns":{
"headers":{
"apns-expiration":"1604750400"
}
},
"android":{
"ttl":"4500s"
},
"webpush":{
"headers":{
"TTL":"4500"
}
}
}
}
some time has passed since asking the question, that project went into hibernation but I’ve started another which also includes calling functionality. This time though I made it work.
How? Using a combination of packages:
agora: for the actual communication part - audio and video
flutter_callkit_incoming: this one helps with showing the call notifications on Android and iOS
a custom implementation of PushKit: I don’t have extensive documentation available for this one, but on iOS, to wake the device up form sleep when a notification is received, you can’t always rely on classic notifications (that come from firebase in my case). so instead, I generated a pushkit token for the user and modified the cloud function so that if a pushkit token exists, I’ll use the pushkit notification channel instead of firebase messaging channel. You can find more info in the pushkit documentation of flutter_callkit_incoming.
Hope this helps, good luck!

I can't send a Facebook game request using Graph API v2.8

I've spent a lot of time trying to send a game request from the (latest) JS API, using the Graph API v2.8, but nothing seems to work.
I've used only common OG, since custom OG are deprecated. When I use "turn" instead of "send" as the action type, my request works, since the "turn" requests don't require an object id, so I guess the problem comes from my OG.
I first created an action like this:
curl -X POST \
-F "access_token=*a user access token*" \
-F "game=*my game id*" \
https://graph.facebook.com/v2.8/me/games.plays
And then sent a game request using it the returned id in the "object_id" field. And this is the result I got:
Facebook response after calling FB.ui
Which doesn't provide any information...
So I tried to make a game object instead of an action. I figured "maybe you can't use actions in this context", and since game.achievement is the ONLY game object available, I made an achievement object, like this:
curl -X POST \
-F "access_token=*my app access token*" \
-F "object={\"fb:app_id\":\"*my app id*\",\"og:type\":\"game.achievement\",\"og:url\":\"*object's URL*\",\"og:title\":\"*A title*\",\"og:description\":\"*A description*\",\"og:image\":\"*A link to an image*\",\"game:points\":\"1\"}" \
https://graph.facebook.com/v2.8/app/objects/game.achievement
This is the result that I got:
Facebook response after calling FB.ui
Which makes no sense, because the object was created using an app access token, and that my app IS a game. So this statement makes no sense.
And now, I'm lost. I have no solution left, no new idea to try. I don't know what to do... The documentation is obviously missing information. They didn't even bother making a documentation for the games.plays action...
I need someone who knows how to use this damned API to help me figure this out, because right now, I'm just completely stuck.
Thanks in advance, community.

How to simulate your chat bot is "writing" a response using the Facebook Messenger API?

I've seen some chat bots released during the F8 conference that display the three point "writing" bubble before answering. Haven't found any documentation as to how to reproduce that behavior in my chat bot, is it a special payload or some kind of configuration or special message that must be sent?
Right with the help of THIS method sendTyping
This is what the doc says
Sends the user an indication that the bot is typing. For long running
operations this should be called every few seconds.
It is when you have Button Template and someone click on "button" for "postback" (documentation in section "button teplate").
Then during your parsing of message a sending answer, it is shown like "writing".
This can be done using the sender actions fields in the api (documentation here).
E.g.
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"USER_ID"
},
"sender_action":"typing_on"
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"
Will start the 3 dots animation. This automatically stops after 20s or after the "typing_off" sender action.

Parse REST API - Push Notification with Custom Data (and where query)?

I've been using Parse REST API for push notifications to targeted users (using "where"), it works well . I am now trying to add a custom data field so the devices can handle a tapped notification (i.e. redirect to specific object id etc). From what I have read, I should add the custom properties in the data json node, at the same level as alert, like the documented example below. But every time I make the request I get a 400 Bad Request. But, when I use the Parse.com web console with json: { "alert":"Notification Message","CustomObjectId":"12345" } ... it works - I see the CustomObjectId in the push notification (on the parse.com push tab).
Why is my REST API request failing, but the seemingly same request on the Parse.com website console is working? What am I missing?
My Parse REST Request:
{"where":{"UserId":"MyUserId"},"data":{"alert":"Notification Message","CustomObjectId":"12345"}}
Example from documentation (note this is using channels, not a where though) https://parse.com/docs/rest/guide/#push-notifications :
{
"channels": [
"Indians"
],
"data": {
"action": "com.example.UPDATE_STATUS",
"alert": "Ricky Vaughn was injured during the game last night!",
"name": "Vaughn",
"newsItem": "Man bites dog"
}
}
Thank you for the help,
Tim
For anyone else running into this, make sure you have "REST push enabled?" set to true in your Parse settings on the website. It's defaulted to false. Parse seems to allow 5 or so requests through per day with "REST push enabled" set to false. So after you wire this up, you may think you've successfully integrated with Parse, but then you start getting 400 Bad Request errors. This would lead many to think the issue is with their code possibly malforming requests or missing required parameters, not an authorization level issue like "REST push enabled" is not allowed.