Send Message Using GCM [closed] - android

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to know whether it is possible for sending a notification from one android mobile to android mobile via a local server?

You don't need a server.
Send: Your phone can perform a HTTP POST to Google's servers of some JSON describing the sender/registration ids (along with the message), which then passes the message to the target device(s). Details here: http://developer.android.com/google/gcm/c2dm.html
Note that that page describes migration from C2DM to GCM. What i'm suggesting here is the new GCM method. Base your JSON on the last example on that page:
Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{
"registration_id" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"data" : {
"Team" : "Portugal",
"Score" : "3",
"Player" : "Varela",
},
}
Receive: using Google's GCM system to receive via intents as described here: http://developer.android.com/google/gcm/client.html

I want to know whether it is possible for sending a message from one android mobile to another using GCM ?
Yes , it is possible.
Can android mobile act as server to post message via GCM?
No , You will need to use 3rd party server to communicate between two mobile phones.
Full information is available here.

Related

How do I send push notification on Android depending on the data from a REST API using Firebase? [closed]

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 5 years ago.
Improve this question
I have successfully setup Firebase and my Android app to work together. I can send notification from the Firebase console and receive perfectly. But, that's not what I want, I want to send notification depending on the data I receive from a REST API in JSON format(I'm using the USGS API). So I would like to notify my users when a major earthquake takes place. How do I achieve this? I'm pretty new to all this, it would be great if you could help me out.
Once you implement Firebase in your app, you will receive refreshedToken, you need to send this to your Web Server so it has the updated token.
And implement a your own section on web to send Push notification with help from following process
https://firebase.google.com/docs/cloud-messaging/admin/send-messages
You can achieve your goal using node.js script.
Just follow below instructions:
1. install fcm node
npm install fcm-node
paste below code & save file with name say "fcm_demo" with .js extension
var FCM = require('fcm-node');
var serverKey = 'YOURSERVERKEYHERE'; //put your server key here
var fcm = new FCM(serverKey);
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
to: 'registration_token',
data: { //you can send only notification or only data(or include both)
my_key: 'my value',
my_another_key: 'my another value'
}
};
fcm.send(message, function(err, response)
{
if (err)
{
console.log("Something has gone wrong!");
}
else
{
console.log("Successfully sent with response: ", response);
}
});
Few points to remember :-
You will get your server key from Firebase Console where you have registered your Project. (Just search there..).
You will get registration token from refreshedToken.
Before installing fcm-node, your machine must have pre-installed node.js and npm. If you don't have node.js and npm previously installed, first install those components & then install fcm-node.
As you want to send notification depending on the data you receive from a REST API in JSON format, just copy your JSON format in data section of above node.js script.
Run above script from terminal as
node fcm_demo.js
If everything goes well, you will receive your notification.
Thanks. ;)

How to check the delivery status of Firebase message sent to an Android application? [duplicate]

