I'm totally lost on this, got like 20 tabs open to solve this annoying puzzle. I've gone though multiple tutorials but none of them answer where to define a channel ID and how to send a notification through PHP to it.
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
showNotification(remoteMessage!!.data["message"]!!)
}
private fun showNotification(message: String) {
val i = Intent(this, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)
val builder = NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("FCM Test")
.setContentText(message)
.setLargeIcon(BitmapFactory.decodeResource(resources, com.amoflirt.amoflirt.R.drawable.ic_vip_heart))
.setSmallIcon(com.amoflirt.amoflirt.R.drawable.common_google_signin_btn_icon_dark)
.setContentIntent(pendingIntent)
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.notify(0, builder.build())
}
No matter what I change here, it doesn't effect the way the notifications are sent/received, like setLargeIcon isn't adding anything.
This is the PHP:
define( 'API_ACCESS_KEY', 'xxx');
$msg = array(
'body' => $body,
'title' => $title,
);
$fields = array(
'to' => $token,
'notification' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
echo $result;
curl_close( $ch );
I tried all kind of "solutions" to add a large icon and vibration on both sides (android and PHP) but none of them works. But the most important is I don't understand how to add the damn channels and how to send the notifications to them. Why do android as a whole have to be such a mess and pile of dog crap :(
Thanks in advance