Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在三星Galaxy A5中,自定义对话框无法在来电屏幕上显示_Android_Service_Dialog_Flags_Android Windowmanager - Fatal编程技术网

Android 在三星Galaxy A5中,自定义对话框无法在来电屏幕上显示

Android 在三星Galaxy A5中,自定义对话框无法在来电屏幕上显示,android,service,dialog,flags,android-windowmanager,Android,Service,Dialog,Flags,Android Windowmanager,我的代码在大多数设备上运行良好,但在三星galaxy A5上运行不好 我试图在本机拨号器上显示我的自定义覆盖对话框,这样通过单击它,我就可以将用户重定向到我的应用程序。我已经在每台设备上用Smasung J7 prime、Samsung onNXT、Moto G4 plus等测试了我的代码。它工作正常,我不知道为什么三星Galaxy A5不起作用 这里有人面对同样的问题吗 这是我的代码: private static WindowManager wm; public static View po

我的代码在大多数设备上运行良好,但在三星galaxy A5上运行不好 我试图在本机拨号器上显示我的自定义覆盖对话框,这样通过单击它,我就可以将用户重定向到我的应用程序。我已经在每台设备上用Smasung J7 prime、Samsung onNXT、Moto G4 plus等测试了我的代码。它工作正常,我不知道为什么三星Galaxy A5不起作用

这里有人面对同样的问题吗

这是我的代码

private static WindowManager wm;
public static View popupView;
private static WindowManager.LayoutParams params1;

private static void showPopup(Context applicationContext) {
    wm = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE);
    params1 = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
                    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
            PixelFormat.TRANSPARENT);
    params1.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params1.width = WindowManager.LayoutParams.MATCH_PARENT;
    params1.x = 0;
    params1.y = 0;
    params1.gravity = Gravity.TOP;
    params1.format = PixelFormat.TRANSLUCENT;
    LayoutInflater layoutInflater =
            (LayoutInflater) applicationContext
                    .getSystemService(applicationContext.LAYOUT_INFLATER_SERVICE);
    popupView = layoutInflater.inflate(R.layout.activity_dialog, null);
    int[] attrs = new int[]{R.attr.selectableItemBackground};
    TypedArray typedArray = applicationContext.obtainStyledAttributes(attrs);
    int backgroundResource = typedArray.getResourceId(0, 0);
    popupView.setBackgroundResource(backgroundResource);
    wm.addView(popupView, params1);
    popupView.setVisibility(View.GONE);
    popupView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popupView.setVisibility(View.GONE);
            startActivity(applicationContext);
        }
    });
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/rv_parentview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="2sp"
        android:background="@drawable/rounded_corner_bg">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="@dimen/text_size_very_small">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginLeft="@dimen/text_size_very_small"
                android:text="Add Call"
                style="@style/FontHeavyBold"
                android:textColor="@android:color/black"
                android:textSize="@dimen/text_size_large"/>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/text_size_very_small"
                android:layout_marginRight="@dimen/text_size_very_small">

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_centerVertical="true"
                    android:background="@drawable/fill_circle_bg" />

                <ImageView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/white_add_call" />

            </RelativeLayout>

            <!-- <TextView
                 style="@style/FontHeavyBold"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:paddingLeft="90dp"
                 android:paddingRight="90dp"
                 android:text="Add Call"
                 android:textAppearance="@style/FontLight"
                 android:textColor="@color/app_color"
                 android:textSize="@dimen/text_size_medium" />

             <ImageView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="@dimen/text_size_very_small"
                 android:src="@mipmap/ico_return" />-->

        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>
用于弹出视图的Xml

private static WindowManager wm;
public static View popupView;
private static WindowManager.LayoutParams params1;

private static void showPopup(Context applicationContext) {
    wm = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE);
    params1 = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
                    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
            PixelFormat.TRANSPARENT);
    params1.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params1.width = WindowManager.LayoutParams.MATCH_PARENT;
    params1.x = 0;
    params1.y = 0;
    params1.gravity = Gravity.TOP;
    params1.format = PixelFormat.TRANSLUCENT;
    LayoutInflater layoutInflater =
            (LayoutInflater) applicationContext
                    .getSystemService(applicationContext.LAYOUT_INFLATER_SERVICE);
    popupView = layoutInflater.inflate(R.layout.activity_dialog, null);
    int[] attrs = new int[]{R.attr.selectableItemBackground};
    TypedArray typedArray = applicationContext.obtainStyledAttributes(attrs);
    int backgroundResource = typedArray.getResourceId(0, 0);
    popupView.setBackgroundResource(backgroundResource);
    wm.addView(popupView, params1);
    popupView.setVisibility(View.GONE);
    popupView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popupView.setVisibility(View.GONE);
            startActivity(applicationContext);
        }
    });
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/rv_parentview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="2sp"
        android:background="@drawable/rounded_corner_bg">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="@dimen/text_size_very_small">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginLeft="@dimen/text_size_very_small"
                android:text="Add Call"
                style="@style/FontHeavyBold"
                android:textColor="@android:color/black"
                android:textSize="@dimen/text_size_large"/>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/text_size_very_small"
                android:layout_marginRight="@dimen/text_size_very_small">

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_centerVertical="true"
                    android:background="@drawable/fill_circle_bg" />

                <ImageView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/white_add_call" />

            </RelativeLayout>

            <!-- <TextView
                 style="@style/FontHeavyBold"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:paddingLeft="90dp"
                 android:paddingRight="90dp"
                 android:text="Add Call"
                 android:textAppearance="@style/FontLight"
                 android:textColor="@color/app_color"
                 android:textSize="@dimen/text_size_medium" />

             <ImageView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="@dimen/text_size_very_small"
                 android:src="@mipmap/ico_return" />-->

        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

将此权限检查添加到onCreate()中

使用AlertDialog并将窗口类型更改为“电话”

 AlertDialog.Builder builder = new AlertDialog.Builder(context.getApplicationContext());
            LayoutInflater inflater = LayoutInflater.from(context);
            View dialogView = inflater.inflate(R.layout.caller_dialog, null);
            Window window = alert.getWindow();
            builder.setView(dialogView);
            final AlertDialog alert = builder.create();
            window.requestFeature(Window.FEATURE_NO_TITLE);
            window.setType(WindowManager.LayoutParams.TYPE_PHONE);
            alert.setCanceledOnTouchOutside(true);
            alert.show();
            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();

            window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            window.setGravity(Gravity.TOP);
            lp.copyFrom(window.getAttributes());
            //This makes the dialog take up the full width
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            window.setAttributes(lp);
不要忘记在清单中添加此权限

<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />


您能发布完整的功能吗?您现在使用全局VAR。@greenapps,请查看我更新的问题,我发布了我的全部服务,这不是我要求的。我不会摆弄你的服务。我要求提供一个完整的
showPopup()
函数,我可以在onClick()事件中调用它。你应该让我们很容易帮助你。我只想复制/粘贴一个函数。请检查上面的内容。这样好吗,我粘贴了我的xml代码、变量和完整函数,现在你只需要调用这个函数并将静态图像和维度放入代码中,如果它仍然不符合你的期望,让我知道A5上已经有覆盖权限,但当屏幕锁定时,我的对话框不会出现在本机拨号器Ui上。是否尝试将类型更改为“WindowManager.LayoutParams.setType(WindowManager.LayoutParams.type_PHONE);”?是的,我试图在代码中添加这一行,但它表示无法解析setType(我认为这将适用于Window=getWindow();)