Giter VIP home page Giter VIP logo

gcm's Introduction

Gcm

O que devo alterar antes de testar o projeto?

1 - No arquivo string.xml você irá alterar os atributos "sender_id" e "sender url".

    <string name="sender_id">Project number - Google API console</string>
    <string name="sender_url">http://[your URL]/gcmserver.php</string>

2 - Na classe "GcmHelper.java" você irá criar a sua rotina de registro no método "toSendRegistrationIdServer"

    private static void toSendRegistrationIdServer(Context context, String key) throws IOException {

        try {
            URL url = new URL(context.getString(R.string.sender_url));

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);

            OutputStream os = connection.getOutputStream();
            os.write(("acao=registrar&regId=" + key).getBytes());
            os.flush();
            os.close();
            connection.connect();
            int responseCode = connection.getResponseCode();
            if (responseCode != HttpURLConnection.HTTP_OK) {
                throw new RuntimeException("Error saving server");
            }
        }catch (Exception e){
            e.getStackTrace();
        }
    }

3 - Caso não tenho um back-end pronto, você pode utilizar o arquivo gcmserver.php para fazer os seus testes. Lebrando que você deve informar sua Chave de API criada no Console Google Api Ex: "AIzaSyB-yNd_TuJWh1urQo45w_9pziIMyO360n9". Criar chave de Api

Será preciso criar um arquivo chamado "dispositivos.txt" no mesmo local do gcmserver.php pois, ele irá guardar todos os Ids registrados para o envio da mensagem já que não foi utilizando um banco de dados.

4 - Depois de efetuar o registro do usuário, você pode utilizar o arquivo index.html para fazer o envio das mensagens.

Documentação: Google Cloud Messaging
Crédito especial: Eduardo Gorio

Espero que esse projeto ajude você e muitos outros :D

gcm's People

Contributors

gorio avatar zirouan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.