Как установить значок уведомления FCM

Я использую php curl для отправки уведомлений. Помогите мне добавить значок в мое уведомление.
Я использую ниже PHP-код для push-уведомлений

Использование плагина Cordova Firebase в моем приложении
Работа над гибридным приложением с использованием PhoneGap, Cordova
В настоящее время просто делаю это для Android-приложения

function sendFCM($title,$message, $id,$additional_data="") {
$url = 'https://fcm.googleapis.com/fcm/send';

$fields = array (
'registration_ids' => $id, //Device Ids
'data' => array (

"additional_data"  =>$additional_data
),
'notification' => array(
'title' => $title,
'body' => $message,
'sound'=> 'default'
)
);
$fields = json_encode ( $fields );

$headers = array (
'Authorization: key=' . "Server Key",
'Content-Type: application/json'
);

$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );

$result = curl_exec ( $ch );
curl_close ( $ch );
}

0

Решение

Ты это:

Код push-уведомления fcm с помощью приложения для Android

Мы создали для классов:

  • Класс уведомлений
  • Класс обслуживания токенов

Класс обслуживания уведомлений Fcm

public class NotificationService extends FirebaseMessagingService {
private static final String TAG = "FCM";

boolean notification, sound, vibration;

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, remoteMessage.getNotification().getBody()+"");
Log.d(TAG, remoteMessage.getNotification().getTitle()+"");
Log.d(TAG, remoteMessage.getFrom()+"");
Log.d(TAG, remoteMessage.getData()+"");
addNotification(remoteMessage.getNotification());
}
private void addNotification(RemoteMessage.Notification data) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)  // add icon
.setContentTitle(data.getTitle()+"")
.setAutoCancel(true)
.setContentText(data.getBody()+"");
Notification notification = new Notification();

if (sound)
notification.defaults |= Notification.DEFAULT_SOUND;

if (vibration)
notification.defaults |= Notification.DEFAULT_VIBRATE;

builder.setDefaults(notification.defaults);
Intent notificationIntent = new Intent(this, Service_confirmedActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_ONE_SHOT);
builder.setContentIntent(contentIntent);

// Add as notification
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
}

Класс обслуживания токена

public class TokenService extends FirebaseInstanceIdService {
private static final String TAG = "FirebaseIDService";
public static String DeviceToc = "";
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.e(TAG, "Refreshed token: " + refreshedToken);

DeviceToc = refreshedToken;
Log.e("DeviceToc",""+refreshedToken);
sendRegistrationToServer(refreshedToken);
}

private void sendRegistrationToServer(String token) {

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0);

SharedPreferences.Editor editor = pref.edit();
editor.putString("deviceToc",token); // Storing string
editor.commit();

Log.i("token",""+token);

}
}

это помогает тебе

0

Другие решения

Других решений пока нет …