Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.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 通知的待定内容不';别再叫我的活动了_Android_Notifications_Android Pendingintent - Fatal编程技术网

Android 通知的待定内容不';别再叫我的活动了

Android 通知的待定内容不';别再叫我的活动了,android,notifications,android-pendingintent,Android,Notifications,Android Pendingintent,我希望接收推送通知(c2dm)接收显示通知。此通知将启动一个显示弹出窗口的活动,其中包含PendingEvent。单击“确定”按钮时,此弹出窗口将启动我的应用程序 以下是接收推送通知时执行的代码: private void dealMessage(Context context, Intent intent) { try { String message = intent.getExtras().getString("message");

我希望接收推送通知(c2dm)接收显示通知。此通知将启动一个显示弹出窗口的活动,其中包含PendingEvent。单击“确定”按钮时,此弹出窗口将启动我的应用程序

以下是接收推送通知时执行的代码:

private void dealMessage(Context context, Intent intent)
{       
    try
    {
        String message = intent.getExtras().getString("message");

        Log.v("testc2dm","message :     [" + message + "]");

        //create bean of my Notification
        NotificationPush notif = new NotificationPush();
        notif.init((JSONObject)JSONValue.parse(message));

        //create PendingIntent
        Intent intentDialog = new Intent(context, DialogActivity.class);
        intentDialog.putExtra("notif", notif);
        int requestCode= (int) System.currentTimeMillis();
        PendingIntent pi = PendingIntent.getActivity(context, requestCode, intentDialog, PendingIntent.FLAG_ONE_SHOT);

        //Create the Notification
        Notification n = new Notification();
        n.flags |= Notification.FLAG_SHOW_LIGHTS; // allume l'écran
        n.flags |= Notification.FLAG_AUTO_CANCEL; // fait disparaitre automatiquemet la notif apres un clic dessus
        n.defaults = Notification.DEFAULT_ALL;
        n.icon = R.drawable.icon;
        n.when = System.currentTimeMillis();
        n.setLatestEventInfo(context, "Mon titre", notif.getTitre(), pi);

        //add my Notification
        NotificationManager notificationManager = (NotificationManager)context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(ID_NOTIFICATION, n);
    }
    catch(Exception e)
    {
        Log.e("testc2dm","error :       [" + e.getMessage() + "]");
        e.printStackTrace();
    }
}
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    Log.v("testc2dm","DialogActivity oncreate()");

    //recovery of my bean Notification
    Intent intentParam = getIntent();
    NotificationPush notif = (NotificationPush)intentParam.getSerializableExtra("notif");

    if(notif != null)
    {           
        Log.v("testc2dm","notif => titre [" + notif.getTitre() + "] -- msg [" + notif.getMessage() + "] -- type [" + notif.getType() + "]");

        //display popup
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(notif.getMessage());
        builder.setTitle(notif.getTitre());
        builder.setCancelable(false);
        builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() 
        {
            public void onClick(DialogInterface dialog, int id) 
            {
                if(!TestC2DMActivity.appIsRunning)
                {
                    //launch first Activity of my application
                    Intent intent = new Intent(DialogActivity.this, TestC2DMActivity.class);
                    startActivity(intent);
                }
            }
        });
        builder.show();
    }
}
这是我的活动,显示弹出窗口并启动我的应用程序:

private void dealMessage(Context context, Intent intent)
{       
    try
    {
        String message = intent.getExtras().getString("message");

        Log.v("testc2dm","message :     [" + message + "]");

        //create bean of my Notification
        NotificationPush notif = new NotificationPush();
        notif.init((JSONObject)JSONValue.parse(message));

        //create PendingIntent
        Intent intentDialog = new Intent(context, DialogActivity.class);
        intentDialog.putExtra("notif", notif);
        int requestCode= (int) System.currentTimeMillis();
        PendingIntent pi = PendingIntent.getActivity(context, requestCode, intentDialog, PendingIntent.FLAG_ONE_SHOT);

        //Create the Notification
        Notification n = new Notification();
        n.flags |= Notification.FLAG_SHOW_LIGHTS; // allume l'écran
        n.flags |= Notification.FLAG_AUTO_CANCEL; // fait disparaitre automatiquemet la notif apres un clic dessus
        n.defaults = Notification.DEFAULT_ALL;
        n.icon = R.drawable.icon;
        n.when = System.currentTimeMillis();
        n.setLatestEventInfo(context, "Mon titre", notif.getTitre(), pi);

        //add my Notification
        NotificationManager notificationManager = (NotificationManager)context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(ID_NOTIFICATION, n);
    }
    catch(Exception e)
    {
        Log.e("testc2dm","error :       [" + e.getMessage() + "]");
        e.printStackTrace();
    }
}
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    Log.v("testc2dm","DialogActivity oncreate()");

    //recovery of my bean Notification
    Intent intentParam = getIntent();
    NotificationPush notif = (NotificationPush)intentParam.getSerializableExtra("notif");

    if(notif != null)
    {           
        Log.v("testc2dm","notif => titre [" + notif.getTitre() + "] -- msg [" + notif.getMessage() + "] -- type [" + notif.getType() + "]");

        //display popup
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(notif.getMessage());
        builder.setTitle(notif.getTitre());
        builder.setCancelable(false);
        builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() 
        {
            public void onClick(DialogInterface dialog, int id) 
            {
                if(!TestC2DMActivity.appIsRunning)
                {
                    //launch first Activity of my application
                    Intent intent = new Intent(DialogActivity.this, TestC2DMActivity.class);
                    startActivity(intent);
                }
            }
        });
        builder.show();
    }
}
我的问题是:如果我的应用程序将通过接收推送(c2dm>通知>PendingEvent>DialogActivity>TestC2DMActivity)启动,然后接收下一次推送,则通知将显示良好,但单击通知不会启动DialogActivity。而当应用程序正常启动时(应用程序图标),则一切正常

我觉得如果我的应用程序是由我的PendingEvent启动的,那么这个PendingEvent就不再需要启动DialogActivity了。。为什么

非常感谢您的帮助,并为我糟糕的英语感到抱歉。

我有解决方案:

intentDialog.setAction("" + Math.random());

无论如何谢谢你