mirror of
https://github.com/balzack/databag.git
synced 2025-04-22 09:35:16 +00:00
handle unified push notifications
This commit is contained in:
parent
3803b04504
commit
8764c0f075
@ -16,6 +16,7 @@ import android.os.Build;
|
||||
import android.net.Uri;
|
||||
import android.media.RingtoneManager;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import com.facebook.react.ReactApplication;
|
||||
import com.facebook.react.ReactInstanceManager;
|
||||
@ -71,6 +72,9 @@ public class CustomReceiver extends MessagingReceiver {
|
||||
return;
|
||||
}
|
||||
|
||||
String strMessage = new String(message, StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code */, intent,
|
||||
@ -81,21 +85,19 @@ public class CustomReceiver extends MessagingReceiver {
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,
|
||||
channelId)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setContentTitle("FCM Message").setContentText("ROLO?").setAutoCancel(true).setSound(
|
||||
.setContentTitle(strMessage).setAutoCancel(true).setSound(
|
||||
defaultSoundUri).setContentIntent(pendingIntent);
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(
|
||||
Context.NOTIFICATION_SERVICE);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(channelId, "Channel human readable title",
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
|
||||
notificationManager.notify(0, notificationBuilder.build());
|
||||
|
||||
// Called when a new message is received. The message contains the full POST body of the push message
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setAccountAccess(server, token, appName, appVersion, platform, deviceToken, notifications) {
|
||||
let access = await fetchWithTimeout(`https://${server}/account/access?token=${token}&appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}`, { method: 'PUT', body: JSON.stringify(notifications) })
|
||||
let access = await fetchWithTimeout(`https://${server}/account/access?token=${token}&appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=up`, { method: 'PUT', body: JSON.stringify(notifications) })
|
||||
checkResponse(access)
|
||||
return await access.json()
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import base64 from 'react-native-base64'
|
||||
export async function setLogin(username, server, password, appName, appVersion, platform, deviceToken, notifications) {
|
||||
let headers = new Headers()
|
||||
headers.append('Authorization', 'Basic ' + base64.encode(username + ":" + password));
|
||||
let login = await fetchWithTimeout(`https://${server}/account/apps?appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}`, { method: 'POST', body: JSON.stringify(notifications), headers: headers })
|
||||
let login = await fetchWithTimeout(`https://${server}/account/apps?appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}&pushType=up`, { method: 'POST', body: JSON.stringify(notifications), headers: headers })
|
||||
checkResponse(login)
|
||||
return await login.json()
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ export function useAppContext() {
|
||||
useEffect(() => {
|
||||
|
||||
DeviceEventEmitter.addListener('unifiedPushURL', (e) => {
|
||||
Alert.alert("PUSH ENDPOINT", JSON.stringify(e));
|
||||
deviceToken.current = e.endpoint;
|
||||
});
|
||||
|
||||
(async () => {
|
||||
@ -81,6 +81,13 @@ export function useAppContext() {
|
||||
}
|
||||
|
||||
const notifications = [
|
||||
{ event: 'contact.addCard', messageTitle: 'New Contact Request' },
|
||||
{ event: 'contact.updateCard', messageTitle: 'Contact Update' },
|
||||
{ event: 'content.addChannel.superbasic', messageTitle: 'New Topic' },
|
||||
{ event: 'content.addChannel.sealed', messageTitle: 'New Topic' },
|
||||
{ event: 'content.addChannelTopic.superbasic', messageTitle: 'New Topic Message' },
|
||||
{ event: 'content.addChannelTopic.sealed', messageTitle: 'New Topic Message' },
|
||||
{ event: 'ring', messageTitle: 'Incoming Call' },
|
||||
];
|
||||
|
||||
const actions = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user