i'm using 2 Galaxy S3 and i send a message from one to the other. I want the other to send back a response like "received msg"
i'm using the android beam demo, and i want to add this ack.I send the ack message when i treat the first message in ProcessIntent with a simple "sendNdefMessage"? how do i manage the receipt of the ack in the other device?
void processIntent(Intent intent) {
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
NfcAdapter.EXTRA_NDEF_MESSAGES);
// only one message sent during the beam
NdefMessage msg = (NdefMessage) rawMsgs[0];
// record 0 contains the MIME type, record 1 is the AAR, if present
mInfoText.setText(new String(msg.getRecords()[0].getPayload()));
//ack message
mNfcAdapter.setNdefPushMessageCallback(ackMsg, this);
}
Thanks a lot
You cannot send a message back, unfortunately. However, the device that sent the message knows when it has been received successfully. Your app can be notified of this by registering a callback with NfcAdapter.OnNdefPushCompleteCallback()
Related
I'm trying to send push notifications throught FCM services.
In my MainActivity I write this code:
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// checking for type intent filter
if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
// gcm successfully registered
// now subscribe to `global` topic to receive app wide notifications
FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
displayFirebaseRegId();
} else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) {
// new push notification is received
String message = intent.getStringExtra("message");
Toast.makeText(getApplicationContext(), "Push notification: " + message, Toast.LENGTH_LONG).show();
}
}
};
In order to subscribe user to a topic.
From backend I make a call to FCM service at this link : https://fcm.googleapis.com/fcm/send
in which I pass this JSON:
{
"to":"/topics/global",
"data":{
"title":"test",
"is_background":false,
"message":"testmessage",
"image":"",
"payload":{
"team":"Test",
"score":"5.6"
},
"timestamp":"2017-05-23 11:55:35"
}
}
and I get this response:
{\"message_id\":8863205901902209389}
But my device doesn't show any notifaction, exept if I use Firebase console with "user segment" or "single device" . Also in Firebase console doesn't works "topic" way.
Thank you in advance for any response.
There are two types of FCM messages.
Notification Messages
Data Messages
On the client side, Notification messages are handled by FCM and automatically displayed in the notification window. If you are using Data Messages, your app needs to handle the received message and create a notification.
The sample payload in your question is a data message and hence it is not displayed in notification (I assume you didn't do any handling). The notifications sent via FCM console are always notification messages and hence those are automatically displayed.
Refer to this FCM page for more details on this.
I have implemented GCM in my application and I have tested via two android devices and it works. I am implementing a simple chat application within my app. My app is actually selling or buying products.
When a user wants to give a bid, then he types his message and send it to server and gcm is activated and seller receives the potential customer's message. When seller clicks on the received push notification message, it should take him to the chat activity. With this simple text message, how do I know which corresponding product?
What I've mentioned in the comments, if you are sending via a server you can do this:
$registatoin_ids = array($regId);
$message = array("message" => $message, "productId" => $uniqueProductId);
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
then in your intent service:
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
String message = extras.getString("message");
String productId = extras.getString("productId");
When you go to build your notification:
Intent productWindow = new Intent(this, ProductActivity.class);
productWindow.putExtra("productId", productId);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,productWindow , 0);
You could format your GCM messages in a specific way, so the message overhead is sent with a format that you know and then you can parse it and take any needed actions. For example, you could send your messages this way:
ProdID:123456,Action:Bid,...
You would take the comma (or any other sign) as separator, get the parts of it and do whatever you want with them.
I know that this may possible be a duplicate question, but the other questions don't answer mine.
I am working on an app that pulls notifications (specifically notifications for new WhatsApp messages) from the status bar and reads their content. I have managed to pull the notification title and the message content.
The problem is, when more than one unread message is received, the notification switches from using EXTRA_TEXT to EXTRA_SUMMARY_TEXT (then returning e.g. "2 new messages" instead.
It must possible to separate the messages somehow, seeing as certain existing apps do it (e.g. Snowball combines all messages and displays them in one place, showing message content even when multiple messages have been received and are still unread).
I know that users can send messages via Intents. However, I cannot seem to access incoming intents and have, therefore, assumed that WhatsApp uses explicit intents to send messages.
Intent i = new Intent("com.test.testapp.NOTIFICATION_LISTENER");
Bundle extras = sbn.getNotification().extras;
if(sbn.getPackageName().contains("com.whatsapp"))
{
String title = extras.getString(Notification.EXTRA_TITLE);
String summary = extras.getString(Notification.EXTRA_SUMMARY_TEXT);
String msg = extras.getString(Notification.EXTRA_TEXT);
if(msg != null)
{
i.putExtra("notification_event", msg);
}
else
{
i.putExtra("notification_event", summary);
}
}
else
{
i.putExtra("notification_event","...");
}
sendBroadcast(i);
My question:
How can I display all received messages without getting "2 new messages" as content OR is there a better way of doing this?
I need to access message content, the sender's number and the time that the message was received, so that I can save it to a database.
Any help would be appreciated.
WhatsApp application has structure for sending notification like this :
Case Notification
Message comes from A : Hi Title : A Text: Hi
Message comes from A : How are you Title : A Text: How are you
Title : A Text: 2 new messages
Message comes from B : Hello Title : B Text: Hello
Title : B Text: 1 new message
Title : A Text: 2 new messages
Title : WhatsApp Text: 3 new messages from 2 conversation
---- Here comes the stacking ----
Message comes from C : Good work Title : C Text: Good work
Title : C Text: 1 new message
Title : B Text: 1 new message
Title : A Text: 2 new messages
Title : WhatsApp Text: 4 new messages from 3 conversation
---- This way when new sender message comes, previoud notifications also comes and we get callback in NotificationListener ----
Last notification comes with Title as Package Name : WhatsApp and Text as : X messages from Y Conversation
To get Text :
sbn.getNotification().extras.getCharSequence(Notification.EXTRA_TEXT).toString();
To get Title :
sbn.getNotification().extras.getCharSequence(Notification.EXTRA_TITLE).toString();
To work with this sturcture of stacking, we need to parse this notification stack and display only selective information in our application
I hope my answer will help and solve your query
This answer is given at : enter link description here
I am sending an SMS to multiple numbers. When I choose only one, it works, and the message is being sent immediately. But when I use multiple (3 for example) SMS Intent is opened, but after I click Send button I see "Sending..." message all the time, SMS is not sent.
Intent sms = new Intent(Intent.ACTION_VIEW);
sms.setType("vnd.android-dir/mms-sms");
sms.putExtra("address", getSMSNumbers);
sms.putExtra("sms_body", "Help!!!");
startActivity(sms);
And getSMSNumbers String looks like this: 512991220;505202222;606123456.
What is wrong? Why isn't the message being sent and it's "sending" all the time?
Also I see when I have more than 1 number, it's being converted to MMS - why?
Maybe you could loop through the numbers and send messages one by one, like this
android.telephony.SmsManager.getDefault().
sendTextMessage("00112233", null, "Message body text", null, null);
I managed to do this - needed to turn off "Group Messaging" in AVD Settings. App was trying to send MMS and that's why it wasn't being sent.
I have created application for receieving the message from one perticular number.Its working fine.Now i want to display the alert icon on inbox application icon after receiving the message.Where should i add the code for that.
if ( extras != null ) {
// get array data from SMS
Object[] smsExtra = (Object[]) extras.get( "pdus" ); // "pdus" is the key
for ( int i = 0; i < smsExtra.length; ++i ) {
// get sms message
SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
// get content and number
String body = sms.getMessageBody();
String address = sms.getOriginatingAddress();
// create display message
if( address.equals("+91999999999")){
messages += "SMS from " + address + " :\n";
messages += body + "\n";
// notify new arriving message
Toast.makeText( context, messages, Toast.LENGTH_LONG ).show();
listSms.add(new SmsInfo(address, body));
this.abortBroadcast();
}
I am sure where you want to display alert badge/icon, but you can check and try to implement: https://github.com/jgilfelt/android-viewbadger
The icon is hardcoded in the AndroidManifest file. It is designed in this way, so the app icon can be retrieved without running any piece of code (which may result in slower startup for the app)
Some custom home applications support this, but with private APIs.
You can try to use the NotificationManager and add an icon to the status bar. That would be even more visible, which is a more recommended way of doing it. Use the status bar in such cases, for what's its designed for...
In regards to getting a dynamic icon, when the phone receives the message (push notification or whatever) and your app goes to build the notification, you can do a small http request to pull a dynamic icon file before building the notification. This will delay the posting a few seconds, but it doesn't really matter. Then you can get the resulting image and use it in the notification. The specific image can be chosen by sending some data with the (let me guess, push notification) that identifies what photo, such as a url, or an id that you can append onto an already existing url in your notification building part of the app.