some cleanup

This commit is contained in:
Michael Zanetti 2020-10-16 19:45:51 +02:00
parent e02274fce1
commit d375ad387d
4 changed files with 21 additions and 12 deletions

View File

@ -75,7 +75,7 @@ android {
HEADERS += platformintegration/android/platformhelperandroid.h
SOURCES += platformintegration/android/platformhelperandroid.cpp
javafiles.commands = $(COPY_DIR) $${PWD}/platformintegration/android/io $${ANDROID_PACKAGE_SOURCE_DIR}/src
javafiles.commands = $(COPY_DIR) $${PWD}/platformintegration/android/io $${ANDROID_PACKAGE_SOURCE_DIR}/src/
QMAKE_EXTRA_TARGETS += javafiles
POST_TARGETDEPS += javafiles

View File

@ -5,6 +5,7 @@ import com.google.firebase.messaging.FirebaseMessagingService;
import android.util.Log;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.app.PendingIntent;
import android.app.Notification;
import android.app.NotificationChannel;
@ -13,15 +14,16 @@ import android.net.Uri;
import android.content.Context;
import android.provider.Settings.System;
import android.os.Build;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.support.v4.app.NotificationCompat;
import java.util.Random;
import R;
public class NymeaAppNotificationService extends FirebaseMessagingService {
private static final String TAG = "nymea-app: NymeaAppNotificationService";
/**
* Called when message is received.
@ -50,9 +52,16 @@ public class NymeaAppNotificationService extends FirebaseMessagingService {
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 0);
Resources r = Context.getResources();
// We can't directly access R.drawable.ic_stat_notification from here:
// When the package is branded, the package name is not "io.guh.nymeaapp" and resources in
// the res/ folder are built into the app's package which isn't the same as this files package.
// Because of this, we need to dynamically fetch the resource from the package resources
int resId = getResources().getIdentifier("ic_stat_notificationicon", "drawable", getPackageName());
Log.d(TAG, "notification icon resource: " + resId + " Package:" + getPackageName());
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "notify_001")
.setSmallIcon(R.drawable.ic_stat_notificationicon)
.setSmallIcon(resId)
.setColor(0xFF57BAAE)
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getData().get("body"))
@ -70,7 +79,7 @@ public class NymeaAppNotificationService extends FirebaseMessagingService {
int notificationId = new Random().nextInt(60000);
Log.d("Posting Notification", remoteMessage.getMessageId());
Log.d(TAG, "Posting Notification: " + remoteMessage.getMessageId());
notificationManager.notify(notificationId, notificationBuilder.build());
}

View File

@ -53,11 +53,6 @@ static QAndroidJniObject getAndroidWindow()
PlatformHelperAndroid::PlatformHelperAndroid(QObject *parent) : PlatformHelper(parent)
{
// QAndroidIntent serviceIntent(QtAndroid::androidActivity().object(), "io.guh.nymeaapp.NymeaAppControlService");
// m_serviceConnection = new DeviceControlServiceConnection();
// QtAndroid::bindService(serviceIntent, *m_serviceConnection, QtAndroid::BindFlag::AutoCreate);
m_instance = this;
}

View File

@ -237,7 +237,12 @@ Item {
PlatformHelper.requestPermissions();
}
} else {
AWSClient.registerPushNotificationEndpoint(PushNotifications.token, PlatformHelper.machineHostname, PlatformHelper.deviceSerial + "+io.guh.nymeaapp", PlatformHelper.deviceManufacturer, PlatformHelper.deviceModel);
AWSClient.registerPushNotificationEndpoint(
PushNotifications.token,
PlatformHelper.machineHostname,
PlatformHelper.deviceSerial + "+io.guh.nymeaapp" + (appBranding.length > 0 ? "-" + appBranding : ""),
PlatformHelper.deviceManufacturer,
PlatformHelper.deviceModel);
}
}