How do I restart SystemUI in source code without rebooting the device?
I am trying to switch system font without rebooting, everything is OK except for SystemUI. I want to restart SystemUI immediately rather than reboot the device.
Thanks~~~
Requires root access, but you can restart System UI via this method:
private void restartSystemUi() {
Process process = null;
try {
process = Runtime.getRuntime().exec("su");
} catch (IOException e) {
Log.e(TAG, "Error retrieving process", e);
}
if (process != null ){
try {
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("pkill com.android.systemui\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
Log.e(TAG, "Error killing system UI", e);
}
}
}
As with any root operations, your mileage may vary. It's not possible without root, so this (or similar privilege abuse) are your only option.
call following method from where you want the rest the UI
private void restartSelf() {
AlarmManager am = (AlarmManager)getActivity().getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 500, // one second
PendingIntent.getActivity(getActivity(), 0, getActivity().getIntent(), PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT));
Intent i = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With