Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

No Sound and vibration #242

Closed
omaisali opened this issue Oct 19, 2015 · 16 comments
Closed

No Sound and vibration #242

omaisali opened this issue Oct 19, 2015 · 16 comments

Comments

@omaisali
Copy link

Hi,

I am able to receive the message from server when app is running. but not getting any sound and vibration nor any notification.

@macdonst
Copy link
Member

@omaisali platform? plugin version? payload sent to device?

@omaisali
Copy link
Author

i am able to receive the registration id from gcm to my app. how to sent platform, plugin version, payload to the device?

My code is like:

var push = PushNotification.init({ "android": {"senderID": "48XXXXXXXXXX6", "icon": "phonegap", "iconColor": "blue"},
"ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } );

@macdonst
Copy link
Member

@omaisali I meant, what platform are you testing on, iOS or Android? What version of the plugin are you using? What does the JSON you are sending to the device from the push service look like?

@omaisali
Copy link
Author

Android, plugin 1.3.0,

I am just sending registration id to my server in POST and want to test the response.

// php code is here.

    function send_notification($registation_ids, $message) {
    // include config


    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';

    $fields = array(
        'registration_ids' => $registation_ids,
        'data' => $message,
    );

$googlekey="AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX4";

    $headers = array(
        'Authorization: key='. $googlekey,
        'Content-Type: application/json'
    );
    // Open connection
    $ch = curl_init();

    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    // Execute post
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }

    // Close connection
    curl_close($ch);
    echo $result;
     $Response = array('success'=>true, 'array'=>$result); //<--- Success 
                        echo json_encode($Response); 
}

if($_POST['id']){
$gcm_regid = $_POST['id'];
$registation_ids = array($gcm_regid);
$message =array("product" => "shirt");
send_notification($registation_ids, $message);
}

@macdonst
Copy link
Member

@omaisali when you get the notification is the app in the foreground? If so you won't get sound or notification unless you do it yourself. When the app is in the background the notification gets put in the shade and it should vibrate and ding. Lemme know.

@omaisali
Copy link
Author

as soon as i receive the registration id, i am sending that registration id to server and server response. I am not getting any msg but the alert which i have set. check my code.

         var push = PushNotification.init({ "android": {"senderID": "4XXXXXXXXXX6", "icon": "phonegap", "iconColor": "blue"},
                         "ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } );

                    push.on('registration', function(data) {
                        // data.registrationId
                        //alert(data.registrationId);
                            var postData = "id="+data.registrationId;
                                           $.ajax({
                                            cache: false,
                                            type: 'POST',
                                            url: "http://XXXXXXX.net/XXXX.php",
                                            beforeSend: function() { toastLong('Please wait...'); },
                                            complete: function(){  },
                                            data: postData,
                                            success: function(data) {
                                               // PROCESS DATA HERE
                                                    //alert(data);

                                            },
                                            error: function(data) {
                                               //PROCESS HERE FOR FAILURE
                                               toast("Check Network");
                                            }
                                        });
                    });

                    push.on('notification', function(data) {
                        alert("You have new message");
                        // data.title,
                        // data.count,
                        // data.sound,
                        // data.image,
                        // data.additionalData
                    });

                    push.on('error', function(e) {
                        // e.message
                    });

@omaisali
Copy link
Author

n just get this alert("You have new message");

@macdonst
Copy link
Member

@omaisali right because your app is in the foreground and this is expected behaviour. Mimimize/put the app in the background and send a push. You will get sound.

@omaisali
Copy link
Author

you mean i need to make any event or any timer to send the request to the server when app is in background. thn i will get notification?

@macdonst
Copy link
Member

@omaisali here are the steps so you will have your device vibrate/play sound on notification.

  1. start your app.
  2. successfully get registration ID
  3. hit the HOME button to put the app in the background
  4. send a push from your service to the device.
  5. a notification shows up in the shade and should vibrate/play sound

When you app is in the foreground it is up to you if you want to vibrate or play a sound. You get to choose how to respond to the push.

Make sense?

@omaisali
Copy link
Author

ok. i think now i got the point. leme try that.

@omaisali
Copy link
Author

I used node-gcm to send notification.

it is working and showing this.

{ multicast_id: 8737520860603611000,
success: 1,
failure: 0,
canonical_ids: 0,
results: [ { message_id: '0:1445402589283049%39597f64f9fd7ecd' } ] }
{ message_id: 6134494132970507000 }

but no notification . app is in the background

@macdonst
Copy link
Member

@omaisali what data are you sending to the device?

@omaisali
Copy link
Author

message.addData('key1', 'msg1');

when i open the app, i receive the alert. but when app is in the background, no notification or nothing.

@omaisali
Copy link
Author

once i changed the code in the GCMIntentService by the suggestion of someone on stackoverflow. but when i change back to original. I am getting notifications now.

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants