如何打开android的警告对话框系统级 [英] How to open Alert DIalog System level in android
问题描述
我有打开一个警告对话框,当蓝牙设备连接/断开连接的应用程序。 警报对话框通过连接一个BroadcastReceiver蓝牙设备的触发。
我想打开一个警告对话框,这样,如果我打开我的应用程序的(应用程序A)>长preSS首页>去一个不同的应用程序(应用程序B),蓝牙设备连接 - >我的提醒从应用程序A将被显示在附录二之上。
这是怎么回事,现在是,我只能看到对话框,如果我回去的应用程序A
我目前的code:
最后AlertDialog.Builder对话框=新AlertDialog.Builder(活动,
AlertDialog.THEME_DEVICE_DEFAULT_DARK);
......一些设置在这里
最后AlertDialog警报= dialog.create();
。alert.getWindow()的setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alert.show();
这可以帮助你......
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
最后的窗口管理器,管理器=(窗口管理器)context.getApplicationContext()getSystemService(Context.WINDOW_SERVICE)。
WindowManager.LayoutParams的LayoutParams =新WindowManager.LayoutParams();
layoutParams.gravity = Gravity.CENTER;
layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
layoutParams.alpha = 1.0F;
layoutParams.packageName = context.getPackageName();
layoutParams.buttonBrightness = 1F;
layoutParams.windowAnimations = android.R.style.Animation_Dialog;
最终的视图中查看= View.inflate(context.getApplicationContext(),R.layout.test_layout,NULL);
按钮yesButton =(按钮)view.findViewById(R.id.yesButton);
按钮noButton =(按钮)view.findViewById(R.id.noButton);
yesButton.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
manager.removeView(视图);
}
});
noButton.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
manager.removeView(视图);
}
});
manager.addView(视图的LayoutParams);
}
}
I have an app that opens an Alert Dialog when a bluetooth device is connected / disconnected. The alert dialog is triggered by a BroadcastReceiver on connect of a Bluetooth device.
I want to open an alert dialog such that if I open my app (app A) > long press home > go to a different app (app B), bluetooth device is connected -> my alert from app A will be displayed on top of app B.
What's happening now is that I can only see the dialog if I go back to app A
My current code:
final AlertDialog.Builder dialog = new AlertDialog.Builder(activity,
AlertDialog.THEME_DEVICE_DEFAULT_DARK);
... some setting here
final AlertDialog alert = dialog.create();
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alert.show();
this may help you...
@Override
public void onReceive(Context context, Intent intent) {
final WindowManager manager = (WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.gravity = Gravity.CENTER;
layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
layoutParams.alpha = 1.0f;
layoutParams.packageName = context.getPackageName();
layoutParams.buttonBrightness = 1f;
layoutParams.windowAnimations = android.R.style.Animation_Dialog;
final View view = View.inflate(context.getApplicationContext(),R.layout.test_layout, null);
Button yesButton = (Button) view.findViewById(R.id.yesButton);
Button noButton = (Button) view.findViewById(R.id.noButton);
yesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
manager.removeView(view);
}
});
noButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
manager.removeView(view);
}
});
manager.addView(view, layoutParams);
}
}
这篇关于如何打开android的警告对话框系统级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!