How to avoid displaying push notification in notification bar when app is already in foreground in android

You must Login before you can answer or comment on any questions.

Hi I am developing a application for android using ACS push notifications and I am able to successfully registered for ACS and to send notifications. But my problem is when my application is already in foreground and if a push notification arrives at that time it displays only in notification bar and then again I need to go to notification bar and click on notification to come back to the app. Isn't there any method of avoid it means directly fetching notification details when I am already in foreground.

Thanks in advance

— asked 10 months ago by Nivedita N
0 Comments

1 Answer

Hi Nivedita! I think it in device settings to show notifications as banner or alert.

I want to ask one thing.

are you sending notifications to devices from php server?

— answered 10 months ago by Abdus Sattar
answer permalink
3 Comments
  • No I am sending notifications through ACS web console

    — commented 10 months ago by Nivedita N

  • OK, I want to send push notification to android devices from php server but it is not working. can you please help me out to send push notifications from php?

    here is my code

    $tmp_fname = "cookie.txt";
    $curl_handle = curl_init('https://api.cloud.appcelerator.com/v1/users/login.json?key=uGDhfoFYdIwwyCKQMzKlSuNIPxl3CBSd');
    curl_setopt($curl_handle, CURLOPT_COOKIEJAR, $tmp_fname);
    curl_setopt($curl_handle, CURLOPT_POST, 1);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl_handle, CURLOPT_COOKIEFILE, $tmp_fname);
    $post_array = array('login' => 'abs', 'password' => '123456');
    curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post_array);
    $output = curl_exec($curl_handle);
    //$session = json_decode($output);
    print_r($output);
    $json = '{"badge": 1,"sound": "default","alert" : "Abdul Sattar Testing"}';
    $Curl_Session2 = curl_init('https://api.cloud.appcelerator.com/v1/push_notification/notify.json?key=uGDhfoFYdIwwyCKQMzKlSuNIPxl3CBSd&to_ids=ND1TQ9BM8TW4GYASMP2MJ84');
    curl_setopt($Curl_Session2, CURLOPT_COOKIEFILE, "$tmp_fname");
    curl_setopt($Curl_Session2, CURLOPT_COOKIEJAR, "$tmp_fname");
    curl_setopt($Curl_Session2, CURLOPT_POST, 1);
    curl_setopt($Curl_Session2, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($Curl_Session2, CURLOPT_POSTFIELDS, "channel=friend_request&payload=" . $json);
    curl_setopt($Curl_Session2, CURLOPT_FOLLOWLOCATION, 1);
    $res2 = curl_exec($Curl_Session2);
    $response = curl_getinfo($Curl_Session2);
    print_r($res2);
    echo '<br /><br />';
    print_r($response);
    curl_close($Curl_Session2);

    — commented 10 months ago by Abdus Sattar

  • When you are sending notification to only one device use the parameter 'to_id' instead of to_ids. So your http request should be like https://api.cloud.appcelerator.com/v1/push_notification/notify.json?key=uGDhfoFYdIwwyCKQMzKlSuNIPxl3CBSd&to_id=ND1TQ9BM8TW4GYASMP2MJ84'. Hope it will help

    — commented 10 months ago by Nivedita N

Your Answer

Think you can help? Login to answer this question!