React Native + Parse.com Push Notifications on Android - android

Couldn't find any documentation on how to handle push notifications coming from Parse on React Native for Android.
I am able to receive the notification after integrating the SDK, but couldn't go from there in order to handle the notification inside the app.
Any ideas?

No Problem.
This is php code.
$data = array("alert" => 'Hello, this í' );
ParsePush::send(array(
"channels" => ["channels"],
"data" => $data,
"post_id" => '1234',
));
And this is Android code.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String jsonData = extras.getString("com.parse.Data");
JSONObject json = new JSONObject(jsonData);
String postID = json.getString("post_id");
if (postID != null) {
Intent parseIntent = new Intent(this, MatchActivity.class);
parseIntent.putExtra("postID", postID);
startActivity(parseIntent);
}
In android code. You can get parametter post_id from php. Sorry English verry bad

Related

Can't parse push payload message in Titanium

In my app, i couldn't parse the "payload" object coming from push notification. There is automatically added '/' in each property in payload after push sent from server. How can i parse the payload property/object and get the notification data in my code?
Here is the payload object :
"payload":"{\"android\":{\"badge\":\"2\",\"alert\":\"Microfinaa_new_ne\",\"sound\":\"door_bell\",\"icon\":\"little_star\",\"vibrate\":true,\"title\":\"Mahboob Zaman\"}}"
And here is the full notification message coming from fcm server:
{"type":"callback","source":{"showTrayNotification":true,"pushType":"gcm","enabled":false,"showTrayNotificationsWhenFocused":false,"singleCallback":false,"focusAppOnPush":false,"showAppOnTrayClick":true,"debug":false,"apiName":"Ti.Module","bubbleParent":true,"invocationAPIs":[],"__propertiesDefined__":true,"_events":{"callback":{}}},"payload":"{\"android\":{\"badge\":\"2\",\"alert\":\"Microfinaa_new_ne\",\"sound\":\"door_bell\",\"icon\":\"little_star\",\"vibrate\":true,\"title\":\"Mahboob Zaman\"}}","bubbles":false,"cancelBubble":false}
And here is my code -
CloudPush.addEventListener('callback', function(evt) {
var json = JSON.stringify(evt.payload);
Ti.API.info("datos = " + json.android);// This line shows undefined
});
Payload is already string you need to parse it and use inverse function
var json = JSON.stringify(evt.payload);
JSON.stringify(Object) -> return String
JSON.parse(StringOject) -> return Object

Android: FCM push notification in background passing data

I'm having difficulty in passing background data to a screen. In the background the app is calling the screen correctly but the data that this screen needs that is in the "data" (id from data object) in the notification is not being picked up.
In foreground I got "data" correctly.
notification json
{
"to" : "akshih890uhnkjh389jfkn3...",
"priority" : "normal",
"time_to_live" : 0,
"data" : {
"type" : "my_type",
"id" : "my_id"
},
"notification" : {
"body" : "Test body",
"title" : "Test title",
"click_action" : ".MyActivity"
}
}
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
String clickAction = remoteMessage.getNotification().getClickAction();
Map<String, String> data = remoteMessage.getData();
Gson gson = new Gson();
MyObject myObject = new MyObject(data.get("id"), data.get("type"), remoteMessage.getNotification().getTitle(),
remoteMessage.getNotification().getBody());
Intent intent = new Intent(myObject.getClickAction());
intent.putExtra("id", myObject.getId());
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
sendFCMNotification(title, body, contentIntent);
}
MyActivity
if(getIntent() != null) {
Bundle extras = getIntent().getExtras();
code = extras.getString("id");
}
int id = Integer.valueOf(remoteMessage.getData().get("id"));
Since you use remoteMessage.getData(), you get entire data object, not an object who has data json inside, you get actual data json with your fields.
String data = remoteMessage.getData();
Gson gson = new Gson();
MyObject myObject = gson.fromJson(data, MyObject.class);
If your app is in background, Firebase will not trigger onMessageReceived(). Why.....? I have no idea. In this situation, I do not see any point in implementing FirebaseMessagingService.
According to docs, if you want to process background message arrival, you have to send 'click_action' with your message. But it is not possible if you send message from Firebase console, only via Firebase API. It means you will have to build your own "console" in order to enable marketing people to use it. So, this makes Firebase console also quite useless!
There is really good, promising, idea behind this new tool, but executed badly.
I suppose we will have to wait for new versions and improvements/fixes!
in the background, you can get data from intent extras if you want to call specific activity then specify it in click_action attribute of data
refer:
Firebase Server reference
Firebase Push
I found the problem, when the server sends me the notification object in the background I can not see the date. But when the server sends only the date I get the id however how will I be able to build a notification without the title and body data?

Cannot read custom data in firebase notification when sending via SDK

I have an Android app which calls a web service to send messages to us for support.
There is a website which we develop where we can respond to a message and we use Firebase for that. Up until now we were just sending a title and a message like so:
var applicationID = "snip";
var senderId = "snip";
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/json";
var data = new
{
to = model.RequestFirebaseID,
notification = new
{
body = model.ResponseMessage,
title = model.ResponseTitle
}
};
In the Android app I am able to extract the message title using the following Java code
String notificationTitle = remoteMessage.getNotification().getTitle();
String notificationBody = remoteMessage.getNotification().getBody();
However now I am trying to send back a custom field called id,so I amend the code to be
var data = new
{
to = model.RequestFirebaseID,
notification = new
{
body = model.ResponseMessage,
title = model.ResponseTitle,
requestid = model.id
}
};
So now when I send a message back to the device using Firebase I have this code to try and read the id field.
String messageID = remoteMessage.getData().get("requestid");
However this causes ends up as null.
So I have tried testing sending this via the Firebase console, I add requestid to the custom data section and give it a value and the above code is able to read it.
It seems that when I am sending via the web application it cannot see the requestid field.
You have to include the data message inside the payload. Something like this:
var payload = new
{
to = model.RequestFirebaseID,
notification = new
{
body = model.ResponseMessage,
title = model.ResponseTitle
},
data = new
{
requestid = model.id
}
};
I changed the root variable name to payload to distinguish it.
If you add a custom data when using the Firebase Notifications console to send the message, it is included inside a data message parameter instead of the notification message. See the Message Types documentation for the difference of the two.

Can we post/send data from Windows Forms Application to Android application?

I have my Windows Forms Application in c# 4.0, I wanted to post/send data to an android application. It need to triggered from Windows Forms.
Any one can suggest me the possible ways to do this?
Thanks & Regards.
Use the WebClient class. Depending on the "payload", you can use of of the UploadXXX methods.
For example:
string URL = "..."; //Your url here
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["Username"] = "myusername";
formData["Password"] = "mypassword";
byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
string Result = Encoding.UTF8.GetString(responseBytes);
Cheers

External administration login script?

I really need your help. I am junior Joomla! developer and also junior Android developer. I am currently building an Android app for Joomla! site administration. So, where do I need help?
I managed without any problems to log in some user to frontend using this code:
// Function for user login
// return : JSON array (login : true/false; user_id : if user is loged in)
public function login() {
$post = JFactory::getApplication()->input;
$result = array();
$username = $post->get('username');
$password = $post->get('password');
$credentials = array("username" => $username, "password" => $password);
$app = JFactory::getApplication('site');
$result['login'] = $app->login($credentials);
if($result['login']) {
$result['user_id'] = JUserHelper::getUserId($username);
}
CJoomDroidHelper::postResult($result);
}
I made component named CJoomDroid which is simple web service with JSON response for every call.
For an example, when I enter:
http://some.joomla.website/index.php?option=com_cjoomdroid&view=authetication&task=login&username=user&password=pass&format=raw
, I manage to log in user to front site panel.
So no problems there, but if I want to log in to administration panel with same user using this code:
// Function for user login
// return : JSON array (login : true/false; user_id : if user is loged in)
public function login() {
$post = JFactory::getApplication()->input;
$result = array();
$username = $post->get('username');
$password = $post->get('password');
$credentials = array("username" => $username, "password" => $password);
$app = JFactory::getApplication('admin');
$result['login'] = $app->login($credentials);
if($result['login']) {
$result['user_id'] = JUserHelper::getUserId($username);
}
CJoomDroidHelper::postResult($result);
}
On this link:
http://some.joomla.website/administration/index.php?option=com_cjoomdroid&view=authetication&task=login&username=user&password=pass&format=raw
, I am getting errors. Is there any way to log in to admin panel this way?
Thanks!
Errors are like "Your session has expired; Please log in again.." etc... Android app is making call with: HttpResponse response = httpclient.execute(new HttpGet(url.toString())); , and response should be JSON object like:
{"login":true}
Automatically logging on Joomla can be very tricky.
You should give a look to this post on google groups.
There is a library named FrameworkOnFramework that enhance the power of Joomla and allows you to automatically login (via CLI or using a simple call) providing a very good protection.

Categories

Resources