Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService implements Constants{
- SharedPreferences sp;
- @Override
- public void onMessageReceived(RemoteMessage remoteMessage) {
- sp = getSharedPreferences(CHECK_SETTINGS,
- Context.MODE_PRIVATE);
- boolean webSite = sp.getBoolean(notifWebSite, true);
- boolean shops = sp.getBoolean(notifShops, true);
- if(webSite && shops){
- if(remoteMessage.getData().equals("WEB")){
- sendNotification(remoteMessage.getNotification().getBody(),remoteMessage.getData().get("WEB"));
- }
- if (remoteMessage.getData().equals("SHOP")){
- sendNotification(remoteMessage.getNotification().getBody(),remoteMessage.getData().get("SHOP"));
- }
- }
- else if(!webSite && !shops){
- }
- else if(!webSite && shops){
- if(remoteMessage.getData().equals("SHOP")){
- sendNotification(remoteMessage.getNotification().getBody(),remoteMessage.getData().get("WEB"));
- }
- }
- else if(webSite && !shops){
- if(remoteMessage.getData().equals("WEB")){
- sendNotification(remoteMessage.getNotification().getBody(),remoteMessage.getData().get("WEB"));
- }
- }
- /*if(remoteMessage.getData().get("URL")==null){
- sendNotification(remoteMessage.getNotification().getBody(),URL_HODITE_COM);
- }
- else{
- sendNotification(remoteMessage.getNotification().getBody(),remoteMessage.getData().get("URL"));
- }*/
- }
- private void sendNotification(String body,String url) {
- Intent intent=new Intent(this,WebActivity.class);
- intent.putExtra(KEY_INTENT,url);
- PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);
- Notification.Builder builder = new Notification.Builder(this);
- // оставим только самое необходимое
- builder.setContentIntent(pendingIntent)
- .setWhen(System.currentTimeMillis()) //Время уведомления
- .setSmallIcon(R.mipmap.ico)
- .setContentTitle("Hodite")
- .setContentText(body); // Текст уведомления
- Notification notification = builder.build();
- notification.defaults = Notification.DEFAULT_SOUND |
- Notification.DEFAULT_VIBRATE;
- // ставим флаг, чтобы уведомление пропало после нажатия
- notification.flags |= Notification.FLAG_AUTO_CANCEL;
- NotificationManager nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- nm.notify((body+url).hashCode(),notification);
- }
- }
Add Comment
Please, Sign In to add comment