I've currently wrote an app that receives a GCM message and stores it in a database then creates an alertDialog to show above any app what the new message is, the only problem i have is if a new message is received before the current alertDialog is closed you don't get to see the new message, if i sit and close each message its fine.
So i think what ive been trying is to ask 'is the alertDialog showing...if not show the message, if its already showing close it and open a new one with the new message'.
Does this sound feasible?
Cheers
Mark
I would recommend using a notification rather than an alert dialog for showing incoming messages. The NotificationManager lets you set an id and tag when you post a notification. Then if you later post one with the same id and tag, the existing one will be updated.
On Lollipop (and newer) devices you can even get a similar effect to what you describe with the notification coming up on top of the current app using heads up notifications: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Heads-up
Related
In my application, I am offering video and voice calls between users. I'm using Firebase Realtime database and FCM as well to do so.
Here is the data that my notification is delivering:
data: {
channel_id: channel_id,
user_id: user_id
}
In my FirebaseMessagingService class, I retrieve the data and open the Video/Call activity like so:
if(remoteMessage.getData().size > 0) {
Intent intent = new Intent(this, VideoCallActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("channel_id", remoteMessage.getData().get("channel_id"));
intent.putExtra("user_id", remoteMessage.getData().get("user_id"));
getApplicationContext().startActivity(intent);
}
Everything is working perfectly even when the application is in background. However, I'm facing this issue:
If an user didn't have internet connection when he was called, when he connects to internet his phone will automatically start the VideoCallActivity even if the call has been aborted (by the caller) and the notification removed from Firebase real time database.
So, please is there a way to cancel sent notifications, or know the delivery status of those notifications, or another way around to do so? That will allow me to add the list of missed calls for users.
Thanks!
In a scenario like this, I know of two options:
Send another FCM message when the call is cancelled
Only use FCM to send a tickle
Send another FCM message when the call is cancelled
One of the properties you can give an FCM message is an collapse_key. When you send a message with a collapse_key, that message replaces any previous message with the same collapse_key value.
You can use this to send a "nope, forget about it" message, when the user cancels the call.
Only use FCM to send a tickle
Alternatively you can have the FCM message just be a so-called tickle: an almost empty message, that just tells the app to wake up and go check its queue of incoming messages in the database.
That way: if the call is still in the database, the app can pick it up. But if there is no call in the database, it can just do nothing.
You'll want to do this type of database interaction in a service, so that it can run when the app is backgrounded.
Giving an expiration time is feasible as suggested in the documentation
Check Here
Setting the lifespan of a message
On Android and Web/JavaScript, you can specify the maximum lifespan of a message. The value must be a duration from 0 to 2,419,200 seconds (28 days), and it corresponds to the maximum period of time for which FCM stores and attempts to deliver the message. Requests that don't contain this field default to the maximum period of four weeks.
Here are some possible uses for this feature:
Video chat incoming calls
Expiring invitation events
Calendar events
Im having problems with notifications in android. Im making a chat client.
when my client tells me that someone is chatting with me from a previous chat, and I push it, it opens up a new instance of that chat. I want it to work like the facebook mesenger, that is when I push the notification it opens up the chat for the person which is trying to speak to me, instead of an empty chat window.
regards.
In your Notification you can set a Intent:
Notification n;
n.setContentIntent(intent)
In your intent you will set the activity that will be started and also you can put extras, like an ID of the conversation or something that can be identified latter.
Because when you start this new chat activity on onCreate() you need to check if there is extras, take the ID for example and search for your conversation history and write all your logic.
I am trying to create a simple android messaging app. So basically let us assume that user A sends a message to user B. I would like that user B receives a notification when the message is received. I know how to create the notification and all. But basically I would like to know how the user B constantly checks if a new message has been received even when he is out of the app, and then that would trigger the notification and subsequent actions.
Thank you
You have to setup an unbound background service.
With this you can constantly make pull-requests to your server or get push-notifications from your server and display notifications.
https://developer.android.com/training/run-background-service/create-service.html
You can use Event Bus lib for this purpose. When new message will be received it will create and event and then you can receive that event event and do other operations.
If you are talking about text messages then you will have to create a BroadcastReceiver
http://developer.android.com/reference/android/content/BroadcastReceiver.html
You can see my answer here for SMS Receiver
Verify sms text message by app before it displayed to user
Don't forget to give permissions in your app's manifest.
Hope it helps.
I have a text messaging app that I want users to be able to text another app of mine on someone else's phone that will show up within the app. Printed on screen. I have one app that will send the message and one app on the receiving device that will display the message. How would I go about doing this?
The receiving app is an opengl app that will display the message in front of a 3d model from the sending app.
If someone could help me out or get me going in the right direction, I would greatly appreciate it. Thank you for your time.
EDIT: This is what I'm doing. I'm making a live wallpaper that women can put on their phone, a seperate "regular" app will allow the husband, fiance, etc to send a message to the lwp on the significant others phone that will display at the top half of the lwp screen.
public void sendSMS(String phoneNumber, String message)
{
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
You can do something like this for sending the sms.
Yes, it's possible.
Use SMSPopup as a working Android project you can use. It has the two parts you need: the sending part and the receiving part, and it's open source. Here it is on Google Play.
The only issue is that the user probably won't want those application messages intermingled with his normal SMS messages.
So you'll want to tag your application text messages with a unique keyword so that the receiving app knows it's a message for itself and no one else. And by tagging, I just mean to insert a unique keyword at the beginning of its subject line.
And your receiving app will have to register a BroadcastReceiver with a priority of 100 so that if it detects a message intended for itself, it can just delete it from the content provider and just do an AbortBroadcast so that the other text messaging apps don't beep for a message that wasn't meant for them in the first place.
In that sense, SMSPopup probably already does 90% of what you need. SMSPopup doesn't automatically delete the sms it receives, nor will it filter them on a particular keyword, but it must silently swallow them so that the normal notification system for sms doesn't get triggered (since SMSPopup provides its own notification popup interface instead).
Hi Steve we have RabbitMQServer to send messages between apps. We should configure the server and need to implement functionlities to send and receiving messages.
You may get details about RabbitMQ server at http://www.rabbitmq.com/.
Currently I have a button that when pushed calls the Intent below.
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { toString });
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
"New Files from Safe Storage");
sharingIntent.setType("text/*");
startActivity(sharingIntent);
This intent then uses the default share activity to share the email with my attached file (which i took out for this example). When this code goes off it opens the gmail activity for me, but i still need to push the send button even though everything is filled in. Is there a way to make this instead just send automatically without showing the user the activity and having them forced to push "Send"?
Have a look on the following link, there is an answer for your question.
Sending Email in Android using JavaMail API without using the default android app(Builtin Email application)