Notification using PHP and Webservice on Android

Asked

Viewed 1,672 times

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 whether it is possible to generate notifications on Android through PHP?

For example;

Tomorrow is the day of the user X go to the dentist. On the user’s phone X will appear a notification stating the commitment.

2 answers

2


It is possible yes, if you use a function in the Android application that is always run at a set time (every 1 minute, for example). This function should look up if Webservice has new notifications for that user.

Edited

I found a tutorial that shows how to consume a JSON on Android: http://www.devmedia.com.br/consumindo-json-em-aplicacoes-android/27589.
What you should do is add a method that will fetch the Webservice (I always use in REST for already knowing) always every x seconds/minutes. In the PHP application, when running the REST method (if you have something to send to the Android application), you provide the information and, after running on Android, you should remove this information from the WS (logically or physically), so that there is no duplication of information sent

Edited 2

After configuring the Androidmanifest file so that the user has access to the internet and imported the package of JSON, the method is created (in this example, it is executed every 5000 ms, that is, 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);

No 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;
  • Julyano good morning, you have some practical example of this ?

  • I will provide an example, a moment.

  • 1

    Can you illustrate with code here what is in the link? Answers that depend on links are not encouraged here, will in the future this link become inaccessible?

2

  • The problem with GCM is that it’s a paid platform and this project that I have in mind is a basic system for managing breakfast here at the company.

  • I thought your app was for testing and figuring out how to implement the notification. Although GCM has 60 free days to test, its use is actually paid for.

  • I just wanted to point out that the GCM was discontinued, favoring the FCM. If I’m not mistaken, the FCM is more accessible than the GCM, I think most of it is free (with limitations, like, 5 called per year, but free use)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.