Android GCM未收到我的手机

时间:2016-03-02 11:39:13

标签: android google-cloud-messaging apple-push-notifications gcmlistenerservice

在触发从WebService到我的手机的推送通知时,我的Eclipse日志中出现此错误。喜欢这个..

  

03-02 16:14:41.839:V / GCMBroadcastReceiver(28046):onReceive:   com.google.android.c2dm.intent.RECEIVE 03-02 16:14:41.839:   V / GCMBroadcastReceiver(28046):GCM IntentService类:   com.gcm.gcmtest.GCMIntentService 03-02 16:14:41.839:   V / GCMBaseIntentService(28046):获取唤醒锁无法启动   service Intent {act = com.google.android.c2dm.intent.RECEIVE flg = 0x10   PKG = com.gcm.gcmtest   cmp = com.gcm.gcmtest / com.activate.gcm.GCMIntentService(有附加内容)}   U = 0:未找到

我的计划:

Context mContext = MainActivity.this;

GoogleCloudMessaging gcm;

String gcmRegId;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    registerPushNotifInBackground();

}
private void registerPushNotifInBackground() {

    new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {

            gcm = GoogleCloudMessaging.getInstance(mContext);

            String msg = "";

            try {

                if (gcm == null) {

                    gcm = GoogleCloudMessaging.getInstance(mContext);
                }

                Log.v("gcm", "---GCMRegistrar.isRegistered(mContext):"
                        + GCMRegistrar.isRegistered(mContext));

                gcmRegId = GCMRegistrar.getRegistrationId(mContext);

                Log.v("gcm", "---GCMRegistrar.getRegistrationId(mContext):"
                        + gcmRegId);

                if (gcmRegId.equals("")) {

                    Log.v("gcm",
                            "---------if.. gcm.register:GCMIntentService.SENDER_ID:"
                                    + GCMIntentService.SENDER_ID);

                    gcmRegId = gcm.register(GCMIntentService.SENDER_ID);

                } else {

                    Log.v("gcm",
                            "----else---GCMRegistrar.getRegistrationId...-");

                    gcmRegId = GCMRegistrar.getRegistrationId(mContext);

                }
                Log.v("gcm", "----------------regId:" + gcmRegId);

            } catch (Exception ex) {

                ex.printStackTrace();

                Log.v("gcm",
                        "----------------ex:" + ex.getLocalizedMessage());
            }
            return msg;
        }

        @Override
        protected void onPostExecute(String msg) {

        }
    }.execute(null, null, null);
}

清单许可:

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />
<uses-feature
    android:name="android.hardware.telephony"
    android:required="false" />
<uses-feature
    android:name="android.hardware.location"
    android:required="false" />
<uses-feature
    android:name="android.hardware.location.gps"
    android:required="false" />
<uses-feature
    android:name="android.hardware.location.network"
    android:required="false" />

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

<uses-permission android:name="com.gcm.gcmtest.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

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

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


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



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

            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.gcm.gcmtest" />
        </intent-filter>
    </receiver>

    <service
        android:name="com.gcm.gcmtest.GCMIntentService"
        android:enabled="true" />
</application>

0 个答案:

没有答案