1. java
  2. android
  3. c#
  4. .net
  5. javascript
  6. php
  7. jquery
  8. html
  9. sql

Serviço do GCM funcionando o meu sempre apresenta o erro: SERVICE NOT AVAILABLE

Olá,

Estou com esse problema já tentei tudo e mesmo assim na mensagem continua. Já estou começando a pensar que o problema é no servidor do google. Bom segue meu codigo.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="br.com.clientechattcc"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />

    <permission android:name="br.com.clientechattcc.permission.C2D_MESSAGE" 
        android:protectionLevel="signature" />
    <uses-permission android:name="br.com.clientechattcc.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

         <!-- android:name=".appConfig.GCMBroadcastReceiver" -->
        <receiver
             android:name=".appConfig.GCMBroadcastReceiver"
             android:permission="com.google.android.c2dm.permission.SEND" >
               <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.SEND" />
               <category android:name="br.com.clientechattcc" />
            </intent-filter>
       </receiver>

       <service android:name=".appConfig.GCMIntentService" />

        <activity
            android:name="br.com.clientechattcc.activity.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

           <activity
            android:name="br.com.clientechattcc.activity.CadastrarUsuarioActivity">
           </activity>

        <activity
           android:name="br.com.clientechattcc.activity.HomeActivity">
        </activity>

    </application>

</manifest>
package br.com.clientechattcc.configgcm;

import br.com.clientechattcc.appConfig.AppConf;
import br.com.clientechattcc.enuns.GCM;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;

public class GCMBroadcastReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Log.i(AppConf.TAGLOG, GCM.ONRECEIVE.toString());

        ComponentName comp = new ComponentName(context.getPackageName(), 
                                                GCMIntentService.class.getName());

        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);

    }
}
package br.com.clientechattcc.configgcm;

import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import br.com.clientechattcc.appConfig.AppConf;
import br.com.clientechattcc.enuns.GCM;
import br.com.clientechattcc.notify.CreateNotification;

import com.google.android.gms.gcm.GoogleCloudMessaging;

public class GCMIntentService extends IntentService {

    public GCMIntentService() {
         super(GCM.GCMINTNVTSERVICE.toString());
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.i(AppConf.TAGLOG, GCM.ONHANDLEINTET.toString());

        CreateNotification notification = new CreateNotification();
        Bundle extras = intent.getExtras();

        GoogleCloudMessaging gcm = AppConf.getGCM();
        String messageType = gcm.getMessageType(intent);

        if (!extras.isEmpty()) { 

            if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
                notification.sendNotification("Send error: " + extras.toString(), this);
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
                notification.sendNotification("Deleted messages on server: " + extras.toString(),this);
            // If it's a regular GCM message, do some work.
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

                notification.sendNotification("OK!!!!!!!!!!!!!" + extras.toString(),this);
                Log.i(AppConf.TAGLOG, "Received: " + extras.toString());
            }
        }

        GCMBroadcastReceiver.completeWakefulIntent(intent);
    }
}
package br.com.clientechattcc.asynctask;

import com.google.android.gms.gcm.GoogleCloudMessaging;

import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;
import br.com.clientechattcc.appConfig.AppConf;
import br.com.clientechattcc.configgcm.ServiceGCM;
import br.com.clientechattcc.enuns.MessageApp;
import br.com.clientechattcc.serverrequest.RequestClientUsuario;

public class GetRegisterGCM  extends AsyncTask<Void, Void, String> {

    private Activity activity;

    public GetRegisterGCM(Activity activity) {
        this.activity = activity;
    }

    @Override
    protected String doInBackground(Void... params) {

         String msg = "";
         String regid = ""; 
         try { 

            ServiceGCM serviceGCM = new ServiceGCM();

            regid = serviceGCM.getRegistrationId(activity.getApplicationContext());

            if(regid.equals("")){
                 //AppConf.getGCM()
                regid = GoogleCloudMessaging.getInstance(activity.getApplicationContext()).register(AppConf.SENDER_ID);

                serviceGCM.storeRegistrationId(activity.getApplicationContext(), regid);
            }

            RequestClientUsuario client = new RequestClientUsuario();

            client.updateGCM(regid, AppConf.getDataUsuario().getUsuario());

            if(!client.getStatus())
              msg = client.getRetorno();

         } catch (Exception ex) {
            msg = MessageApp.ERRORAPP+ex.getMessage()+" / "+this.getClass().getName();
            Log.i(AppConf.TAGLOG, msg);
        }
        return msg;
    }

}
  1. Você vai ver essas setas em qualquer página de pergunta. Com elas, você pode dizer se uma pergunta ou uma resposta foram relevantes ou não.
  2. Edite sua pergunta ou resposta caso queira alterar ou adicionar detalhes.
  3. Caso haja alguma dúvida sobre a pergunta, adicione um comentário. O espaço de respostas deve ser utilizado apenas para responder a pergunta.
  4. Se o autor da pergunta marcar uma resposta como solucionada, esta marca aparecerá.
  5. Clique aqui para mais detalhes sobre o funcionamento do GUJ!

2 respostas

Não é a resposta que estava procurando? Procure outras perguntas com as tags android cloud mobile ou faça a sua própria pergunta.