diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 440480e..5cd135a 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,5 +1,6 @@ + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 6c0b863..2c9deb1 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,7 @@ - + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 64d348c..65572da 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,4 +43,7 @@ dependencies { //implementation 'com.github.denzcoskun:ImageSlideshow:0.1.0' // image slider implementation 'com.github.smarteist:autoimageslider:1.4.0' -} \ No newline at end of file + implementation 'com.google.firebase:firebase-messaging:11.0.4' +} + +apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2eb3e0c..93ff019 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,6 +22,13 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/midstart/FireBaseMessagingService.java b/app/src/main/java/com/example/midstart/FireBaseMessagingService.java new file mode 100644 index 0000000..9f0041a --- /dev/null +++ b/app/src/main/java/com/example/midstart/FireBaseMessagingService.java @@ -0,0 +1,56 @@ +package com.example.midstart; + +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.media.Ringtone; +import android.media.RingtoneManager; +import android.nfc.Tag; +import android.os.IBinder; +import android.util.Log; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.NotificationCompat; + +import com.google.firebase.messaging.FirebaseMessagingService; +import com.google.firebase.messaging.RemoteMessage; + +public class FireBaseMessagingService extends android.app.Service { + private static final String TAG = "FirebaseMsgService"; + private String msg, title; + + public void onMessageReceived(RemoteMessage remoteMessage) { + Log.e(TAG, "onMessageReceived"); + + title = remoteMessage.getNotification().getTitle(); + msg = remoteMessage.getNotification().getBody(); + + Intent intent = new Intent(this, MainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + + PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class),0); + + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.ic_launcher) + .setContentTitle(title) + .setContentText(msg) + .setAutoCancel(true) + .setVibrate(new long[]{1,1000}); + //.setSound(Ringtone.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) + + + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.notify(0,mBuilder.build()); + + mBuilder.setContentIntent(contentIntent); + + + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +}