0

プラグインで Android の GCM プッシュ通知を使用しようとしています。Google サーバーから有効な登録 ID を取得しています。しかし、サーバーからデータを送信するBroadcastReceiverと、まったく呼び出されません。問題はマニフェストのアクセス許可にあると思います。これが私が使用しているマニフェストの部分です-

<receiver
android:name="com.creator.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.creator.test" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.creator.test" />
</intent-filter>
</receiver>
<service android:name="com.creator.gcm.GcmIntentService" />

<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>


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

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

ボラキャスト受信機の私のコードは、公式の Android の例から取られていますが、ここにコードがあります -

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
    private static final String TAG = "BROADCAST_TAG";
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive");
        // 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);
    }
}

インテントサービス -

public class GcmIntentService extends IntentService {

    private static native void native_notificationCallback();

    public static final int NOTIFICATION_ID = 1;
    private NotificationManager mNotificationManager;
    NotificationCompat.Builder builder;
    private static final String TAG = "INTENT_TAG";

    public GcmIntentService() {
        super("GcmIntentService");
        Log.d(TAG, "GcmIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.d(TAG, "onHandleIntent");
        Bundle extras = intent.getExtras();
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        String messageType = gcm.getMessageType(intent);

        if (!extras.isEmpty()) {
            if (GoogleCloudMessaging.
                    MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
                sendNotification("Send error: " + extras.toString());
            } else if (GoogleCloudMessaging.
                    MESSAGE_TYPE_DELETED.equals(messageType)) {
                sendNotification("Deleted messages on server: " +
                        extras.toString());
            // If it's a regular GCM message, do some work.
            } else if (GoogleCloudMessaging.
                    MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                // This loop represents the service doing some work.
                for (int i=0; i<5; i++) {
                    Log.i(TAG, "Working... " + (i+1)
                            + "/5 @ " + SystemClock.elapsedRealtime());
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                    }
                }
                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                sendNotification("Received: " + extras.toString());
                Log.i(TAG, "Received: " + extras.toString());
            }
        }
        GcmBroadcastReceiver.completeWakefulIntent(intent);
    }
    private void sendNotification(String msg) {
        Log.d(TAG, "Got Notification: "+msg);
        mNotificationManager = (NotificationManager)
                this.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, LoaderActivity.class), 0);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
        //.setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("GCM Notification")
        .setStyle(new NotificationCompat.BigTextStyle()
        .bigText(msg))
        .setContentText(msg);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }
}

インストール時に、デバイスは常に logcat でこのメッセージを生成します -

