Browse Source

v2.1.1 - Support Notifications d'Evènements

master v2.1.1
Samuel Vermeulen 2 weeks ago
parent
commit
16f755d564
  1. 1
      .idea/gradle.xml
  2. 2
      .idea/misc.xml
  3. 10
      app/build.gradle
  4. 76
      app/google-services.json
  5. 5
      app/src/main/AndroidManifest.xml
  6. 65
      app/src/main/java/fr/svpro/radiomercure/NotificationsService.java
  7. BIN
      app/src/main/res/drawable/logo_mail.png
  8. 1
      app/src/main/res/values/strings.xml
  9. 19
      build.gradle
  10. 2
      gradle/wrapper/gradle-wrapper.properties

1
.idea/gradle.xml

@ -7,6 +7,7 @@
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

2
.idea/misc.xml

@ -10,7 +10,7 @@
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

10
app/build.gradle

@ -1,5 +1,6 @@
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
// Load keystore
def keystorePropertiesFile = rootProject.file("keystore.properties")
@ -22,8 +23,8 @@ android {
applicationId "fr.svpro.radiomercure"
minSdk 26
targetSdk 33
versionCode 210
versionName '2.1.0'
versionCode 211
versionName '2.1.1'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@ -44,7 +45,7 @@ android {
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
@ -55,4 +56,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation platform('com.google.firebase:firebase-bom:31.2.2')
implementation 'com.google.firebase:firebase-analytics:21.2.0'
implementation 'com.google.firebase:firebase-messaging:23.1.2'
}

76
app/google-services.json

@ -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"
}

5
app/src/main/AndroidManifest.xml

@ -42,6 +42,11 @@
android:screenOrientation="portrait" />
<service android:name=".MediaPlayerService" />
<service android:name=".NotificationsService" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>

65
app/src/main/java/fr/svpro/radiomercure/NotificationsService.java

@ -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());
}
}

BIN
app/src/main/res/drawable/logo_mail.png

After

Width: 200  |  Height: 200  |  Size: 31 KiB

1
app/src/main/res/values/strings.xml

@ -43,5 +43,6 @@
<string name="btn_envoyer">Envoyer</string>
<string name="btn_annuler">Annuler</string>
<string name="splash_txt">Bienvenue...</string>
<string name="default_notification_channel_id">Notifications</string>
</resources>

19
build.gradle

@ -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) {

2
gradle/wrapper/gradle-wrapper.properties

@ -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
Loading…
Cancel
Save