This question already has answers here:
Firebase notification records/log API
(2 answers)
Closed 4 years ago.
I am testing the Firebase JSON to check the delivery receipts of the notification sent to the news app. I can successfully send the message to the Android app without any issues and I receive the message on my Android app. However, I want to know how and where can I check if the notification was successfully delivered to the Android app?
How do I use the message_id and/or multicast_id that is given back to get the delivery status of the notification? I can't find working code examples of checking for delivery status with Firebase. Does anyone have working JSON code to query the delivery status of a Firebase message via the message_id and/or multicast_id or another way? The Firebase documentation does not give examples on how to do this (or maybe I missed the example).
Please see the Firebase JSON below used to send the notification to the Firebase news app. Anyone's help is highly appreciated.
In the header I set authorization key=firebase_server_key
and content type is set to application/json
{
"to" : "token received from firebase",
"notification" : {
"body" : "test",
"title" : "Alert",
"icon" : "myicon",
"delivery_receipt_requested": true
}
}
Output from postman:
{"multicast_id":7845213569874521,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:4853214789631%31bd1c9631bd1c96"}]}
Update:
The Diagnostics Tool has been removed since Nov. 30, 2017:
You can no longer access FCM diagnostics data in the Play Console.
Confirming what #user7410521 said in the comments section. There is currently no available API to make use of the message_ids/multicast_ids to retrieve the details of the delivery status of the message sent, other than using the FCM Diagnostics Page. Do also keep in mind that the Diagnostics page is only usable when the app is already published (for Alpha testing or later).
I noticed that you included the delivery_receipt_requested parameter in your payload. Receiving the a message confirmation should be enough to determine that the device received the message.
Though there is no API so far also I could find out. I have tried a workarond. From the server side PHP I am sending an FCM message. Let me present how I have handled this in PHP.
$fcm_return = fcm_message_send($message);
$fcm_return_JSON = json_decode($fcm_return, true);
echo $$fcm_return_JSON['success'];
As I am sending a message to one device, I am comparing return with 1. Based on this you could further implement your logic.

How to add contcat in Roster without sending and accepting subscription request in xmpp chatting

I have download yaxim source code from github yaxim link
Now I want to implement adding contact in Roster without sending and accepting subscription request, i didn't find any documents that describes code and explain it with document,
So I need a solution , I try with github code but I can't solve my issue
You will need to create your own stanza if you want to just add user to your roster. The XML stanza would look like below. You can find info on
http://xmpp.org/rfcs/rfc3921.html#int.
I had a similar requirement on my project but I have been using JsJaC bosh library with openfire as XMPP server.
<iq type='set' id='set1'>
<query xmlns='jabber:iq:roster'>
<item
jid='contact#example.org'
name='MyContact'>
<group>MyBuddies</group>
</item>
</query>
</iq>
After so many research Finally I found that its not possible (or hardly possible if we do some change in library and in our own server) to add contact directly without sending and accepting subscription request, but I found that we can add contacts to end user side without User Interface asking to end user for accepting the subscription request and I have done it in my application.

How to send a URL in email using Android Intents

I'm trying to send a market URL (for eg- market://details?id=com.android.chrome) to a helper app in an email using Intents. I tried using SpannableStringbuilder to ember the URL as proposed in Stack overflow answer and I also tried to use Html.fromHtml as proposed in this blog post
In both the cases, I'm able to send the email but email received does not have any URL. while sending the email I use Gmail as the application for sending the email.
It seems like both the options were proposed a few years ago. Is there a more current way to do this ?
thanks

PHP to android using HTTPpost [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Is there a way to send the selected data from my website to an android application? I want to use the data selected to use on conditions in android.Thanks in advance.
If you use WebView to load the webpage, you can invoke a native-method by using the JavaScriptInterface.
For example:
Bind the JavascriptInterface to your WebView in Android:
webView.addJavascriptInterface(new JavaScriptInterface(), "Android");
in HTML:
<button onclick="appTest('test');return false;">test-button</button>
in Javascript:
function appTest(args) {
if (typeof Android != "undefined"){
if (Android.appTest!= "undefined") {
Android.appTest(args);
}
}
}
and finally in Android:
class JavaScriptInterface {
public void appTest(String s) {
//do something
}
}
EDIT:
Sorry, didn't see HTTPpost in the header
Nope , It is not possible to send data using httppost from server to android.
Approach 1:
For this kind of data transmission you need to implement socket programming both the side.
Like : XMPP Server(Openfire);
Approac 2:
1) Implement push notification at device side.
2) Make one webservice at server side which will return response(whatever you want to send to mobile side).
3) Fire pushnotification from your server to google server and google server will send that push to android device.
4) When android receive push it will call the webservice of your server and will get the date that you want to send.
We are using Second approach in our application IjoomerAdvance.
Refer this link for Google push implementation between android and php
http://androidexample.com/Android_Push_Notifications_using_Google_Cloud_Messaging_GCM/index.php?view=article_discription&aid=119&aaid=139

Categories

Resources