【问题标题】:Manually switch notificationListenerService on and off手动打开和关闭 notificationListenerService
【发布时间】:2015-02-05 16:33:29
【问题描述】:

您将如何使用按钮手动打开和关闭 notificationListenerService?

在安全->通知中允许应用程序的那一刻服务启动,但是我不确定如何防止这种情况并改为手动执行。

我知道有诸如 startService() 之类的函数,但不确定如何针对服务实现。

谢谢

【问题讨论】:

  • 缺少很多细节。你在说什么?是编程问题吗?

标签: java android android-intent service android-service


【解决方案1】:

您可以使用PackageManager.setComponentEnabledSetting() 以编程方式启用或禁用服务:

PackageManager packageManager = getPackageManager();
ComponentName notificationListenerService = new ComponentName(this,
    YourNotificationListenerService.class);

// The new state of the service - either enabled or disabled
int newState = enableService
    ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
    : PackageManager.COMPONENT_ENABLED_STATE_DISABLE;

packageManager.setComponentEnabledSetting(
    notificationListenerService,
    newState,
    PackageManager.DONT_KILL_APP);

【讨论】:

    猜你喜欢
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2012-10-14
    • 2020-08-31
    • 2020-10-20
    相关资源
    最近更新 更多