Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android启动intent不会';Don’不要采取行动_Android_Android Activity_Android Notifications - Fatal编程技术网

Android启动intent不会';Don’不要采取行动

Android启动intent不会';Don’不要采取行动,android,android-activity,android-notifications,Android,Android Activity,Android Notifications,我正在处理推送通知。接收和显示通知当前正在工作,但单击事件的作用不正常 int NOTIFICATION_ID = 1593; NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.notificat

我正在处理推送通知。接收和显示通知当前正在工作,但单击事件的作用不正常

int NOTIFICATION_ID = 1593;

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.notification, title, System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        Intent notificationIntent =  new Intent(this, MyMainActivity.class);
        notificationIntent.putExtra("test", "test");
        notificationIntent.setAction("load_notifications");

        PendingIntent intentNotification = PendingIntent.getActivity(this, 999, notificationIntent, 0);
        notification.setLatestEventInfo(this, title,  body, intentNotification);
        notificationManager.notify(NOTIFICATION_ID, notification);
这就是我显示通知的方式,它还包括启动/恢复我的主要活动

但是,如果我在应用程序中单击通知,putExtra(“测试”、“测试”)和setAction似乎没有效果。如果我的应用程序不工作,从通知启动它可以正常工作

在我的主要活动中,我的onResume功能:

public void onResume() {
        super.onResume();

        if(this.getIntent().getAction().equalsIgnoreCase("load_notifications")) {
//Do stuff
            }


    }
我的应用程序配置如下:

 <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Activity"
            android:label="@string/app_name" 
            android:configChanges="orientation"
            android:launchMode="singleInstance"
            >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Push notifications -->

        <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.app.android" />
            </intent-filter>
        </receiver>

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

    </application>

答案可能在这里:

API 16中引入了通知操作。

这意味着您应该将目标SDK设置为16或更高

但是,只有果冻豆和上面的可以利用通知操作-确保在这些平台上测试此功能


NotificationCompat.Builder负责生成与它运行的任何API兼容的通知,因此,如果您要支持冰淇淋三明治和更旧的,请继续使用它。如果没有,只需使用Notification.Builder即可(当然,在更改目标SDK之后)

我会尝试输入一些日志输出,以检查它是否根本没有进入那里,或者它是否只是没有进入if循环。也许将操作加载到一个变量并将其打印出来?我删除了代码块的日志调用。活动保持为MAIN,而不是新设置的“load_notifications”,并且我添加的测试变量只是null。