简体   繁体   中英

GCM android Error receiving broadcast Intent { act=PATH.DISPLAY_MESSAGE flg=0x10 (has extras)

Iḿ having troubles to fix this, the message arrive to the device, but when it appear the notification, the app crash with this error ->

Error receiving broadcast Intent { act=PATH.DISPLAY_MESSAGE flg=0x10 (has extras)

I have posted some parts of the code, if it's neccesary I can post more

Thanks to all

David

NOTIFICATION GENERATE

    private static void generateNotification(Context context, String message) {
            int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
            NotificationManager notificationManager = (NotificationManager)
                    context.getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notification = new Notification(icon, message, when);

            String title = context.getString(R.string.app_name);

                Intent notificationIntent = new Intent(context, MainActivity.class);
                // set intent so it does not start a new activity
                notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                        Intent.FLAG_ACTIVITY_SINGLE_TOP);
                PendingIntent intent =
                        PendingIntent.getActivity(context, 0, notificationIntent, 0);
                notification.setLatestEventInfo(context, title, message, intent);
                notification.flags |= Notification.FLAG_AUTO_CANCEL;

                // Play default notification sound
                notification.defaults |= Notification.DEFAULT_SOUND;

                //notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");

                // Vibrate if vibrate is enabled
                notification.defaults |= Notification.DEFAULT_VIBRATE;
                notificationManager.notify(0, notification);      

            }

On Message

@Override
    protected void onMessage(Context context, Intent intent) {

        if(aController == null)
            aController = (Controller) getApplicationContext();

        Log.i(TAG, "Received message");
        String message = intent.getExtras().getString("price");

        aController.displayMessageOnScreen(context, message);
        // notifies user
        generateNotification(context, message);
    }

CONTROLLER VOID display Message

       // Notifies UI to display a message.
       void displayMessageOnScreen(Context context, String message) {

            Intent intent = new Intent(Config.DISPLAY_MESSAGE_ACTION);
            intent.putExtra(Config.EXTRA_MESSAGE, message);

            // Send Broadcast to Broadcast receiver with message
            context.sendBroadcast(intent);

        }

MANIFEST

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

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

    <application
        android:name="PATH.Controller"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <activity
            android:name="PATH.MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </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="PATH" />
            </intent-filter>
        </receiver>

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

        <activity
            android:name="PATH.SplashScreen"
            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="com.google.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

    </application>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- GCM connects to Internet Services. -->
    <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" />

    <!-- Creates a custom permission so only this app can receive its messages. -->
    <permission
        android:name="PATH.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

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

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

</manifest>



        01-09 22:03:21.315: E/AndroidRuntime(13801): java.lang.RuntimeException: Error receiving broadcast Intent { act=PATH.DISPLAY_MESSAGE flg=0x10 (has extras) } in PATH.MainActivity$1@41a10b28
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at android.os.Handler.handleCallback(Handler.java:605)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at android.os.Handler.dispatchMessage(Handler.java:92)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at android.os.Looper.loop(Looper.java:137)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at android.app.ActivityThread.main(ActivityThread.java:4517)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at java.lang.reflect.Method.invokeNative(Native Method)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at java.lang.reflect.Method.invoke(Method.java:511)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at dalvik.system.NativeStart.main(Native Method)
    01-09 22:03:21.315: E/AndroidRuntime(13801): Caused by: java.lang.NullPointerException
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at PATH.MainActivity$1.onReceive(MainActivity.java:140)
    01-09 22:03:21.315: E/AndroidRuntime(13801):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)

It works comenting this controller lines.

@Override
    protected void onMessage(Context context, Intent intent) {

        /*if(aController == null)
            aController = (Controller) getApplicationContext();*/

        Log.i(TAG, "Received message");
        String message = intent.getExtras().getString("price");

       // aController.displayMessageOnScreen(context, message);
        // notifies user
        generateNotification(context, message);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM