0

GCM이 작동하는 방식을 이해하려고합니다. 이렇게하려면 http://developer.android.com/이 제안하는 코드를 'GCM 클라이언트 구현'섹션에 복사하여 붙여 넣으십시오.android - classnotfoundexception - 신비한

서버 작품에서 메시지를 내보내지만, 내 클라이언트 응용 프로그램이 메시지를 수신 할 때, 그것은 나를이되는 이야기, 충돌 : 사람의

내가 인터넷에서 비슷한 문제를 검색
E/AndroidRuntime(5722): java.lang.RuntimeException: Unable to instantiate receiver 
com.test.testnotification3.GcmBroadcastReceiver: java.lang.ClassNotFoundException: Didn't 
find class "com.test.testnotification3.GcmBroadcastReceiver" on path: 
/data/app/com.test.testnotification3-2.apk 

, 많은 것 매니페스트의 문제점 (매니페스트의 잘못된 패키지 이름)으로 인해이 오류가 발생합니다. 하지만 내 매니페스트를 확인하고 확인을 것 같다 :

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

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="com.test.testnotification3.permission.C2D_MESSAGE" /> 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="19" /> 

<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" /> 

    <receiver 
     android:name="com.test.testnotification3.GcmBroadcastReceiver" 
     android:permission="com.google.android.c2dm.permission.SEND" > 
     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 

      <category android:name="com.test.testnotification3" /> 
     </intent-filter> 
    </receiver> 

    <service android:name="com.test.testnotification3.GcmIntentService" /> 

    <activity 
     android:name="com.test.testnotification3.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> 
</application> 

당신이 어떤 생각 ... 덕분에 많이있는 경우!

편집 : 패키지 이름이 변경 이후, 나는 수신기의 "핵심"에 의해 "com.test.testnotification3"을 대체 물론

package core; 

import android.app.Activity; 
import android.content.ComponentName; 
import android.content.Context; 
import android.content.Intent; 
import android.support.v4.content.WakefulBroadcastReceiver; 

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { 
@Override 
public void onReceive(Context context, Intent intent) { 
    // Explicitly specify that GcmIntentService will handle the intent. 
    ComponentName comp = new ComponentName(context.getPackageName(), 
      GcmIntentService.class.getName()); 
    // Start the service, keeping the device awake while it is launching. 
    startWakefulService(context, (intent.setComponent(comp))); 
    setResultCode(Activity.RESULT_OK); 
    } 

} 

: 여기 내 GcmBroadcastReceiver입니다.

+0

com.test.testnotification3.GcmBroadcastReceiver의 소스를 볼 수 있습니까? –

+0

매니페스트에'com.test.testnotification3.permission.C2D_MESSAGE' 권한에 대한 정의가 없습니다. 귀하의 질문에 그것을 포함하는 것을 잊어 버렸습니까? 아니면 실제로 매니 페스트에서 빠져 있습니까? – Eran

답변

1

수신자를 다른 패키지에 넣어야합니다. 기본 패키지에 있으면 시스템에서 인스턴스를 생성 할 수 없습니다.

+0

당신이 옳았습니다, 그것이 충돌의 이유였습니다. 하지만 충돌이 없다고하더라도, 내가 알았던대로 알림을받지 못합니다. 그러나 다른 문제가 있습니다. 솔루션을 찾지 못하면 다시 돌아올 것입니다! 고마워요! –

관련 문제