10-13 21:31:59.329: W/ActivityManager(2190): No content provider found for permission revoke: file:///data/local/tmp/Notification Example.apk
10-13 21:31:59.489: W/ActivityManager(2190): No content provider found for permission revoke: file:///data/local/tmp/Notification Example.apk
10-13 21:32:00.129: I/PackageManager(2190): Running dexopt on: com.creator.test
10-13 21:32:01.371: I/ActivityManager(2190): Force stopping package com.creator.test uid=10180
10-13 21:32:01.531: D/PackageManager(2190): New package installed in /data/app/com.creator.test-1.apk
10-13 21:32:01.531: W/PackageManager(2190): Unknown permission android.permission.ADD_SYSTEM_SERVICE in package com.android.phone
10-13 21:32:01.531: W/PackageManager(2190): Unknown permission com.google.android.providers.gmail.permission.READ_GMAIL in package com.mobisystems.fileman
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission android.permission.RECEIVE_USER_PRESENT in package com.stericsson.atservice
10-13 21:32:01.541: W/PackageManager(2190): Not granting permission android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS to package com.android.browser (protectionLevel=2 flags=0x9be45)
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.sonyericsson.android.permission.FACERECOGNITION_SERVICE in package com.sonyericsson.android.camera3d
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.android.launcher.permission.READ_SETTINGS in package com.android.settings
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.android.launcher.permission.WRITE_SETTINGS in package com.android.settings
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.sonyericsson.android.permission.FACERECOGNITION_SERVICE in package com.sonyericsson.android.camera
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.google.android.voicesearch.SHORTCUTS_ACCESS in package com.google.android.googlequicksearchbox
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.google.android.ears.permission.WRITE in package com.google.android.googlequicksearchbox
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.google.android.apps.googlevoice.permission.AUTO_SEND in package com.google.android.googlequicksearchbox
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.android.chrome.PRERENDER_URL in package com.google.android.googlequicksearchbox
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.facebook.orca.provider.ACCESS in package com.facebook.katana
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission android.permission.ACCESS_LOCATION in package com.sonyericsson.android.servicemenu
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission android.permission.ACCESS_GPS in package com.sonyericsson.android.servicemenu
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission android.permission.ACCESS_WAKE_LOCK in package com.sonyericsson.android.servicemenu
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.sonyericsson.servicemenu.permission.ACCESS_SERVICE_MENU in package com.sonyericsson.android.servicemenu
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.sony.nfx.app.irremoteservice.permission.EXECUTE_SERVICE in package com.sonyericsson.android.servicemenu
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission android.permission.FM_RADIO_RECEIVER in package com.sonyericsson.android.servicemenu
10-13 21:32:01.541: W/PackageManager(2190): Not granting permission com.sonyericsson.permission.INSTALL_APPLICATION to package com.sonyericsson.trackid (protectionLevel=2 flags=0x8be44)
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.USERAGENT in package com.sonyericsson.trackid
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.CUSTOMIZATION in package com.sonyericsson.trackid
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.sonymobile.permission.SOMC_CAMERA in package com.sonymobile.cameraautoupload
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.BLACKLISTED_USB_DEVICE in package com.sonyericsson.extras.liveware
10-13 21:32:01.541: W/PackageManager(2190): Unknown permission com.sonyericsson.music.permission.MUSICSERVICE in package com.sonyericsson.extras.liveware
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.VENDOR_BUTTON in package com.sonyericsson.extras.liveware
10-13 21:32:01.551: W/PackageManager(2190): Not granting permission android.permission.READ_LOGS to package com.stackexchange.marvin (protectionLevel=50 flags=0x8be44)
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.android.launcher.permission.READ_SETTINGS in package com.google.android.onetimeinitializer
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.android.launcher.permission.WRITE_SETTINGS in package com.google.android.onetimeinitializer
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.sonymobile.permission.READ_CONTACT_FACE_META in package com.sonymobile.photoanalyzer
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.sonymobile.permission.WRITE_CONTACT_FACE_META in package com.sonymobile.photoanalyzer
10-13 21:32:01.551: W/PackageManager(2190): Not granting permission android.permission.READ_LOGS to package com.avast.android.mobilesecurity (protectionLevel=50 flags=0x28be44)
10-13 21:32:01.551: W/PackageManager(2190): Not granting permission android.permission.MODIFY_PHONE_STATE to package com.avast.android.mobilesecurity (protectionLevel=18 flags=0x28be44)
10-13 21:32:01.551: W/PackageManager(2190): Not granting permission android.permission.DUMP to package com.avast.android.mobilesecurity (protectionLevel=50 flags=0x28be44)
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission android.permission.ACCESS_SUPERUSER in package com.avast.android.mobilesecurity
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.sony.walkman.media.service.permission.ACCESS_TEMPORARY_PROVIDER in package com.sonyericsson.video
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.sony.walkman.media.service.permission.ACCESS_DRM in package com.sonyericsson.video
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.FMRADIO in package com.sonyericsson.dlna
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.google.android.gallery3d.permission.PICASA_STORE in package com.google.android.apps.plus
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission com.google.android.hangouts.START_HANGOUT in package com.google.android.apps.plus
10-13 21:32:01.551: W/PackageManager(2190): Not granting permission android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS to package com.android.vending (protectionLevel=2 flags=0xabec5)
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission android.permission.MANAGE_USERS in package com.android.vending
10-13 21:32:01.551: W/PackageManager(2190): Unknown permission android.permission.INTERACT_ACROSS_USERS in package com.android.vending
10-13 21:32:01.551: W/PackageManager(2190): Not granting permission android.permission.WRITE_SECURE_SETTINGS to package com.android.vending (protectionLevel=50 flags=0xabec5)
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.CRASHSMS in package com.sonyericsson.crashmonitor
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sonymobile.dlna.permission.READ_DATA in package com.sonyericsson.album
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sonyericsson.extras.liveview.permission.LIVEVIEW_API in package com.sonyericsson.androidapp.timescapefeedsplugin
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.CUSTOMIZATION in package com.sonyericsson.androidapp.retaildemo
10-13 21:32:01.561: W/PackageManager(2190): Not granting permission android.permission.CLEAR_APP_USER_DATA to package com.sonyericsson.androidapp.retaildemo (protectionLevel=2 flags=0xbe45)
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sony.walkman.database.media.permission.WRITE_MEDIA_METADATA in package com.sonyericsson.metadatacleanup
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sony.walkman.database.media.permission.ACCESS_DRM_METADATA in package com.sonyericsson.metadatacleanup
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sony.walkman.permission.ACCESS_MEDIA in package com.sonyericsson.metadatacleanup
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.timhoeck.android.eventghost.permission.SEND_EVENTS in package de.gavitec.semc
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.CUSTOMIZATION in package com.sonyericsson.textinput.chinese
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.android.vending.billing.IBillingAccountService.BIND2 in package com.google.android.gsf.login
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.CONTACTS_PICK_CONVERSATIONS_TARGET in package com.sonyericsson.conversations
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sonyericsson.pws.permission.EMERGENCY_ALERTS in package com.sonyericsson.conversations
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.ACCESS_PROTECTED_CONTACTS in package com.sonyericsson.conversations
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.CUSTOMIZATION in package com.sonyericsson.textinput.uxp
10-13 21:32:01.561: W/PackageManager(2190): Unknown permission android.permission.INTERACT_ACROSS_USERS in package com.google.android.gms
10-13 21:32:01.571: W/PackageManager(2190): Unknown permission android.permission.LOCATION_HARDWARE in package com.google.android.gms
10-13 21:32:01.571: W/PackageManager(2190): Unknown permission android.permission.GET_APP_OPS_STATS in package com.google.android.gms
10-13 21:32:01.571: W/PackageManager(2190): Unknown permission android.permission.UPDATE_APP_OPS_STATS in package com.google.android.gms
10-13 21:32:01.671: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.FMRADIO in package com.sonyericsson.music
10-13 21:32:01.671: W/PackageManager(2190): Not granting permission com.google.android.gm.permission.READ_GMAIL to package com.sonyericsson.music (protectionLevel=2 flags=0x8be45)
10-13 21:32:01.671: W/PackageManager(2190): Unknown permission com.sony.walkman.database.media.permission.WRITE_MEDIA_METADATA in package com.sonyericsson.music
10-13 21:32:01.671: W/PackageManager(2190): Unknown permission com.sony.walkman.database.media.permission.ACCESS_DRM_METADATA in package com.sonyericsson.music
10-13 21:32:01.671: W/PackageManager(2190): Unknown permission com.sony.walkman.media.service.permission.ACCESS_TEMPORARY_PROVIDER in package com.sonyericsson.music
10-13 21:32:01.671: W/PackageManager(2190): Unknown permission com.sonymobile.dlna.permission.READ_DATA in package com.sonyericsson.music
10-13 21:32:01.671: W/PackageManager(2190): Not granting permission android.permission.BIND_DEVICE_ADMIN to package com.android.email (protectionLevel=2 flags=0xbbc45)
10-13 21:32:01.681: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.CUSTOMIZATION in package com.sonyericsson.android.pobox
10-13 21:32:01.681: W/PackageManager(2190): Unknown permission com.android.launcher.permission.PRELOAD_WORKSPACE in package com.google.android.partnersetup
10-13 21:32:01.681: W/PackageManager(2190): Not granting permission android.permission.DEVICE_POWER to package com.sonyericsson.android.socialphonebook (protectionLevel=2 flags=0x8be45)
10-13 21:32:01.681: W/PackageManager(2190): Not granting permission android.permission.ACCESS_DRM to package com.sonyericsson.android.socialphonebook (protectionLevel=2 flags=0x8be45)
10-13 21:32:01.681: W/PackageManager(2190): Unknown permission com.sonyericsson.phone.CALL_SCREEN_SHORTCUT in package com.sonyericsson.android.socialphonebook
10-13 21:32:01.681: W/PackageManager(2190): Unknown permission com.android.email.permission.ACCESS_GAL_PROVIDER in package com.sonyericsson.android.socialphonebook
10-13 21:32:01.681: W/PackageManager(2190): Unknown permission com.sonyericsson.aab.READ_ICE_CONTACTS in package com.sonyericsson.android.socialphonebook
10-13 21:32:01.681: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.CONTACTS_PICK_CONVERSATIONS_TARGET in package com.sonyericsson.android.socialphonebook
10-13 21:32:01.681: W/PackageManager(2190): Not granting permission com.sonyericsson.permission.IDD to package com.sonyericsson.android.socialphonebook (protectionLevel=2 flags=0x8be45)
10-13 21:32:01.681: W/PackageManager(2190): Unknown permission com.google.android.providers.gmail.permission.READ_GMAIL in package com.mobisystems.office
10-13 21:32:01.681: W/PackageManager(2190): Not granting permission android.permission.WRITE_MEDIA_STORAGE to package com.mobisystems.office (protectionLevel=18 flags=0x1cbe44)
10-13 21:32:01.681: W/PackageManager(2190): Not granting permission android.permission.WRITE_SECURE_SETTINGS to package com.whatsapp (protectionLevel=50 flags=0xbe44)
10-13 21:32:01.691: W/PackageManager(2190): Not granting permission android.permission.BROADCAST_SMS to package com.sonyericsson.nfc (protectionLevel=2 flags=0x8be45)
10-13 21:32:01.691: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.CONTACTS_PICK_CONVERSATIONS_TARGET in package com.sonyericsson.nfc
10-13 21:32:01.691: W/PackageManager(2190): Not granting permission android.permission.ACCESS_BLUETOOTH_SHARE to package com.sonyericsson.nfc (protectionLevel=2 flags=0x8be45)
10-13 21:32:01.691: W/PackageManager(2190): Unknown permission com.sonyericsson.permission.ACCESS_PROTECTED_CONTACTS in package com.sonyericsson.nfc
10-13 21:32:01.691: W/PackageManager(2190): Unknown permission android.provider.Telephony.SMS_RECEIVED in package com.sonyericsson.nfc
10-13 21:32:01.691: W/PackageManager(2190): Not granting permission com.google.android.gm.permission.READ_GMAIL to package com.sonyericsson.nfc (protectionLevel=2 flags=0x8be45)
10-13 21:32:01.691: W/PackageManager(2190): Unknown permission com.vodafone.vodafone360updates.permission.SHOW_SETUP_WIZARD in package com.sonyericsson.setupwizard
10-13 21:32:01.691: W/PackageManager(2190): Unknown permission com.sonyericsson.timescape.permission.TIMESCAPE_SETTINGS in package com.sonyericsson.settings
10-13 21:32:01.691: W/PackageManager(2190): Unknown permission com.sonyericsson.eventstream.twitterplugin.AUTHENTICATION in package com.sonyericsson.eventstream.twitterpostviewer
10-13 21:32:01.701: W/PackageManager(2190): Not granting permission android.permission.DEVICE_POWER to package com.sonyericsson.organizer (protectionLevel=2 flags=0x8bc45)
10-13 21:32:01.701: W/PackageManager(2190): Unknown permission com.sony.walkman.database.media.permission.ACCESS_DRM_METADATA in package com.sonyericsson.musicvisualizer
10-13 21:32:01.701: W/PackageManager(2190): Unknown permission andriod.permission.MANAGE_USB in package com.sonyericsson.usbux

