마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

push알림 아이콘 php사용

0 추천

사물에서 이벤트 발생 시 php로 푸시 알림을 안드로이드앱에 보내는구조인데

아이콘을 어떻게 설정할 수 있나요??

 

$notification = array('title' =>$title , 'text' => '''sound' => 'default''badge' => '1'); 

$arrayToSend = array('registration_ids' => $registration_ids'notification' => $notification,'priority'=>'high'); 

            $json = json_encode($arrayToSend); $headers = array(); 

            $headers[] = 'Content-Type: application/json'

            $headers[] = 'Authorization: key='$serverKey

            $ch = curl_init(); 

            curl_setopt($ch, CURLOPT_URL, $url); 

            curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST"); 

            curl_setopt($ch, CURLOPT_POSTFIELDS, $json); 

            curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

            //Send the request 

            $response = curl_exec($ch);

            //Close request 

            if ($response === FALSE) { die('FCM Send Error: ' . curl_error($ch)); }

            curl_close($ch); 

show7777 (1,170 포인트) 님이 2021년 9월 27일 질문

2개의 답변

+2 추천
 
채택된 답변

개발자 문서에 관련 내용이 나오는데요.

https://firebase.google.com/docs/cloud-messaging/send-message#example-notification-message-with-platform-specific-delivery-options

Example: notification message with color and icon options

This example send request sends a common notification title and content to all platforms, but it also sends some platform-specific overrides to Android devices.

For Android, the request sets a special icon and color to display on Android devices. As noted in the reference for AndroidNotification, the color is specified in #rrggbb format, and the image must be a drawable icon resource local to the Android app.

제가 제대로 이해했는지 모르겠는데, 아래 샘플처럼  noficifation 노드 안에 icon 필드를 추가해서 거기에 안드로이 앱에서 사용하는 drawable 의 이름을 설정하는 것 같네요..

아래는 Node.js 샘플입니다. 

// Node.js
const topicName = 'industry-tech';

const message = {
  notification: {
    title: '`$FooCorp` up 1.43% on the day',
    body: 'FooCorp gained 11.80 points to close at 835.67, up 1.43% on the day.'
  },
  android: {
    notification: {
      icon: 'stock_ticker_update', // <- 요기
      color: '#7e55c3'
    }
  },
  topic: topicName,
};

admin.messaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });
 

 

해당 문서를 잘 살펴보시고 파이어베이스 샘플(Github에 파이어베이스가 제공하는 데모 프로젝트가 있어요)도 찾아보시면 될 것같습니다.

spark (226,420 포인트) 님이 2021년 9월 28일 답변
show7777님이 2021년 9월 28일 채택됨
0 추천
매니패스트 기본아이콘 바꾸기도있어요 
<meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/notification_icon" />
<meta-data android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/google_blue" />
익명사용자 님이 2021년 9월 28일 답변
...