java - Unable to add view to a service in Android -
please: visit question before marking down question link
i want add imageview service , such appears on top of other activities giving error : detail below
code: androidmainfest.xml
<uses-permission android:name="android.permission.system_alert_window"/> <service android:name=".toggleheadservice"/>
code: toggleheadservice.java
public class toggleheadservice extends service{ private windowmanager windowmanager; private imageview togglehead; @override public ibinder onbind(intent intent) { return null; } @override public void oncreate() { super.oncreate(); togglehead=new imageview(this); togglehead.setimageresource(r.drawable.ic_brightness_high_black_48dp); windowmanager = (windowmanager) getsystemservice(window_service); windowmanager.layoutparams params = new windowmanager.layoutparams( windowmanager.layoutparams.wrap_content, windowmanager.layoutparams.wrap_content, windowmanager.layoutparams.type_system_alert, windowmanager.layoutparams.flag_not_focusable | windowmanager.layoutparams.flag_not_touch_modal, pixelformat.translucent); params.gravity = gravity.top | gravity.left; params.x = 0; params.y = 100; windowmanager.addview(togglehead, params); } @override public void ondestroy() { super.ondestroy(); if(togglehead!=null)windowmanager.removeview(togglehead); } }
error: got
java.lang.runtimeexception: unable create service com.betatech.alex.toggle.toggleheadservice: android.view.windowmanager$badtokenexception: unable add window android.view.viewrootimpl$w@3cf2926d -- permission denied window type caused by: android.view.windowmanager$badtokenexception: unable add window android.view.viewrootimpl$w@3cf2926d -- permission denied window type
the permission should be:
<uses-permission android:name="android.permission.system_alert_window"/>
notice lowercase "android.permission".
Comments
Post a Comment