Android开发:禁用"显示通知"编程方式使用root权限? [英] Android development: disable "show notification" programmatically with root permission?

查看:1115
本文介绍了Android开发:禁用"显示通知"编程方式使用root权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法以编程方式更改的细节(设置 - > [anApp为] - >应用程序)的应用程序吗? 具体而言,可以我取消勾选显示通知的?

Is there a way to programmatically change the details (Settings -> Apps -> [anApp]) of an app? Specifically, can I uncheck "show notification"?

像图片

我假设你有root权限

I assume that you have root permissions

由于事先求助

推荐答案

首先,它似乎这取决于你有兴趣在其中的Andr​​oid版本,似乎事情在4.3改变。我调查的最新分支(即1- preVIEW),这样下去,我们发现了AOSP兔子洞......

Firstly it seems that it depends on which version of Android you are interested in. It seems that things changed in 4.3. I am investigating the latest master branch (which is l-preview), so going down the AOSP rabbit hole we find...

在设置包...

InstalledAppDetails.java:1299

private void setNotificationsEnabled(boolean enabled) {
    String packageName = mAppEntry.info.packageName;
    INotificationManager nm = INotificationManager.Stub.asInterface(
            ServiceManager.getService(Context.NOTIFICATION_SERVICE));
    try {
        final boolean enable = mNotificationSwitch.isChecked();
        nm.setNotificationsEnabledForPackage(packageName, mAppEntry.info.uid, enabled);
    } catch (android.os.RemoteException ex) {
        mNotificationSwitch.setChecked(!enabled); // revert
    }
}

在架构/基础...

NotificationManagerService.java:454

public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
    checkCallerIsSystem();

    Slog.v(TAG, (enabled?"en":"dis") + "abling notifications for " + pkg);

    mAppOps.setMode(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg,
            enabled ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);

    // Now, cancel any outstanding notifications that are part of a just-disabled app
    if (ENABLE_BLOCKED_NOTIFICATIONS && !enabled) {
        cancelAllNotificationsInt(pkg, 0, 0, true, UserHandle.getUserId(uid));
    }
}

此外,在架构/基础...

Further in frameworks/base...

底座/核心/爪哇/安卓/ APP / AppOpsManager.java

124:公共静态最终诠释OP_POST_NOTIFICATION = 11;

在框架更深/基...

Deeper in frameworks/base...

底座/服务/爪哇/ COM /安卓/服务器/ AM / ActivityManagerService.java

2000:mAppOpsService =新AppOpsService(新文件(SYSTEMDIR,appops.xml));

因此​​,如果您拥有超级用户可以修改 /data/system/appops.xml 。您可能需要通过阅读code在学习的格式为:<一href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/app/AppOpsManager.java">https://github.com/android/platform_frameworks_base/blob/master/core/java/android/app/AppOpsManager.java

So if you have root you can modify the /data/system/appops.xml. You may need to study the format by reading the code at: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/app/AppOpsManager.java

我发现了一个pretty的长文在这里有一些信息可能会有所帮助:

I found a pretty long article here with some information that might help as well:

<一个href="http://commonsware.com/blog/2013/07/26/app-ops-developer-faq.html">http://commonsware.com/blog/2013/07/26/app-ops-developer-faq.html

这篇关于Android开发:禁用&QUOT;显示通知&QUOT;编程方式使用root权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