Forked from RikkaW/gist:be3fe4178903702c54ec73b2fc1187fe
Created
May 27, 2023 10:15
-
-
Save Kr328/8c767734d5c560aaa0bfe950ab108822 to your computer and use it in GitHub Desktop.
show window in app_process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
token = new Binder(); | |
try { | |
Context _context = android.app.ActivityThread.systemMain().getSystemContext(); | |
final Context context = new ContextWrapper(_context) { | |
@Override | |
public Object getSystemService(String name) { | |
if (Context.WINDOW_SERVICE.equals(name)) { | |
WindowManager wm = (WindowManager) super.getSystemService(name); | |
if (wm != null) { | |
((android.view.WindowManagerImpl) wm).setDefaultToken(token); | |
} | |
return wm; | |
} | |
return super.getSystemService(name); | |
} | |
}; | |
context.setTheme(android.R.style.Theme_Material_Light); | |
CharSequence label = context.getPackageManager().getApplicationLabel(context.getPackageManager().getApplicationInfo("com.android.settings", 0)); | |
LogUtils.i("label " + label); | |
android.widget.Toast.makeText(context, "test", Toast.LENGTH_LONG).show(); | |
LogUtils.i("toast"); | |
android.view.WindowManager wm = context.getSystemService(WindowManager.class); | |
LogUtils.i("class: " + wm.getClass().getName()); | |
//((android.view.WindowManagerImpl) wm).setDefaultToken(token); | |
LinearLayout root = new LinearLayout(context); | |
root.setBackground(new ColorDrawable(0xffffffff)); | |
TextView textView = new TextView(context); | |
textView.setText("test"); | |
root.addView(textView); | |
Button button = new Button(context); | |
button.setSoundEffectsEnabled(false); | |
button.setText("test"); | |
button.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(context, "?!", Toast.LENGTH_LONG).show(); | |
} | |
}); | |
root.addView(button); | |
WindowManager.LayoutParams params = new WindowManager.LayoutParams( | |
WindowManager.LayoutParams.WRAP_CONTENT, | |
WindowManager.LayoutParams.WRAP_CONTENT, | |
WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG, | |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, | |
PixelFormat.TRANSLUCENT); | |
params.gravity = Gravity.CENTER; | |
params.x = 0; | |
params.y = 0; | |
wm.addView(root, params); | |
} catch (Throwable tr) { | |
LogUtils.e(tr.getMessage(), tr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment