10 changed files with 174 additions and 7 deletions
-
1.idea/gradle.xml
-
2.idea/misc.xml
-
10app/build.gradle
-
76app/google-services.json
-
5app/src/main/AndroidManifest.xml
-
65app/src/main/java/fr/svpro/radiomercure/NotificationsService.java
-
BINapp/src/main/res/drawable/logo_mail.png
-
1app/src/main/res/values/strings.xml
-
19build.gradle
-
2gradle/wrapper/gradle-wrapper.properties
@ -0,0 +1,76 @@ |
|||
{ |
|||
"project_info": { |
|||
"project_number": "490705336937", |
|||
"project_id": "notificationsapp-2a7c1", |
|||
"storage_bucket": "notificationsapp-2a7c1.appspot.com" |
|||
}, |
|||
"client": [ |
|||
{ |
|||
"client_info": { |
|||
"mobilesdk_app_id": "1:490705336937:android:7141fc2a8f1a30a70b00f8", |
|||
"android_client_info": { |
|||
"package_name": "fr.svpro.notifications" |
|||
} |
|||
}, |
|||
"oauth_client": [ |
|||
{ |
|||
"client_id": "490705336937-5evh6d5tkrlcnn42gdlnqn755u6n9ej2.apps.googleusercontent.com", |
|||
"client_type": 1, |
|||
"android_info": { |
|||
"package_name": "fr.svpro.notifications", |
|||
"certificate_hash": "fb20ab67d6758912a33a08f4e5ef3390f3698e7c" |
|||
} |
|||
}, |
|||
{ |
|||
"client_id": "490705336937-6ebqqo0ru9qe1dpb9vj2uqtmirkq9qvs.apps.googleusercontent.com", |
|||
"client_type": 3 |
|||
} |
|||
], |
|||
"api_key": [ |
|||
{ |
|||
"current_key": "AIzaSyBUIycGyp0prPr6lnww55rdRUPIuG4m4TQ" |
|||
} |
|||
], |
|||
"services": { |
|||
"appinvite_service": { |
|||
"other_platform_oauth_client": [ |
|||
{ |
|||
"client_id": "490705336937-6ebqqo0ru9qe1dpb9vj2uqtmirkq9qvs.apps.googleusercontent.com", |
|||
"client_type": 3 |
|||
} |
|||
] |
|||
} |
|||
} |
|||
}, |
|||
{ |
|||
"client_info": { |
|||
"mobilesdk_app_id": "1:490705336937:android:3eefe388b5d93c3b0b00f8", |
|||
"android_client_info": { |
|||
"package_name": "fr.svpro.radiomercure" |
|||
} |
|||
}, |
|||
"oauth_client": [ |
|||
{ |
|||
"client_id": "490705336937-6ebqqo0ru9qe1dpb9vj2uqtmirkq9qvs.apps.googleusercontent.com", |
|||
"client_type": 3 |
|||
} |
|||
], |
|||
"api_key": [ |
|||
{ |
|||
"current_key": "AIzaSyBUIycGyp0prPr6lnww55rdRUPIuG4m4TQ" |
|||
} |
|||
], |
|||
"services": { |
|||
"appinvite_service": { |
|||
"other_platform_oauth_client": [ |
|||
{ |
|||
"client_id": "490705336937-6ebqqo0ru9qe1dpb9vj2uqtmirkq9qvs.apps.googleusercontent.com", |
|||
"client_type": 3 |
|||
} |
|||
] |
|||
} |
|||
} |
|||
} |
|||
], |
|||
"configuration_version": "1" |
|||
} |
@ -0,0 +1,65 @@ |
|||
package fr.svpro.radiomercure; |
|||
|
|||
import android.app.NotificationChannel; |
|||
import android.app.NotificationManager; |
|||
import android.app.PendingIntent; |
|||
import android.content.Context; |
|||
import android.content.Intent; |
|||
import android.media.RingtoneManager; |
|||
import android.os.Build; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.core.app.NotificationCompat; |
|||
|
|||
import com.google.firebase.messaging.FirebaseMessagingService; |
|||
import com.google.firebase.messaging.RemoteMessage; |
|||
|
|||
public class NotificationsService extends FirebaseMessagingService { |
|||
|
|||
private final int NOTIFICATION_ID = 007; |
|||
private final String NOTIFICATION_TAG = "NOTIFICATIONS"; |
|||
|
|||
@Override |
|||
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) { |
|||
super.onMessageReceived(remoteMessage); |
|||
if (remoteMessage.getNotification() != null) { |
|||
// Get message sent by Firebase |
|||
RemoteMessage.Notification notification = remoteMessage.getNotification(); |
|||
sendVisualNotification(notification); |
|||
|
|||
} |
|||
} |
|||
|
|||
private void sendVisualNotification(RemoteMessage.Notification notification) { |
|||
|
|||
// Create an Intent that will be shown when user will click on the Notification |
|||
Intent intent = new Intent(this, MainActivity.class); |
|||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); |
|||
|
|||
// Create a Channel (Android 8) |
|||
String channelId = getString(R.string.default_notification_channel_id); |
|||
|
|||
// Build a Notification object |
|||
NotificationCompat.Builder notificationBuilder = |
|||
new NotificationCompat.Builder(this, channelId) |
|||
.setSmallIcon(R.drawable.logo_mail) |
|||
.setContentTitle(notification.getTitle()) |
|||
.setContentText(notification.getBody()) |
|||
.setAutoCancel(true) |
|||
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) |
|||
.setContentIntent(pendingIntent); |
|||
|
|||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
|||
|
|||
// Support Version >= Android 8 |
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
|||
CharSequence channelName = "Firebase Messages"; |
|||
int importance = NotificationManager.IMPORTANCE_HIGH; |
|||
NotificationChannel mChannel = new NotificationChannel(channelId, channelName, importance); |
|||
notificationManager.createNotificationChannel(mChannel); |
|||
} |
|||
|
|||
// Show notification |
|||
notificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, notificationBuilder.build()); |
|||
} |
|||
} |
After Width: 200 | Height: 200 | Size: 31 KiB |
@ -1,7 +1,22 @@ |
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules. |
|||
buildscript { |
|||
repositories { |
|||
// Make sure that you have the following two repositories |
|||
google() // Google's Maven repository |
|||
|
|||
mavenCentral() // Maven Central repository |
|||
|
|||
} |
|||
dependencies { |
|||
// Add the dependency for the Google services Gradle plugin |
|||
classpath 'com.google.gms:google-services:4.3.15' |
|||
|
|||
} |
|||
} |
|||
|
|||
plugins { |
|||
id 'com.android.application' version '7.3.1' apply false |
|||
id 'com.android.library' version '7.3.1' apply false |
|||
id 'com.android.application' version '7.4.2' apply false |
|||
id 'com.android.library' version '7.4.2' apply false |
|||
} |
|||
|
|||
task clean(type: Delete) { |
|||
|
@ -1,6 +1,6 @@ |
|||
#Tue Mar 22 19:55:37 CET 2022 |
|||
distributionBase=GRADLE_USER_HOME |
|||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip |
|||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip |
|||
distributionPath=wrapper/dists |
|||
zipStorePath=wrapper/dists |
|||
zipStoreBase=GRADLE_USER_HOME |
Write
Preview
Loading…
Cancel
Save
Reference in new issue