2015-02-05 5 views
0

button을 사용하여 수동으로 notificationListenerService를 켜거나 끄려면 어떻게해야합니까?수동으로 notificationListenerService를 켜고 끄기

보안 -> 알림에서 앱이 허용되는 순간 서비스가 시작되지만이 문제를 방지하고 대신 수동으로 수행하는 방법이 확실하지 않습니다.

startService()와 같은 기능이 있지만 서비스쪽으로 구현하는 방법이 확실하지 않습니다.

감사

+0

. 너 무슨 소리하는거야? 프로그래밍 문제입니까? – Markus

답변

0

당신은 프로그래밍 방식으로 서비스를 활성화하거나 비활성화 할 수 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); 
관련 문제