大佬教程收集整理的这篇文章主要介绍了android – 按下电源键后从WindowManager中删除浮动按钮,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想从WindowManager中删除我的浮动按钮当用户按下电源键并关闭屏幕时.所以当用户在我的浮动按钮上打开屏幕时不会隐藏(掩码)android模式屏幕锁定.
public class Receiver extends BroadcastReceiver { @Override public void onReceive(Context context,Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { try{ // Remove FloaTing Button from Window Manager MyWindowManager.removeView(floaTing_btn); // Stop service stopSelf(); } catch (Exception E) { //Log Error } } } }
<receiver android:name="com.whatever.client.Receiver" <intent-filter> <action android:name="android.intent.action.SCREEN_OFF" /> </intent-filter> </receiver>
出于某种原因(不确定原因),您似乎无法为SCREEN_OFF或SCREEN_ON执行此操作.所以你必须以编程方式注册它.
作为测试,我制作了一个简单的应用程序.
public class App extends Application { @Override public void onCreate() { super.onCreate(); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context,Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { startservice(new Intent(context,Myservice.class)); } } }; IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(receiver,filter); } }
提供简单的服务.
public class Myservice extends Intentservice { public Myservice() { super("Myservice"); } @Override protected void onHandleIntent(Intent intent) { Log.e("Myservice","Screen was turned off!"); } }
以上是大佬教程为你收集整理的android – 按下电源键后从WindowManager中删除浮动按钮全部内容,希望文章能够帮你解决android – 按下电源键后从WindowManager中删除浮动按钮所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。