v2.1.1 - Support Notifications d'Evènements

This commit is contained in:
2023-03-08 19:40:40 +01:00
parent 86f584fb15
commit 16f755d564
10 changed files with 174 additions and 7 deletions

1
.idea/gradle.xml generated
View File

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

2
.idea/misc.xml generated
View File

@@ -10,7 +10,7 @@
</map> </map>
</option> </option>
</component> </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" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@@ -1,5 +1,6 @@
plugins { plugins {
id 'com.android.application' id 'com.android.application'
id 'com.google.gms.google-services'
} }
// Load keystore // Load keystore
def keystorePropertiesFile = rootProject.file("keystore.properties") def keystorePropertiesFile = rootProject.file("keystore.properties")
@@ -22,8 +23,8 @@ android {
applicationId "fr.svpro.radiomercure" applicationId "fr.svpro.radiomercure"
minSdk 26 minSdk 26
targetSdk 33 targetSdk 33
versionCode 210 versionCode 211
versionName '2.1.0' versionName '2.1.1'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@@ -44,7 +45,7 @@ android {
dependencies { 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 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
@@ -55,4 +56,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 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 Normal file
View File

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

View File

@@ -42,6 +42,11 @@
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<service android:name=".MediaPlayerService" /> <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> </application>
</manifest> </manifest>

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

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

View File

@@ -1,7 +1,22 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // 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 { plugins {
id 'com.android.application' version '7.3.1' apply false id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.3.1' apply false id 'com.android.library' version '7.4.2' apply false
} }
task clean(type: Delete) { task clean(type: Delete) {

View File

@@ -1,6 +1,6 @@
#Tue Mar 22 19:55:37 CET 2022 #Tue Mar 22 19:55:37 CET 2022
distributionBase=GRADLE_USER_HOME 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 distributionPath=wrapper/dists
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME