2012-10-17 3 views
0

GCM을 구현하려고합니다.android 용 GCM을 구현하는 데 도움이 필요합니다.

나는 모두 Google 규정으로 구현했습니다. 장치를 등록 할 때 수신기에 콜백이 적용되지 않습니다. GCMIntentService 클래스에는 onError()도 없습니다.

GCMIntentService도 생성되지 않습니다.

다음

내 코드는 .... 여기

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.roconmachine.gcm" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="8"/> 

    <uses-permission android:name="android.permission.READ_PHONE_STATE"/> 

    <permission android:name="com.roconmachine.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
    <uses-permission android:name="com.roconmachine.gcm.permission.C2D_MESSAGE" /> 

    <!-- App receives GCM messages. --> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <!-- GCM connects to Google Services. --> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <!-- GCM requires a Google account. --> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <!-- Keeps the processor from sleeping when a message is received. --> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 


    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".NewGCMActivity" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > 
      <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 

      </intent-filter> 
     </receiver> 

     <service android:name=".services.GCMIntentService" android:enabled="true"/> 
    </application> 
</manifest> 

는 확인

/* 
* Copyright 2012 Google Inc. 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
* http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 
package com.roconmachine.gcm.services; 



import android.content.Context; 
import android.content.Intent; 
import android.widget.Toast; 
import com.google.android.gcm.GCMBaseIntentService; 

/** 
* {@link IntentService} responsible for handling GCM messages. 
*/ 
public class GCMIntentService extends GCMBaseIntentService { 

    public GCMIntentService() { 
     super("873601972999"); 
    } 

    @Override 
    protected void onRegistered(Context context, String registrationId) { 
     Toast.makeText(this, "onRegistered", Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    protected void onUnregistered(Context context, String registrationId) { 
     Toast.makeText(this, "onUnregistered", Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    protected void onMessage(Context context, Intent intent) { 
     Toast.makeText(this, "onMessage", Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    protected void onDeletedMessages(Context context, int total) { 
     Toast.makeText(this, "onDeletedMessages", Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    public void onError(Context context, String errorId) { 
     Toast.makeText(this, "onError", Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    protected boolean onRecoverableError(Context context, String errorId) { 
     Toast.makeText(this, "onRecoverableError", Toast.LENGTH_LONG).show(); 
     return super.onRecoverableError(context, errorId); 
    } 


} 


package com.roconmachine.gcm; 

import com.google.android.gcm.GCMRegistrar; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 

public class NewGCMActivity extends Activity { 
    private Button btnGetRegister; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     btnGetRegister = (Button)findViewById(R.id.button1); 
     btnGetRegister.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       register(); 
      } 
     }); 
    } 

    private void register() 
    { 
     GCMRegistrar.checkDevice(this); 
     GCMRegistrar.checkManifest(this); 

     if (GCMRegistrar.getRegistrationId(this).equals("")) { 
      GCMRegistrar.register(this, "873601972999"); 
     } else 
     { 
      Toast.makeText(this, "already register", Toast.LENGTH_LONG).show(); 
     } 
    } 
} 

답변

0

입니다. 조류가 보이는 것으로 특별한 오류는 없습니다. 바보 같은 것을 시도해 볼 수 있습니까? GCMIntentService를 서비스 패키지에 넣었습니다. 주 패키지에 보관하고 한 번 테스트 해 주실 수 있습니까?

+1

실제로는 주요 패키지에있었습니다. 결과가 없습니다. – roconmachine

+0

Broadcast Receiver

0

당신은 당신의 수신기에 카테고리를 추가 할 필요가

<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > 
     <intent-filter> 
     <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
     <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
     <category android:name="com.roconmachine.gcm" /> 
     </intent-filter> 
    </receiver> 

또한 응용 프로그램 패키지에 서비스를 이동해야이 문서는 말한다 :

이 의도 서비스가 GCMBroadcastReceiver (에 의해 호출됩니다 이것은 GCM 라이브러리에 의해 제공됩니다). com.google.android.gcm.GCMBaseIntentService의 서브 클래스 여야하며 공용 생성자 을 포함해야하며 my_app_package.GCMIntentService로 지정해야합니다 (GCMBroadcastReceiver의 서브 클래스를 사용하지 않는 한 서비스의 이름을 지정하는 데 사용 된 메소드를 오버라이드하지 않습니다).

+0

의 IntentFiltere에이 라인을 추가합니다.이 \t \t <의도 필터> \t \t <액션 안드로이드 : 이름 = "com.google.android.c2dm.intent.RECEIVE"/> \t \t <동작 로이드 이름 = "com.google.android.c2dm.intent.REGISTRATION"/> \t \t <카테고리 로이드 이름 = "com.roconmachine.gcm"/> \t \t \t \t roconmachine

+0

테스트 결과는 무엇입니까 ?? –

관련 문제