Implement notifications on Android

Notify when there are unread messages
This commit is contained in:
Gioacchino Mazzurco 2017-04-12 18:55:23 +02:00
parent d540900df5
commit 5be6094214
10 changed files with 120 additions and 17 deletions

View file

@ -5,9 +5,10 @@
android:installLocation="auto">
<application android:name="org.qtproject.qt5.android.bindings.QtApplication"
android:hardwareAccelerated="true"
android:label="RetroShare">
android:label="RetroShare"
android:icon="@drawable/retroshare06_128x128">
<activity android:name=".RetroShareQmlActivity"
android:label="RetroShare QML"
android:label="RetroShare"
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation"
android:screenOrientation="unspecified"
android:launchMode="singleTask">

View file

@ -0,0 +1 @@
../../../../../data/128x128/apps/retroshare06.png

View file

@ -0,0 +1 @@
../../../../../data/48x48/apps/retroshare06.png

View file

@ -18,6 +18,40 @@
package org.retroshare.android.qml_app;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import org.qtproject.qt5.android.bindings.QtService;
public class RetroShareAndroidNotifyService extends QtService {}
public class RetroShareAndroidNotifyService extends QtService
{
@UsedByNativeCode @SuppressWarnings("unused")
public void notify(String title, String text, String uri)
{
Notification.Builder mBuilder = new Notification.Builder(this);
mBuilder.setSmallIcon(R.drawable.retroshare06_48x48)
.setContentTitle(title)
.setContentText(text)
.setAutoCancel(true);
Intent resultIntent = new Intent(this, RetroShareQmlActivity.class);
if(!uri.isEmpty()) resultIntent.setData(Uri.parse(uri));
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(RetroShareQmlActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent( 0,
PendingIntent.FLAG_UPDATE_CURRENT );
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
}
}

View file

@ -0,0 +1,3 @@
package org.retroshare.android.qml_app;
public @interface UsedByNativeCode {}