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

时间:2013-12-17 06:21:22

标签: android android-service android-notifications

如何隐藏前台服务的通知(即通知栏中没有任何地方)?

此行为在Switchr和Open Mic +等应用程序中有说明。

1 个答案:

答案 0 :(得分:0)

对于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)
    {}
}