php - Firebase Messaging service not working sometimes -
i'm developing taxi booking application using android & im new firebase. developed 2 android application using firebase message service. create 2 firebase apps in same firebase project @ firebase concole & use 2 keys 2 android modules(passenger module & driver module).
- passenger app/module. (device a)
- driver app/module. (device b)
- php application on server handle requests.
i need send firebase message device device b. application work fine. sometimes, didn't receive firebase message to, onmessagereceived(remotemessage remotemessage)
method on device b. success json array server device a, {"multicast_id":4784526898355206621,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1503395492396343%2f40e632f9fd7ecd"}]}
what doing wrong? please me resolve issue.
these related files used in 2 apps.
androidmenifest.xml - passenger application (device a)
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cdc.passenger"> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <activity ... /> ... <meta-data android:name="com.google.android.geo.api_key" android:value="aiza......................................................" /> <!-- services --> <service android:name="com.cdc.passenger.myfirebasemessagingservice" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="com.google.firebase.messaging_event" /> </intent-filter> </service> <service android:name="com.cdc.passenger.myfirebaseinstanceidservice"> <intent-filter> <action android:name="com.google.firebase.instance_id_event" /> </intent-filter> </service> </application> </manifest>
androidmenifest.xml - driver application (device b)
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cdc.driver"> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:screenorientation="portrait" android:supportsrtl="true" android:theme="@style/apptheme"> <activity ... /> ... <service android:name="com.cdc.driver.driver.myfirebasemessagingservice" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="com.google.firebase.messaging_event" /> </intent-filter> </service> <service android:name="com.cdc.driver.driver.myfirebaseinstanceidservice"> <intent-filter> <action android:name="com.google.firebase.instance_id_event" /> </intent-filter> </service> <meta-data android:name="com.google.android.geo.api_key" android:value="aiza.........................................................................." /> </application> </manifest>
buildgradle - project scope
dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.google.gms:google-services:3.1.0' }
buildgradle - passenger module
apply plugin: 'com.android.application' android { compilesdkversion 24 buildtoolsversion "24.0.1" defaultconfig { applicationid "com.cdc.passenger" minsdkversion 17 targetsdkversion 24 versioncode 21 versionname '1.9' } ... } dependencies { // compile filetree(dir: 'libs', include: ['*.jar']) compile files('libs/commons-net-3.4.jar') testcompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:support-v4:24.1.1' compile 'com.android.support:design:24.1.1' compile 'com.android.support:cardview-v7:24.1.1' compile 'com.android.support:recyclerview-v7:24.1.1' compile 'com.google.firebase:firebase-core:9.4.0' compile 'com.google.firebase:firebase-messaging:9.4.0' } repositories{ ... } apply plugin: 'com.google.gms.google-services'
buildgradle - driver module
apply plugin: 'com.android.application' android { compilesdkversion 24 buildtoolsversion "24.0.1" defaultconfig { applicationid "com.cdc.driver" minsdkversion 17 targetsdkversion 24 versioncode 5 versionname '1.4' } ... } dependencies { // compile filetree(dir: 'libs', include: ['*.jar']) compile files('libs/commons-net-3.4.jar') testcompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:support-v4:24.1.1' compile 'com.android.support:design:24.1.1' compile 'com.android.support:cardview-v7:24.1.1' compile 'com.google.firebase:firebase-core:9.4.0' compile 'com.google.firebase:firebase-messaging:9.4.0' compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' } repositories{ ... } apply plugin: 'com.google.gms.google-services'
server-side code
$fields = array( 'registration_ids' => array($token), 'priority' => 'high', 'time_to_live' => 5, 'data' => array("ride" => $rideid, "pickup" => $pickup) ); $headers = array( 'authorization:key=' . applicationcontroller::$api_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_verifyhost, 0); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_postfields, json_encode($fields)); $result = curl_exec($ch); if ($result === false) { die('curl failed: ' . curl_error($ch)); } curl_close($ch); echo $result;
wiki
Comments
Post a Comment