从通知中打开对话框 [英] Open Dialog from Notification
问题描述
当我点击通知时,我想打开一个对话框,我只打印1个字符串。
现在,我无法使用它,这里做什么,当我创建通知:
...
Intent notificationIntent = new Intent(上下文,{如何打开对话框});
...
然后1个按钮,例如OK,这将关闭
请帮助我。
谢谢。
我在我的一个应用程序中做到这一点。在通知中,您需要执行以下操作:
PendingIntent contentIntent = PendingIntent.getActivity(context,0,
new Intent(com.yourcompany.yourapp.MAINACTIVITY)。putExtra(fromnotification,true);
在你的主要活动中使用onResume()方法检查这个额外的东西:
@Override
public void onResume()
{
super.onResume();
if(getActivity()。getIntent()。getBooleanExtra(fromnotification,false)== true)
{
getActivity()。getIntent()。removeExtra(fromnotification);
startActivityForResult(
new Intent(com.yourcompany.yourapp.DIALOGACTIVITY),123);
}
}
此代码显示带有对话框的活动风格,但没有理由不能创建一个对话框内的if语句虽然。
I have a notification displayed. Now I want this to happen:
When I click on the notification, I would like to open a Dialog, where I print only 1 string.
Now, I can't work it out, what to do here, when I create notification:
...
Intent notificationIntent = new Intent(context, {how to open dialog});
...
Then 1 button, for example "OK", which will close the dialog.
Please, help me.
Thanks.
I do exactly this in one of my apps. In the notification you need to do something like this:
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent("com.yourcompany.yourapp.MAINACTIVITY").putExtra("fromnotification", true);
Inside your main activity use the onResume() method to check for this extra:
@Override
public void onResume()
{
super.onResume();
if (getActivity().getIntent().getBooleanExtra("fromnotification", false) == true)
{
getActivity().getIntent().removeExtra("fromnotification");
startActivityForResult(
new Intent("com.yourcompany.yourapp.DIALOGACTIVITY"), 123);
}
}
This code displays an activity with a dialog style, but there is no reason why it can't create a dialog inside the if statement though.
这篇关于从通知中打开对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!