Skip to content

zirouan/Gcm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Projeto utilizando GCM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages