Notification using PHP and WebService on Android

2

I have a project in mind but I have not yet started to develop it in practice. The idea is to develop a PHP + MySql Web system and an Android application using WebServices. My question is if it is possible to generate notifications on Android through PHP?

For example;

Tomorrow is the day for user X to go to the dentist. In the phone of user X a notification will appear informing the appointment.

    
asked by anonymous 10.05.2016 / 13:39

2 answers

2

Yes, it is possible if you use a function in the Android application that always runs at a set time (every 1 minute, for example). This function should check whether the WebService has new notifications for this user.

Edited

I found a tutorial that shows how to consume JSON in Android: link . Home What you should do, is to add a method that fetches the WebService (I always use it in REST because I already know it) every x seconds / minutes every time. In the PHP application, when you run the REST method (if you have something to send to the Android application), it makes the information available and, after running Android, you must remove this information from the WS (logically or physically), so there is no duplicity of submitted information

Edited 2

After setting the AndroidManifest file so that the user has access to the internet and imported the package from the JSON , the method is created (in this example, it runs every 5000 ms, or be, every 5 seconds):

new Timer().scheduleAtFixedRate(new TimerTask() {
      @Override
      public void run() {
          super.onCreate(savedInstanceState);
          new DownloadJsonAsyncTask()
              .execute("http://meusite.com.br.meujson.json");
      }
}, 0, 5000);

In WS PHP :

<?php

$objetosJson = [];
$objetosJson[] = array('Objeto' => array('id' => 1, 'nome' => 'João'));
$objetosJson[] = array('Objeto' => array('id' => 2, 'nome' => 'Maria'));
echo json_encode($objetosJson);die;
    
10.05.2016 / 13:42
2

I use google GCM, where you can send push notifications to the user's device.

Here's an example of how to use PHP link

And here's another example: link

    
10.05.2016 / 14:17