-1

Below code snippet only shows view but click on buttons not working. I have tried all solution but nothing seems to work. Another service have same code fragment with different layout works.

public int onStartCommand(final Intent intent, int flags, int startId) {

LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
if (inflater!=null)
    v = inflater.inflate(R.layout.layout_accept_sos, null);
    close = v.findViewById(R.id.close);
    close.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onDestroy();
        }
    });
    getDirection = v.findViewById(R.id.getDirection);
    getDirection.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent1=new Intent();
            intent1.setAction("open_map");
            sendBroadcast(intent1);
          //  onDestroy();
        }
    });

params = new WindowManager.LayoutParams(LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT);
params.gravity = Gravity.LEFT | Gravity.TOP;
params.x = 0;
params.y = 0;
wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
wm.addView(v, params);
return START_STICKY;
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1

You need to use WindowManager.FLAG_NOT_FOCUSABLE to make it clickable.

params = new WindowManager.LayoutParams(LayoutParams.MATCH_PARENT, 
WindowManager.LayoutParams.MATCH_PARENT, 
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, 
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, 
PixelFormat.TRANSLUCENT);

More description available at https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_NOT_FOCUSABLE

buzzingsilently
  • 1,546
  • 3
  • 12
  • 18