2

我的应用程序正在发送通知。我想在用户检查通知并单击通知时实现我想在我的应用程序主屏幕上打开一个弹出窗口。这有点像我的主屏幕保持原样但弹出up会在它面前打开。提前致谢

4

4 回答 4

2

你需要一个Broadcast a intent和一个Intent Receiver

下面是我的create Notification代码。当用户单击通知图标时,您将需要广播意图。

    // create NotificationManager..
    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = new Notification(R.drawable.icon, null,
            System.currentTimeMillis());

    // create intent that will be broadcast.
    Intent i = new Intent();
    i.setClassName(this, BReceiver.class.getName());    
    i.setAction("Test");

    PendingIntent contentIntent = PendingIntent.getBroadcast(this, 0, 
            i, 0);
    notification.setLatestEventInfo(this, null, null, contentIntent);
    mNotificationManager.notify(0, notification);

下面是我的BroadCast Receiver

public class BReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        Log.d("Test", "########## intent action "+ intent.getAction());
        Toast.makeText(context, "Hi", Toast.LENGTH_LONG).show();

    }

}

当您单击通知图标时,将显示吐司。无论您在哪个屏幕上,只要用户单击通知图标,都会显示吐司。

于 2012-11-05T08:16:50.233 回答
1

把这个

 android:theme="@android:style/Theme.Dialog"

意味着你的目标活动

于 2012-11-05T06:41:41.290 回答
0

If you're basically asking about HOW to open the dialog (which I'm assuming you've created as an activity) upon clicking the notification, then check out the Notification docs regarding the addAction method in the Notification.Builder class. It allows you to launch any intent you specify upon clicking the notification.

于 2012-11-05T06:52:56.600 回答
0

尝试使用 Alert Builder,这是一段代码片段,

new AlertDialog.Builder(this).
            setCancelable(false).
            setTitle("Title for popup").
            setMessage("Show Message here").
            setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    System.exit(0);
                }
            }).create().show();
于 2012-11-05T06:31:33.157 回答