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

푸시 메시지 내용 수정 관련 질문드립니다

0 추천

우선 푸시 코드입니다.

 


    @Override
    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        // The getMessageType() intent parameter must be the intent you received
        // in your BroadcastReceiver.


        String messageType = gcm.getMessageType(intent);

 

        if (!extras.isEmpty()) {
            if (GoogleCloudMessaging.
                    MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                // This loop represents the service doing some work.
                for (int i=0; i<5; i++) {
                    Log.i(TAG, "Working... " + (i + 1)
                            + "/5 @ " + SystemClock.elapsedRealtime());
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                    }
                }


                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                // Post notification of received message.
                sendNotification ( extras.toString());
                Log.i(TAG, "Received: " + extras.toString());

 

            }
        }
        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);

 

 


    }

    // Put the message into a notification and post it.
    // This is just one simple example of what you might choose to do with
    // a GCM message.
    private void sendNotification(String msg) {
        mNotificationManager = (NotificationManager)
                this.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.gcm)
                        .setContentTitle("색남")
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(msg))
                        .setContentText(msg)
                        .setVibrate(new long[]{0, 500});

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());


    }

 

 

실제로 발송 시킬때는 php를 쓰고 있습니다.

 $headers = array(
            'Content-Type:application/json',
            'Authorization:key=AIzaSyB_d2TurDAw7ZZ9iJg0jLpyuenm3HibXyI'
            );
 
    // 푸시 내용, data 부분을 자유롭게 사용해 클라이언트에서 분기할 수 있음.
    $arr = array();
    $arr['data'] = array();
    $arr['data']['title'] = '푸시 테스트';
    $arr['data']['msg'] = '푸시 내용 ABCD~'; 
    
 $arr['registration_ids'][0] = $row["regid"];
 

 

 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($arr));
    $response = curl_exec($ch);
    curl_close($ch);

 

코드는 이러한데 이러면 결과가 

 

 

이렇게 납니다;; 정말 미칠것같아요 이렇게도해보고 저렇게도 해봤는데 다 실패했습니다;

 

Bundle from 이런거 다 치우고 msg , title '내용'만 발송시키는 방법이 없나요?ㅠ

껄껄앱 (1,910 포인트) 님이 2016년 2월 16일 질문

2개의 답변

0 추천
 
채택된 답변

  sendNotification ( extras.toString()); <-- bundle 을 다찍으심 ..

sadeva (21,550 포인트) 님이 2016년 2월 17일 답변
껄껄앱님이 2016년 2월 17일 채택됨
to가 아니라 get 이였네요!! 감사합니다 ^^
0 추천
제 생각에는 저렇게 나오면 거의 다된거같은데요,

앱에서 알림 띄울때 번들에서 데이터를 꺼내서 Notification에 꺼낸 데이터로 세팅하고 띄워주면 될거같은데요,

지금은 번들 자체를 보여주고있는거 아닌가요?
캬옹이 (37,920 포인트) 님이 2016년 2월 17일 답변
...