Android推送通知不适用于版本号为4.4.2的型号 - vs450pp

时间:2016-03-04 07:36:00

标签: android push-notification

我在Android手机上获得给定型号的推送通知,但是当我点击通知时,它消失了,并且没有打开应用程序。如果有人让我摆脱那些问题,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

尝试以下代码可能适合您。

Intent intent = new Intent(this, MainActivity.class); //define your application activity name which you want to open.
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);


        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("Application Title")
                .setContentText(message)
                .setContentIntent(pIntent)
                .setSound(soundUri); //This sets the sound to play

        notificationManager.notify(0, mBuilder.build());