Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 隐藏前台服务的通知(包括根方法)_Android_Android Service_Android Notifications - Fatal编程技术网

Android 隐藏前台服务的通知(包括根方法)

Android 隐藏前台服务的通知(包括根方法),android,android-service,android-notifications,Android,Android Service,Android Notifications,如何隐藏前台服务的通知(即通知栏中的任何位置) 这种行为在Switchr和Open Mic+等应用程序中有说明。对于4.3+的非root用户,您必须指示用户转到应用程序设置并禁用“显示通知” 对于root用户,请使用以下代码: public static boolean requestRoot() { Process p; try { // Preform su to get root privledges p = Runtime.getRunti

如何隐藏前台服务的通知(即通知栏中的任何位置)


这种行为在Switchr和Open Mic+等应用程序中有说明。对于4.3+的非root用户,您必须指示用户转到应用程序设置并禁用“显示通知”

对于root用户,请使用以下代码:

public static boolean requestRoot()
{
    Process p; 
    try { 
       // Preform su to get root privledges
       p = Runtime.getRuntime().exec("su"); 

       // Attempt to write a file to a root-only 
       DataOutputStream os = new DataOutputStream(p.getOutputStream()); 
       os.writeBytes("echo \"Do I have root?\" >/system/sd/temporary.txt\n");

       // Close the terminal
       os.writeBytes("exit\n"); 
       os.flush(); 
       try { 
          p.waitFor(); 
               if (p.exitValue() != 255) { 
                   return true;
               } 
               else { 
                   return false;
               } 
       } catch (InterruptedException e) { 
          return false;
       } 
    } catch (IOException e) { 
       return false;
    }

}
public static void hideNotification(Context context)
{
    Process p; 
    try { 
       // Preform su to get root privledges
       p = Runtime.getRuntime().exec("su"); 
       DataOutputStream os = new DataOutputStream(p.getOutputStream()); 
       os.writeBytes("service call notification 6 s16 " + context.getPackageName() + " i32 " + context.getApplicationInfo().uid + " i32 0");

       // Close the terminal
       os.writeBytes("exit\n"); 
       os.flush(); 
    }
    catch(Exception e)
    {}
}
public static void showNotification(Context context)
{
    Process p; 
    try { 
       // Preform su to get root privledges
       p = Runtime.getRuntime().exec("su"); 
       DataOutputStream os = new DataOutputStream(p.getOutputStream()); 
       os.writeBytes("service call notification 6 s16 " + context.getPackageName() + " i32 " + context.getApplicationInfo().uid + " i32 1");

       // Close the terminal
       os.writeBytes("exit\n"); 
       os.flush(); 
    }
    catch(Exception e)
    {}
}