Don*_*rty 17 android dialog native screen popup
我想知道是否有人可以判断如何在原生Android屏幕上弹出对话框屏幕?
我目前有一个应用程序可以捕获拨出呼叫并停止呼叫,然后我想弹出一个对话框,该对话框将从拨号器屏幕接管并提醒用户已尝试呼叫被阻止并允许他们从中获取一些新选项对话框.
我知道有些人会说我应该使用通知,但我知道它并不是它应该工作的方式,我需要能够在呼叫被困时弹出一个对话框.
到目前为止,这是我的对话框代码
AlertDialog LDialog = new AlertDialog.Builder(context)
.setTitle("Call Blocked")
.setMessage("Call Blocked, reroute call?")
.setPositiveButton("ok", null).create();
LDialog.show();
Run Code Online (Sandbox Code Playgroud)
我认为我必须以某种方式获得拨号屏幕的上下文?
任何人都可以提供任何帮助和帮助或指向教程的链接?
提前致谢
tbr*_*lle 59
对于我的应用程序,我使用了Dialog主题的活动.您可以在清单文件中声明主题:
<activity android:name="PopupActivity"
android:launchMode="singleInstance" android:excludeFromRecents="true"
android:taskAffinity="" android:theme="@android:style/Theme.Dialog" />
Run Code Online (Sandbox Code Playgroud)
launcheMode="singleInstance",taskAffinity=""如果您的弹出窗口与主应用程序分离.否则,用户可以单击后退按钮并返回到应用程序的上一个活动.excludeFromRecents="true" 避免弹出窗口出现在最近的任务中(长按回家)theme="@android:style/Theme.Dialog" 设置Dialog主题.如何在代码中获得等效的launchMode = singleTask
我还没有看到有关如何以编程方式设置这些标志的明确解释,因此我将在此处包含我的结果。tldr:你必须设置 FLAG_ACTIVITY_NEW_TASK 和 FLAG_ACTIVITY_MULTIPLE_TASK。
如果您直接从您的应用程序启动它,您的对话框将出现在您应用程序的最后一个 Activity 之上。但是,如果您使用 AlarmManager 的 PendingIntent 广播来启动您的“对话框”,则您有时间切换到不同的应用程序,以便您可以看到您的“对话框”将出现在其他应用程序上,如果样式设置适当以显示什么是它的背后。
显然,人们应该负责何时适合在其他应用程序之上显示对话框。
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// you have to set these flags here where you receive the broadcast
// NOT in the code where you created your pendingIntent
Intent scheduledIntent = new Intent(context, AlertAlarmActivity.class);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivity(scheduledIntent);
Run Code Online (Sandbox Code Playgroud)