这是我的代码:
protected window_fly (Context context) {
WindowManager.LayoutParams params = new WindowManager.LayoutParams (
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT ) ;
params.gravity = Gravity.LEFT | Gravity.BOTTOM ;
LayoutInflater layOutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE) ;
View in_view = layOutInflater.inflate(R.layout.in_layout, null) ;
Toast.makeText(context, "daemon born", Toast.LENGTH_SHORT).show() ;
WindowManager wm = (WindowManager) context.getSystemService(context.WINDOW_SERVICE);
//wm.addView(in_view, params);
}
全部在服务上下文中。 window_fly是构造函数。如果我取消注释wm.addView()并运行它,应用程序将会崩溃。请告诉我可能的原因。抱歉英语不好。
答案 0 :(得分:0)
添加到Manifest行,其中包含SYSTEM_ALERT_WINDOW的权限说明:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>