弹出像truecaller来电屏幕上的窗口 [英] popup window on incoming call screen like truecaller

查看:111
本文介绍了弹出像truecaller来电屏幕上的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图来电屏幕上添加弹出窗口,真正的来电,但未能实现。让我知道了什么​​是这背后的逻辑,以及如何,我可以实现这个

 公共无效的onReceive(上下文的背景下,意图意图){

    尝试 {
        //注册一个听者电话管理器类对象
        TelephonyManager TMGR =(TelephonyManager)上下文
                .getSystemService(Context.TELEPHONY_SERVICE);


            }
    }赶上(例外五){
        Log.e(手机接收错误,+ E);
    }

}
 

解决方案

我用下面的方法对我的应用程序,其中我想表明一个观点ontop当它启动(类似的东西,在Truecaller)的拨号器应用程序的。为此,创建一个广播接收器,这有助于接受各种设备事件,如下所述。

广播接收器

 专用窗口管理WM;
        私有静态的LinearLayout LY1;
        私人WindowManager.LayoutParams params1;

        //广播接收器的onReceive功能
        公共无效的onReceive(背景为arg0,意图ARG1){
                字符串状态= arg1.getStringExtra(TelephonyManager.EXTRA_STATE);

                //添加就可以了启动时的拨号器应用程序的顶部视图。
                如果(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
                    WM =(窗口管理器)context.getSystemService(Context.WINDOW_SERVICE);
                    params1 =新WindowManager.LayoutParams(
                            LayoutParams.MATCH_PARENT,
                            LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
                            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                            PixelFormat.TRANSPARENT);

                    params1.height = 75;
                    params1.width = 512;
                    params1.x = 265;
                    params1.y = 400;
                    params1.format = PixelFormat.TRANSLUCENT;

                    LY1 =新的LinearLayout(上下文);
                    ly1.setBackgroundColor(Color.BLACK);
                    ly1.setOrientation(LinearLayout.VERTICAL);

                    wm.addView(LY1,params1);
                }

                //要删除的看法,一旦拨号应用程序被关闭。
                如果(arg1.getAction()。等于(android.intent.action.PHONE_STATE)){
                    字符串状态= arg1.getStringExtra(TelephonyManager.EXTRA_STATE);
                    如果(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
                        窗口管理WM =(窗口管理器)context.getSystemService(Context.WINDOW_SERVICE);
                        如果(LY1!= NULL)
                        {
                            wm.removeView(LY1);
                            LY1 = NULL;
                        }
                    }
                }
            }
 

PS :以上如发生具有黑色背景的布局视图,其尺寸如图所示above.You有自由在这个view.For如添加任何布局:要包括布局在视图中,你可以修改上面的code,包括以下内容:

  LY1 =新的LinearLayout(getApplicationContext());
        ly1.setOrientation(LinearLayout.HORIZONTAL);


        查看hiddenInfo = getLayoutInflater()膨胀(R.layout.layout1,LY1,假的)。
        ly1.addView(hiddenInfo);

        wm.addView(LY1,params1);
 

PS :布局1是你需要创建布局文件夹,并在这里引用一个布局

Addtionally ,在你的清单,你需要包括以下权限。

 <使用-权限的Andr​​oid:名称=android.permission.SYSTEM_ALERT_WINDOW>< /使用-许可>
<使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE/>
<使用-权限的Andr​​oid:名称=android.permission.MODIFY_PHONE_STATE/>
<作用机器人:名称=android.intent.action.PHONE_STATE/> (在广播接收机的意图过滤器)
 

i am trying to add popup window on incoming call screen as true caller but fail to implement .let me know what is logic behind this and how i can implement this

  public void onReceive(Context context, Intent intent) {

    try {
        // TELEPHONY MANAGER class object to register one listner
        TelephonyManager tmgr = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);


            }
    } catch (Exception e) {
        Log.e("Phone Receive Error", " " + e);
    }

}

解决方案

I have used the below approach for my app,wherein I wanted to show a view ontop of the Dialer app when it launches(something similar to that in Truecaller).For this,create a Broadcast Receiver which helps to accept various device events as described below.

Broadcast Receiver :

        private WindowManager wm;
        private static LinearLayout ly1;
        private WindowManager.LayoutParams params1;

        // onReceive function of the Broadcast Receiver
        public void onReceive(Context arg0, Intent arg1) {
                String state = arg1.getStringExtra(TelephonyManager.EXTRA_STATE);

                // Adds a view on top of the dialer app when it launches.
                if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
                    wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                    params1 = new WindowManager.LayoutParams(
                            LayoutParams.MATCH_PARENT,
                            LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
                            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                            PixelFormat.TRANSPARENT);

                    params1.height = 75;
                    params1.width = 512;
                    params1.x = 265; 
                    params1.y = 400;
                    params1.format = PixelFormat.TRANSLUCENT;

                    ly1 = new LinearLayout(context);
                    ly1.setBackgroundColor(Color.BLACK);
                    ly1.setOrientation(LinearLayout.VERTICAL);

                    wm.addView(ly1, params1);
                }

                // To remove the view once the dialer app is closed.
                if(arg1.getAction().equals("android.intent.action.PHONE_STATE")){
                    String state = arg1.getStringExtra(TelephonyManager.EXTRA_STATE);
                    if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
                        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                        if(ly1!=null)
                        {
                            wm.removeView(ly1);
                            ly1 = null;
                        }
                    }
                }
            }

PS: The above eg generated a view having a layout with black background,having dimension as shown above.You have the liberty to add any layout within this view.For eg :To include a layout within the view you can modify the above code to include the following:

        ly1 = new LinearLayout(getApplicationContext());
        ly1.setOrientation(LinearLayout.HORIZONTAL);


        View hiddenInfo = getLayoutInflater().inflate(R.layout.layout1, ly1, false);
        ly1.addView(hiddenInfo);

        wm.addView(ly1, params1);

PS: Layout1 is a layout which you need to create in your layout folder and reference it here.

Addtionally , in your manifest you need to include the following permissions.

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<action android:name="android.intent.action.PHONE_STATE" /> (within intent filter of Broadcast Receiver)

这篇关于弹出像truecaller来电屏幕上的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