Edit (( I found the error, the error occurs when I try to add this line
mwindow.addView (img,parmas);
Does anyone have an idea why?))
I'm trying to create floating window in Android 9.0 API 28 put i get the same error evry time i try The app cloces when i do this this is my code for FloatingWindow.java
public class FloatingWindow extends Service {
private WindowManager mwindow;
private ImageView img;
@Override
Public IBinder onBind (Intent intent){
//TODO: Retur the communication chanel to the servic.
throw new UnsupportedOperationException ("Not yet implemented")
}
public void onCreate (){
img = new ImageView (this);
img.setImageResource (R.drawable.imgicon);
mwindow = (WindowManager)getSystemService (WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams (
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTECT,
WindowManager.LayoutParams.TYPE_APPLICTION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
);
mwindow.addView (img,params);
}
}
In MainActivity i have one button to called with FloatinWindow;
button.setOnClickLidtener (new View.OnClickListener(){
@Override
public void onClick (View v){
startService (new Intent (MainActivity.this,FloatingWindow.class));
}
});
In mainfest.XML i added
<service
android:name=".FloatinWindow"
android:enabled="true"
android:exported="true"></service>
<uses-permission android:name"android.permission.SYSTEM_ALERT_WINDOW/>
Finally For the type of WindowManager.LayoutParams I used TYPE_PHONE & TYPE_TOAST and get the same error
Can anyone help my Thanks.