java - GCM android 接收广播 Intent 时出错 { act=PATH.DISPLAY_MESSAGE flg=0x10 (有额外内容)

标签 java android

我无法修复此问题,消息到达设备,但当出现通知时,应用程序崩溃并出现此错误 ->

接收广播 Intent 时出错 { act=PATH.DISPLAY_MESSAGE flg=0x10(有额外内容)

我已经发布了部分代码,如果有必要我可以发布更多

感谢大家

大卫

通知生成

    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);      

            }

留言

@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 无效显示消息

       // 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);

        }

list

<?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)

最佳答案

它可以注释此 Controller 行。

@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);
    }

关于java - GCM android 接收广播 Intent 时出错 { act=PATH.DISPLAY_MESSAGE flg=0x10 (有额外内容),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21032045/

相关文章:

android - 播放媒体文件时出错

android - 在 Android 中的三个 Activity 之间传递包

java - 恢复 ArrayList 中的 CheckBox 状态永远不会将 CheckBox 设置为已选中

java - m2e: 包含 java _sources_ 的文件夹需要被多个 m2e 项目使用

java - Java:使用javazoom时控制台停止工作

java - hibernate - 第二个查询给出未知服务请求

java - 如何检索 firebase 实时数据库中的值

android - 如何获得 Android 设备的唯一 ID?

android - 如何在android上发送假电话广播

android - RecyclerView 错误?