android-firebase-chat
android-firebase-chat copied to clipboard
Notification
is there anybody solve pushNotification problem??
yes
@MintuReena Could you please let me know how to do it? How to send notification to user when he/she receives a new message without the need to check the chats for new messages in the application? Thanks guys
give me your mail address ill send u the code of notification
R33N4
On Mon, Feb 5, 2018 at 1:29 AM, ahmaddaas94 [email protected] wrote:
@MintuReena https://github.com/mintureena Could you please let me know how to do it? How to send notification to user when he/she receives a new message without the need to check the chats for new messages in the application? Thanks guys
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hieuapp/android-firebase-chat/issues/30#issuecomment-362934720, or mute the thread https://github.com/notifications/unsubscribe-auth/AYpEynwNptrEvjjVQ0Ua3MrCT4eIWC5Qks5tRgwxgaJpZM4Q8git .
Hello
Can i have the code for the notification? I have try the code, but i just can receive one time for the message notification! Could you help ?
Regards Riff
On Mon, 5 Feb 2018 at 14:01, ReenaKoR [email protected] wrote:
give me your mail address ill send u the code of notification
R33N4
On Mon, Feb 5, 2018 at 1:29 AM, ahmaddaas94 [email protected] wrote:
@MintuReena https://github.com/mintureena Could you please let me know how to do it? How to send notification to user when he/she receives a new message without the need to check the chats for new messages in the application? Thanks guys
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/hieuapp/android-firebase-chat/issues/30#issuecomment-362934720 , or mute the thread < https://github.com/notifications/unsubscribe-auth/AYpEynwNptrEvjjVQ0Ua3MrCT4eIWC5Qks5tRgwxgaJpZM4Q8git
.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hieuapp/android-firebase-chat/issues/30#issuecomment-362989492, or mute the thread https://github.com/notifications/unsubscribe-auth/Ac8UWfEgK0nrDo-HxEPWPbN2rTjRVvFZks5tRpkkgaJpZM4Q8git .
@MintuReena Thanks for the reply, I really appreciate your help. Here is my email: [email protected] Thanks alot Ahmad
@RiffChan give me your email address
public class FcmNotificationBuilder { public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); private static final String TAG = "FcmNotificationBuilder"; private static final String SERVER_API_KEY = "Your Server Api Key"; private static final String CONTENT_TYPE = "Content-Type"; private static final String APPLICATION_JSON = "application/json"; private static final String AUTHORIZATION = "Authorization"; private static final String AUTH_KEY = "key=" + SERVER_API_KEY; private static final String FCM_URL = "https://fcm.googleapis.com/fcm/send"; // json related keys private static final String KEY_TO = "to"; private static final String KEY_NOTIFICATION = "notification"; private static final String KEY_TITLE = "title"; private static final String KEY_TEXT = "text"; private static final String KEY_DATA = "data"; private static final String KEY_USERNAME = "username"; private static final String KEY_UID = "uid"; private static final String KEY_ROOMID = "roomId"; private static final String KEY_FCM_TOKEN = "fcm_token"; private static final String KEY_FCM_GROUPID = "GroupId"; private static final String KEY_BITMAP = "bitmap"; private String mTitle; private String mMessage; private String mUsername; private String mUid; private String mroomId; private String mFirebaseToken; private String mGroupId; private String mReceiverFirebaseToken; private String mBitmap; private FcmNotificationBuilder() { } public static FcmNotificationBuilder initialize() { return new FcmNotificationBuilder(); } public FcmNotificationBuilder title(String title) { mTitle = title; return this; } public FcmNotificationBuilder message(String message) { mMessage = message; return this; } public FcmNotificationBuilder username(String username) { mUsername = username; return this; } public FcmNotificationBuilder uid(String uid) { mUid = uid; return this; } public FcmNotificationBuilder roomId(String roomId) { mroomId = roomId; return this; } public FcmNotificationBuilder firebaseToken(String firebaseToken) { mFirebaseToken = firebaseToken; return this; } public FcmNotificationBuilder GroupId(String GroupId) { mGroupId = GroupId; return this; } public FcmNotificationBuilder receiverFirebaseToken(String receiverFirebaseToken) { mReceiverFirebaseToken = receiverFirebaseToken; return this; } public FcmNotificationBuilder bitmap(String bitmap) { mBitmap = bitmap; return this; } public void send() { RequestBody requestBody = null; try { requestBody = RequestBody.create(MEDIA_TYPE_JSON, getValidJsonBody().toString()); } catch (JSONException e) { e.printStackTrace(); } Request request = new Request.Builder() .addHeader(CONTENT_TYPE, APPLICATION_JSON) .addHeader(AUTHORIZATION, AUTH_KEY) .url(FCM_URL) .post(requestBody) .build();
Call call = new OkHttpClient().newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e(TAG, "onGetAllUsersFailure: " + e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.e(TAG, "onResponse: " + response.body().string());
}
});
}
private JSONObject getValidJsonBody() throws JSONException {
JSONObject jsonObjectBody = new JSONObject();
jsonObjectBody.put(KEY_TO, mReceiverFirebaseToken);
JSONObject jsonObjectData = new JSONObject();
jsonObjectData.put(KEY_TITLE, mTitle);
jsonObjectData.put(KEY_TEXT, mMessage);
jsonObjectData.put(KEY_USERNAME, mUsername);
jsonObjectData.put(KEY_UID, mUid);
jsonObjectData.put(KEY_ROOMID, mroomId);
jsonObjectData.put(KEY_FCM_TOKEN, mFirebaseToken);
jsonObjectData.put(KEY_BITMAP, mBitmap);
jsonObjectBody.put(KEY_DATA, jsonObjectData);
return jsonObjectBody;
}
}
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { private static final String TAG = "MyFirebaseIIDService"; /** * Called if InstanceID token is updated. This may occur if the security of * the previous token had been compromised. Note that this is called when the InstanceID token * is initially generated so this is where you would retrieve the token. */ // [START refresh_token] @Override public void onTokenRefresh() { // Get updated InstanceID token. String refreshedToken = FirebaseInstanceId.getInstance().getToken(); Log.d(TAG, "Refreshed token: " + refreshedToken); // If you want to send messages to this application instance or // manage this apps subscriptions on the server side, send the // Instance ID token to your app server. sendRegistrationToServer(refreshedToken); } // [END refresh_token]
/**
* Persist token to third-party servers.
* <p>
* Modify this method to associate the user's FCM InstanceID token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(final String token) {
// new SharedPrefUtil(getApplicationContext()).saveString(Constants.ARG_FIREBASE_TOKEN, token);
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
FirebaseDatabase.getInstance()
.getReference()
// .child(Constants.ARG_USERS)
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
// .child(Constants.ARG_FIREBASE_TOKEN)
.setValue(token);
}
}
}
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
String title = remoteMessage.getData().get("title");
String message = remoteMessage.getData().get("text");
String username = remoteMessage.getData().get("username");
String uid = remoteMessage.getData().get("uid");
String fcmToken = remoteMessage.getData().get("fcm_token");
String GroupId=remoteMessage.getData().get("GroupId");
String roomId=remoteMessage.getData().get("roomId");
// Don't show notification if chat activity is open.
if (!FirebaseChatMainApp.isChatActivityOpen()) {
sendNotification(title,
message,
username,
uid,
fcmToken,
GroupId,
roomId);
} else {
EventBus.getDefault().post(new PushNotificationEvent(title,
message,
username,
uid,
fcmToken,
roomId));
}
}
}
/**
* Create and show a simple notification containing the received FCM message.
*/
private void sendNotification(String title,
String message,
String receiver,
String receiverUid,
String firebaseToken,
String GroupId,
String roomId) {
Intent intent = new Intent(this, ChatActivity.class);
intent.putExtra("ARG_RECEIVER", receiver);
intent.putExtra("Fname",title);
intent.putExtra("ARG_RECEIVER_UID", receiverUid);
intent.putExtra("ARG_FIREBASE_TOKEN", firebaseToken);
intent.putExtra("GroupId",GroupId);
intent.putExtra("roomId",roomId);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setLights(0,128,0)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
@MintuReena Thanks for the reply, I have added the FCM related classes. However, it worked on Android 21 (Lollipop) but didn't work or newer versions like Nougat. Do you have any idea why this happens? Thanks
Me too I need the modified files only please @MeetuReena @naveenrao2k Email: [email protected]
@MeetuReena please reply
I mean @MintuReena
@ahmaddaas94 please send me your modified files for the notification I too working for lollipop
@mintureena where is pushnotificationevent.class code you mentioned it in the last code
give me your email address I'll send code
R33N4
On Sat, Mar 3, 2018 at 10:09 AM, darkIncorporative <[email protected]
wrote:
@MintuReena https://github.com/mintureena where is pushnotificationevent.class code you mentioned it in the last code
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hieuapp/android-firebase-chat/issues/30#issuecomment-370117612, or mute the thread https://github.com/notifications/unsubscribe-auth/AYpEykY3FBPcJH3UEPPIiU84GR4PQFVwks5tah6AgaJpZM4Q8git .
Already gave it above
@mintuReena I gave it above
@MintuReena Thanks brother i got it.
@MintuReena Could you give me the code? Here is my email [email protected]
yes sent R33N4
On Thu, Aug 2, 2018 at 7:56 AM Giovanka Bisano Putra < [email protected]> wrote:
@MintuReena https://github.com/MintuReena Cloud you give me the code? Here is my email [email protected]
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hieuapp/android-firebase-chat/issues/30#issuecomment-409784997, or mute the thread https://github.com/notifications/unsubscribe-auth/AYpEyjUvbxj0cC_ZsuNd1DOs7OKfG4M9ks5uMmM5gaJpZM4Q8git .
Can u plz send me the modified code I am having the issue with the database when i clicked on add user or login in app get crashed.. mail id: [email protected]
Can you sende me the code please too? mail: [email protected]
@MintuReena Can you send me code too mail: [email protected]
I just downloaded the app today from GitHub and having so many problems I just staring learning so its hell lot of hard...… errors so im reading all the issues one by one lol xD
@MintuReena can u check and see why notification are not working if possible plz I just sent u a mail sorry in advance if its a stupid mistake since I'm new at coding if possible can u check mail: [email protected]
if someone can send me the source code of notification push 👍 : [email protected]
@MintuReena can u give me the source code of push notification 👍: [email protected]