广播意图已取消。 Android GCM

时间:2013-08-12 21:18:54

标签: java android eclipse google-cloud-messaging

我一直在努力解决这个错误,我只是放弃了。每次我尝试使用GCM发送消息时,LogCat上都会显示此错误。我没做什么?我已按照Android示例设置GCM通知。 这是LogCat错误

编辑:消息实际通过,但我不认为此错误是正常的。

08-12 17:13:15.888: W/GTalkService(2237): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE cat=[com.testing.encuesta] (has extras) }

的AndroidManifest.xml

<permission android:name="com.testing.encuesta.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.testing.encuesta.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.testing.encuesta.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=".Inicio">
    </activity>

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

          <action android:name="com.google.android.c2dm.intent.RECEIVE" />
          <category android:name="com.testing.encuesta" />
      </intent-filter>
      <intent-filter>
          <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
          <category android:name="com.testing.encuesta" />
      </intent-filter>

    </receiver>

我的班级GCMBroadcastReceiver

public class GCMBroadcastReceiver extends BroadcastReceiver  {

@Override
public void onReceive(Context context, Intent intent) {
            try {
                String action=intent.getAction();
                if(action.equals("com.google.android.c2dm.intent.REGISTRATION"))
                {
                    String registrationID=intent.getStringExtra("registration_id");
                    Log.d("ID",registrationID);
                    String error=intent.getStringExtra("error");
                    String unregistered=intent.getStringExtra("unregistered");

                }
                else if(action.equals("com.google.android.c2dm.intent.RECEIVE"))
                {
                    String data1=intent.getStringExtra("data1");
                    String data2=intent.getStringExtra("data2");
                    Toast.makeText(context, data1, Toast.LENGTH_LONG);

                }
            } catch (Exception e) {
                Log.d("Error", "error en C2DM"+e.toString());

            }
}

1 个答案:

答案 0 :(得分:7)

修正了,你只需要添加setResultCode(Activity.RESULT_OK);在onReceive()的末尾;方法