Android Question Problem firebase

devmobile

Active Member
Licensed User
I use firebase example source for test firebase
It is ok but have a bug or other
I cannot receive push notification sometimes
Example i sent 3 message and in device i could received first message only
I need to firebase
thanks
 

devmobile

Active Member
Licensed User
Can you send the PHP page you are using? Mask sensible data, pls.
Of course
this function send push to topic(i create topic for each device with deviceid because token not generate for first run app)
this function working now but sometimes not working :(

PHP:
function send($title,$message,$type,$token,$device_id) {
   
        $data    = array('to'  => '/topics/'.$device_id , 'content_available'   => true , 'data'        => array( 'type' => $type));
      
        $api = 'AAAAn';
      
        $res2 = $this->me->db->where('sDeviceID',$device_id)->select('sToken')->get('tokens');
        if ($res2->num_rows() == 1) {
            $data['to'] = $res2->row()->sToken;
        }
      
        ob_start();
        $curl    =    curl_init('https://fcm.googleapis.com/fcm/send');
        curl_setopt($curl, CURLOPT_POST,1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,FALSE);
        curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($data));
        curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-type:application/json;charset=UTF-8','Authorization:key='.$api));
        curl_exec($curl);
        curl_close($curl);
        $res = ob_get_clean();
        return $res;

      
    }
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
PHP:
function send($title,$message,$type,$token,$device_id) {
   
        $data    = array('to'  => '/topics/'.$device_id , 'content_available'   => true , 'data'        => array( 'type' => $type));
      
        $api = 'AAAAn';
      
        $res2 = $this->me->db->where('sDeviceID',$device_id)->select('sToken')->get('tokens');
        if ($res2->num_rows() == 1) {
            $data['to'] = $res2->row()->sToken;
            ob_start();
            $curl    =    curl_init('https://fcm.googleapis.com/fcm/send');
            curl_setopt($curl, CURLOPT_POST,1);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER,FALSE);
            curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($data));
            curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-type:application/json;charset=UTF-8','Authorization:key='.$api));
            curl_exec($curl);
            curl_close($curl);
            $res = ob_get_clean();
            return $res;
        } else {
          return "NoTokenFound";    
        }      
    }
 
Upvote 0

devmobile

Active Member
Licensed User
PHP:
function send($title,$message,$type,$token,$device_id) {
  
        $data    = array('to'  => '/topics/'.$device_id , 'content_available'   => true , 'data'        => array( 'type' => $type));
     
        $api = 'AAAAn';
     
        $res2 = $this->me->db->where('sDeviceID',$device_id)->select('sToken')->get('tokens');
        if ($res2->num_rows() == 1) {
            $data['to'] = $res2->row()->sToken;
            ob_start();
            $curl    =    curl_init('https://fcm.googleapis.com/fcm/send');
            curl_setopt($curl, CURLOPT_POST,1);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER,FALSE);
            curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($data));
            curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-type:application/json;charset=UTF-8','Authorization:key='.$api));
            curl_exec($curl);
            curl_close($curl);
            $res = ob_get_clean();
            return $res;
        } else {
          return "NoTokenFound";   
        }     
    }
What is different between your code and my code?
 
Upvote 0

devmobile

Active Member
Licensed User
it only sends the curl job if a database entry is found.
No No i have token for each device in databae absolutely
I send push to device with token and if token not available yet send to topic
In each state(toekn and topic) i cannot receive push sometimes
Of course i receive all push when i use b4j tools for send push
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Tried to change device? I have a 4.2 Samsung Phone which hangs trying to receive Apps' updates and doesn't receive them till I reboot it. I suppose the Store uses the same FCM structure. I have not the same issue on other devices.
The transport of FCM goes from trasmitter to Google DB then it's sent from Google to target device. What I think that there is a difference in parameters you use in B4J and PHP. In this case your action can modify the behaviour of your device in relation to Google not your PHP page.
Forgive my poor english. What I'd is to compare packets sent by B4J and PHP: a single parameter could do the difference. At least in case the device is ok,
 
Upvote 0

devmobile

Active Member
Licensed User
Tried to change device? I have a 4.2 Samsung Phone which hangs trying to receive Apps' updates and doesn't receive them till I reboot it. I suppose the Store uses the same FCM structure. I have not the same issue on other devices.
The transport of FCM goes from trasmitter to Google DB then it's sent from Google to target device. What I think that there is a difference in parameters you use in B4J and PHP. In this case your action can modify the behaviour of your device in relation to Google not your PHP page.
Forgive my poor english. What I'd is to compare packets sent by B4J and PHP: a single parameter could do the difference. At least in case the device is ok,
Yes i try it.
I my devices have a problem(Nexus and Hawaii)
I decide to use b4j for send push because when i use it there is no any problem
 
Upvote 0

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime User
Hello, in the firemessaning service module in the app. Make sure to set the priority to 10. Nb.priority = 10, you should add the erel example. And also verifies that the notifications counter has the following variable. Dim id As Int = Rnd (1, 0x7FFFFFFF).
example:
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
 
   Log("Message arrived")
   Log($"Message data: ${Message.GetData}"$)
   Dim from As String
   Dim cola As String
   Dim nb As NotificationBuilder
   Dim imag As String
Dim id As Int = Rnd(1, 0x7FFFFFFF)

   Dim bigtext As NotificationBigTextStyle
   Dim extender As NotificationWearableExtender
    
 
    nb.Initialize
    extender.Initialize

    nb.SmallIcon = "icon"
    nb.Ticker = "Jularo"
    nb.priority = 10

 
 
    nb.setActivity(Me)
    nb.ContentTitle = Message.GetData.Get("title")
    nb.SubText = Message.GetData.Get("body")
 
    imag = Message.GetData.Get("photourl")
    nb.ContentInfo =Message.GetData.Get("user")
 

 
    nb.SubText = "Barrio Parque Jularo"
    bigtext.Initialize
    bigtext.BigContentTitle = Message.GetData.Get("title")
    bigtext.Bigtext =Message.GetData.Get("body")

    nb.SetStyle(bigtext)
    notimap.Initialize
    notimap.Put("body",Message.GetData.Get("body"))
    notimap.Put("title",Message.GetData.Get("title"))
    notimap.Put("photourl",Message.GetData.Get("photourl"))
    notimap.Put("user",Message.GetData.Get("user"))
    notimap.Put("token" ,Message.CollapseKey)
    notimap.Put("email",Message.GetData.Get("tag"))
    notimap.Put("userid",Message.GetData.Get("userid"))
    Dim archivo As String
 

 
    nb.Notify(id)
  


End Sub
 
Upvote 0
Top