마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

GCM OnRegistered 호출이 안됩니다..

0 추천

안녕하세요. GCM 푸시 테스트 중인데요.  OnRegistered를 호출 안해서 regId 등록이 안됩니다..

MainActivity 소스이구요

public class MainActivity extends Activity {

    public static String device_Id, device_Code, device_Token;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        startActivity(new Intent(this, SplashActivity.class));
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 디바이스 id 얻어오기.
        final TelephonyManager tm = (TelephonyManager) getBaseContext()
                .getSystemService(Context.TELEPHONY_SERVICE);
        final String tmDevice, tmSerial, androidId;
        tmDevice = "" + tm.getDeviceId();
        tmSerial = "" + tm.getSimSerialNumber();
        androidId = ""
                + android.provider.Settings.Secure.getString(
                getContentResolver(),
                android.provider.Settings.Secure.ANDROID_ID);
        UUID deviceUuid = new UUID(androidId.hashCode(),
                ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
        device_Id = deviceUuid.toString();
        // 디바이스 코드 (고정값 GCM)
        device_Code = Constant.device_Code;

        device_Token = GCMRegistrar.getRegistrationId(this);

        Log.d(Constant.TAG, "dvicId : " + device_Id);
        Log.d(Constant.TAG, "dvicDsCd : " + device_Code);
        Log.d(Constant.TAG, "dvicTkn : " + device_Token);
    }
}

Manifest 입니다.

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

    <!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
    <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" />

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

    <uses-feature
        android:name="android.hardware.telephony"
        android:required="false"/>

    <permission
        android:name="com.pushtest.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.pushtest.permission.C2D_MESSAGE" />

    <!-- This app has permission to register and receive data message. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!-- Network State Permissions to detect Internet status -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Permission to vibrate -->
    <uses-permission android:name="android.permission.VIBRATE" />

    <!-- Permisition to geolocation -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|screenSize"
            android:screenOrientation="portrait"
            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=".splash.SplashActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Light.NoTitleBar" >
        </activity>

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

                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.pushtest" />
            </intent-filter>
        </receiver>

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



    </application>

</manifest>

GCMIntentService OnRegister 부분입니다.

public class GCMIntentService extends GCMBaseIntentService {

    public GCMIntentService() {
        super(Constant.SENDER_ID);
    }

    /**
     * Method called on device registered
     **/
    @Override
    protected void onRegistered(Context context, String device_Token) {
        // TODO Auto-generated method stub
        if(!device_Token.equals("") || device_Token != null){
            Log.w(TAG, "onRegistered!! " + device_Token);
        }

    }

 

뭐가 문제인지 도저히 모르겠네요.. 디버깅에 걸리는것도 아니고 ㅠㅠ

도와주실 수 있나요?

양꼬양 (2,040 포인트) 님이 2015년 7월 28일 질문
양꼬양님이 2015년 7월 28일 수정

1개의 답변

0 추천

mainActivity에서 GCM을 등록해보세요.

등록 코드는 아래와 같구요 PROJECT_ID는 구글개발자콘솔에 등록한 프로젝트코드에요 ex)124125125 숫자로되있어요

그리고 아래 코드는 어싱크테스크에서 돌리셔야대여 구글플레이서비스 유효체크두 하셔야대구요.

일단 테스트로 아래코드 넣고 한번 해보세요.

GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(mContext);
String regId = gcm .register(PROJECT_ID);
 
위와같이 등록읋을시면 regId를 내려받는데 프리페이런스에 저장하셔서 사용하세요.
 
해당 regid와 구글개발자콘솔에 등록한 apikey로 gcm 태스트해볼수있어요. 푸쉬받는 리시버는 필수구요.
 
gcm message 보내는 주소 알려드릴게요 테스트함해보세요. https://gcmsender.herokuapp.com/

 

ㅁㄴㅇㄻㄴㅇㄹ 님이 2015년 7월 28일 답변
...