无法打开通知点击活动

时间:2016-05-12 08:19:59

标签: android android-activity push-notification google-cloud-messaging

我想根据收到的通知内容打开不同的课程。我可以在通知点击时打开MainActivity类,但不能打开OpenActivityOne。不知道原因。

private void sendNotification(String msg) {
Log.d(TAG, "Preparing to send notification...: " + msg);

    mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    if(msg.equalsIgnoreCase("Call")){
        System.out.println("Inside iffffffffffffffffffffff");
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, OpenActivityOne.class), 0);

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

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

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

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

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

    Log.d(TAG, "Notification sent successfully.");
}

OpenActivityOne.java

 public class OpenActivityOne extends Activity {
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        Toast.makeText(getApplicationContext(), "Open OpenActivityOne",
                Toast.LENGTH_LONG).show();
        }
 }

1 个答案:

答案 0 :(得分:0)

尝试以下

AndroidManifiest.xml

中的android:exported="true" 中添加标记
<activity
        android:name="com.your.OpenActivityOne"
        android:exported="true" >
.
.
</activity>

onRenderEye