私はこれらの権限のほとんどを使用していません。問題があれば、デバッグにSony Xperia Pを使用しています。デバイスを GCM サーバーに登録すると、これが logcat に出力されます -

10-13 21:33:21.509: W/GCM(2527): DIR: /data/data/com.google.android.gms/app_APP /data/data/com.google.android.gsf
10-13 21:33:21.959: D/BROADCAST_TAG(5204): onReceive
10-13 21:33:21.969: D/INTENT_TAG(5204): GcmIntentService
10-13 21:33:21.979: D/INTENT_TAG(5204): onHandleIntent
10-13 21:35:36.611: I/Icing.InternalIcingCorporaProvider(3573): Updating corpora: A: MAYBE, C: FORCE_ALL
10-13 21:35:38.653: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089
10-13 21:35:38.653: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089
10-13 21:35:38.693: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089
10-13 21:35:38.693: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089
10-13 21:35:38.703: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089
10-13 21:35:38.703: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089
10-13 21:35:38.723: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089
10-13 21:35:38.723: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089
10-13 21:35:38.753: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089
10-13 21:35:38.753: W/ActivityManager(2190): Permission denied: checkComponentPermission() owningUid=10089

したがって、出力によると、これはある種の権限の問題だと思います。私が使用している送信者 ID とブラウザ キーは正しく、すでに何度も確認しています。
ここで注目すべき興味深い点の 1 つは、デバイスを GCM に登録すると、broadcastIntent が呼び出されることです。理由はわかりませんが、まったく呼び出されません。

SO自体について多くの回答を確認しましたが、この問題を解決するのに役立つ回答はありませんでした。この問題を解決するための助けをいただければ幸いです。過去2週間、解決しようとしています。

PS: 問題を理解するためにさらに情報が必要な場合はお知らせください。

更新:- 初めて BroadcastReceiver が呼び出されると、登録 ID が返されます。メソッドはこれextras.toString()を返しました -

Bundle[{registration_id=****my_device_reg_id**, android.support.content.wakelockid=1}]
4

1 に答える 1