安卓开发: disable "show notification" programmatically with root permission?

标签 android notifications settings root

有没有办法以编程方式更改应用程序的详细信息(设置 -> 应用程序 -> [anApp])? 具体来说,我可以取消选中“显示通知”吗?

enter image description here

我假设你有root权限

在此先感谢您的帮助

最佳答案

首先,这似乎取决于您对哪个版本的 Android 感兴趣。似乎情况在 4.3 中发生了变化。我正在调查最新的 master 分支(即 l-preview),所以我们发现了 AOSP 兔子洞......

在设置包中...

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));
    }
}

进一步在框架/基础...

base/core/java/android/app/AppOpsManager.java

124: public static final int OP_POST_NOTIFICATION = 11;

更深入的框架/基础...

base/services/java/com/android/server/am/ActivityManagerService.java

2000: mAppOpsService = new AppOpsService(new File(systemDir, "appops.xml"));

所以如果你有根你可以修改/data/system/appops.xml。您可能需要通过阅读以下代码来研究格式:https://github.com/android/platform_frameworks_base/blob/master/core/java/android/app/AppOpsManager.java

我在这里找到了一篇很长的文章,其中包含一些可能也有帮助的信息:

http://commonsware.com/blog/2013/07/26/app-ops-developer-faq.html

关于安卓开发: disable "show notification" programmatically with root permission?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24577682/

相关文章:

android - 无法为 http 连接解析主机

android - 谷歌应用邀请 : Tracking Invites

java - Android:ProgressUpdate 上出现 NullPointerException

objective-c - 强制某个类发布特定的 NSNotification?

flutter - 如何获取待处理通知的[scheduledDate](flutter本地通知)

java - 尝试在android中写入SD卡时出现空指针异常

android - 点击通知启动 Activity 两次

c++ - Qt - 为程序中的所有表和模型设置全局精度

cocoa - 以编程方式更改系统网络(代理)设置

ide - CLion 突出显示设置(覆盖)