GithubHelp home page GithubHelp 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]/</string>

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

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

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(context.getString(R.string.sender_url))
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        GcmRetrofit gcmRetrofit = retrofit.create(GcmRetrofit.class);
        Call<String> venuesCall = gcmRetrofit.toSendRegistration("registrar", key);
        venuesCall.enqueue(new Callback<String>() {

            @Override
            public void onResponse(retrofit.Response<String> response, Retrofit retrofit) {

                if (response != null){
                    saveRegistrationId(context, key);
                    listener.toRegister(key, true);
                }
            }

            @Override
            public void onFailure(Throwable t) {
            }
        });
    }

3 - Na classe "GcmRetrofit.java" você irá informar os parametros utilizado para efetuar o registro

    public interface GcmRetrofit {
        @FormUrlEncoded
        @POST("gcmserver.php")
        Call<String> toSendRegistration(@Field("acao") String action,
                                        @Field("regId") String id);
    }

4 - 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.

5 - 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

zirouan avatar gorio avatar

Stargazers

 avatar Pedro Paulo Amorim avatar Santhyago avatar Daniel Baccin avatar

Watchers

 avatar Santhyago avatar  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.