<i id='tTrOt'><tr id='tTrOt'><dt id='tTrOt'><q id='tTrOt'><span id='tTrOt'><b id='tTrOt'><form id='tTrOt'><ins id='tTrOt'></ins><ul id='tTrOt'></ul><sub id='tTrOt'></sub></form><legend id='tTrOt'></legend><bdo id='tTrOt'><pre id='tTrOt'><center id='tTrOt'></center></pre></bdo></b><th id='tTrOt'></th></span></q></dt></tr></i><div id='tTrOt'><tfoot id='tTrOt'></tfoot><dl id='tTrOt'><fieldset id='tTrOt'></fieldset></dl></div>

    <legend id='tTrOt'><style id='tTrOt'><dir id='tTrOt'><q id='tTrOt'></q></dir></style></legend>
    <tfoot id='tTrOt'></tfoot>
      <bdo id='tTrOt'></bdo><ul id='tTrOt'></ul>

    <small id='tTrOt'></small><noframes id='tTrOt'>

      如何在应用程序之外创建警报对话框?

      how to create alertdialog outside of an application?(如何在应用程序之外创建警报对话框?)
          <bdo id='2iCYF'></bdo><ul id='2iCYF'></ul>
            <tbody id='2iCYF'></tbody>

          <small id='2iCYF'></small><noframes id='2iCYF'>

            1. <legend id='2iCYF'><style id='2iCYF'><dir id='2iCYF'><q id='2iCYF'></q></dir></style></legend>
              <tfoot id='2iCYF'></tfoot>

                <i id='2iCYF'><tr id='2iCYF'><dt id='2iCYF'><q id='2iCYF'><span id='2iCYF'><b id='2iCYF'><form id='2iCYF'><ins id='2iCYF'></ins><ul id='2iCYF'></ul><sub id='2iCYF'></sub></form><legend id='2iCYF'></legend><bdo id='2iCYF'><pre id='2iCYF'><center id='2iCYF'></center></pre></bdo></b><th id='2iCYF'></th></span></q></dt></tr></i><div id='2iCYF'><tfoot id='2iCYF'></tfoot><dl id='2iCYF'><fieldset id='2iCYF'></fieldset></dl></div>
                本文介绍了如何在应用程序之外创建警报对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在我的应用程序之外创建一个警报对话框.

                I want to create an alertdialog outside of my application.

                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                    builder.setTitle(Config_ConstantVariable.latest);
                    builder.setMessage(title);
                    builder.setIcon(R.drawable.push_logo);
                    builder.setCancelable(false)
                            .setPositiveButton(Config_ConstantVariable.alertbtnyes,
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {
                                            Intent intent = new Intent(context,
                                                    Main_ParticularNewsDetail.class);
                                            Bundle bundle = new Bundle();
                                            intent.putExtra("newsid", payload);
                                            intent.putExtras(bundle);
                                            context.startActivity(intent);
                                        }
                                    })
                            .setNegativeButton(Config_ConstantVariable.alertbtnno,
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {
                                            dialog.cancel();
                                        }
                                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                

                但是,context 不是一个活动,这个类是 extends BroadcastReceiver.

                However, the context is not an activity and this class is extends BroadcastReceiver.

                当我推送通知时,发生了错误,

                When I push notification, an error occured,

                06-18 18:38:08.629: E/AndroidRuntime(2402): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
                

                我看到WhatsApp可以在三星galaxy标签的应用程序外弹出对话框.

                I saw WhatsApp that can pop out the dialog outside the application in samsung galaxy tab.

                推荐答案

                我在我的应用程序中使用了相同的功能,我使用一个活动作为弹出消息,如下所示

                I am using the same functionality in my app where i used one activity as a pop up message like below

                 @Override
                public void onReceive(Context context, Intent intent) {
                
                
                    try {
                         Bundle bundle = intent.getExtras();
                         String message = bundle.getString("alarm_message");
                
                         Intent newIntent = new Intent(context, PopupActivity.class);
                         newIntent.putExtra("alarm_message", message);
                         newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                         newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                         context.startActivity(newIntent);
                        } catch (Exception e) { 
                         e.printStackTrace();
                
                        }
                }
                

                在 Popup Activity 中设计类似对话框的 UI 并将其添加到 Android Manifest.xml 中

                In the Popup Activity design the UI like the dialog box and add this in Android Manifest.xml

                 <activity android:name=".PopupActivity"
                             android:theme="@android:style/Theme.Dialog"
                             android:label="@string/label"
                             ></activity>
                

                您可以根据您的规范自定义 UI.它对我来说非常适合.希望对你有帮助.

                You can customise the UI based on your specification.Its working perfectly for me. I hope it helps.

                这篇关于如何在应用程序之外创建警报对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                Android file copy(安卓文件拷贝)
                Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                Android copy image from gallery folder onto SD Card alternative folder(Android将图像从图库文件夹复制到SD卡替代文件夹)
                Is there a tool to find unused resources in an Android project?(是否有工具可以在 Android 项目中查找未使用的资源?)
                <tfoot id='WE9OH'></tfoot>
                <legend id='WE9OH'><style id='WE9OH'><dir id='WE9OH'><q id='WE9OH'></q></dir></style></legend>

                      <i id='WE9OH'><tr id='WE9OH'><dt id='WE9OH'><q id='WE9OH'><span id='WE9OH'><b id='WE9OH'><form id='WE9OH'><ins id='WE9OH'></ins><ul id='WE9OH'></ul><sub id='WE9OH'></sub></form><legend id='WE9OH'></legend><bdo id='WE9OH'><pre id='WE9OH'><center id='WE9OH'></center></pre></bdo></b><th id='WE9OH'></th></span></q></dt></tr></i><div id='WE9OH'><tfoot id='WE9OH'></tfoot><dl id='WE9OH'><fieldset id='WE9OH'></fieldset></dl></div>

                      <small id='WE9OH'></small><noframes id='WE9OH'>

                        <bdo id='WE9OH'></bdo><ul id='WE9OH'></ul>
                            <tbody id='WE9OH'></tbody>