Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refreshing android systemui without reboot

Tags:

android

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~~~

like image 730
Tiantian Kong Avatar asked Sep 12 '25 06:09

Tiantian Kong


2 Answers

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.

like image 177
Kane O'Riley Avatar answered Sep 14 '25 20:09

Kane O'Riley


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);  
}  
like image 43
Haroon Avatar answered Sep 14 '25 20:09

Haroon