-1

私のアプリにFCMを実装しようとしましたが、問題があります。私のカスタムコードを呼び出す代わりに、通知を送信するたびに、デフォルトの通知が表示されます。私は間違って何をしていますか?Android FCMがトリガーサービスで通知を表示

ものはサービスです:

<service 
    android:name="com.backgroundws.MyFirebaseMessagingService"> 
    <intent-filter> 
     <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
    </intent-filter> 
</service> 
<service 
    android:name="com.backgroundws.MyFirebaseInstanceIDService"> 
    <intent-filter> 
     <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
    </intent-filter> 
</service> 

そして、これが私ののJavaコードです:

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     Log.d("MyFirebaseMessaging", "GotMessage"); 
     WSListener.sendEvent(this, "Push"); 
    } 

} 

そして、私は、デバイス上の通知を得るとき、私はlogcatでこれを参照してください。

I/SendBroadcastPermission: action:com.google.android.gms.gcm.ACTION_SCHEDULE, mPermissionType:0 
I/SendBroadcastPermission: action:com.google.android.gms.gcm.ACTION_SCHEDULE, mPermissionType:0 

これは私が通知を送る方法です:

function send_gcm_notify($reg_id, $message, $url, $key) { 
     $fields = array(

      'to'     => $reg_id , 
      'priority'    => "high", 
      "notification"   => array("body"=>$message), 
      'data'     => array("url"=> $url) 
     ); 

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

     $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); 
     if ($result === FALSE) { 
      //die('Problem occurred: ' . curl_error($ch)); 
     } 
     curl_close($ch); 
     return $result; 

    } 

もちろん私はテストして、サービスへのパスが正しいです。

+0

通知データは、最も重要な情報を追加してください。 –

+0

が編集されました。私は通知を取得するので、キーとreg_idは正しいです。 –

+0

私はあなたのPHPを解読したくありません。実際のjsonデータを表示する –

答えて

関連する問題