Phone light Turn On when incoming call come

荒凉一梦 提交于 2019-12-06 11:32:11

问题


I got incoming call and working well. But when my screen is turn off and an incoming call is come. Then my screen light is not on. I am using this code in onCreate():-

getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
          | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
          );


    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
     wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");
    wl.acquire();

Also when my screen light ON and an incoming call come then my connection with server is successful. But when my screen light OFF and incoming call come(by service run in background for registration with server) then my registration is failed .

please android expert help me!


回答1:


use the following in oncreate

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

and use the permission

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


来源:https://stackoverflow.com/questions/16118721/phone-light-turn-on-when-incoming-call-come

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!