當前位置: 首頁>>代碼示例>>Java>>正文


Java NotificationManager.isNotificationPolicyAccessGranted方法代碼示例

本文整理匯總了Java中android.app.NotificationManager.isNotificationPolicyAccessGranted方法的典型用法代碼示例。如果您正苦於以下問題:Java NotificationManager.isNotificationPolicyAccessGranted方法的具體用法?Java NotificationManager.isNotificationPolicyAccessGranted怎麽用?Java NotificationManager.isNotificationPolicyAccessGranted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.NotificationManager的用法示例。


在下文中一共展示了NotificationManager.isNotificationPolicyAccessGranted方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onResume

import android.app.NotificationManager; //導入方法依賴的package包/類
@Override
protected void onResume() {
    super.onResume();
    //initialise location permissions checkbox
    CheckBox locationPermissionsCheckBox = (CheckBox) findViewById(R.id.location_permission_checkbox);
    if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
        locationPermissionsCheckBox.setChecked(false);
    }
    else {
        locationPermissionsCheckBox.setChecked(true);
        locationPermissionsCheckBox.setEnabled(false);
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT>=24 && !notificationManager.isNotificationPolicyAccessGranted()){
        mRingerPermissionCheckBox.setChecked(false);
    }
    else {
        mRingerPermissionCheckBox.setChecked(true);
        mRingerPermissionCheckBox.setEnabled(false);
    }
}
 
開發者ID:samagra14,項目名稱:Shush,代碼行數:23,代碼來源:MainActivity.java

示例2: setRingerMode

import android.app.NotificationManager; //導入方法依賴的package包/類
/**
 * Changes the ringer mode on the device to either silent or back to normal
 *
 * @param context The context to access AUDIO_SERVICE
 * @param mode    The desired mode to switch device to, can be AudioManager.RINGER_MODE_SILENT or
 *                AudioManager.RINGER_MODE_NORMAL
 */
public static void setRingerMode(Context context, int mode){
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT<24 || (Build.VERSION.SDK_INT>=24 && !notificationManager.isNotificationPolicyAccessGranted())){
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.setRingerMode(mode);
    }
}
 
開發者ID:samagra14,項目名稱:Shush,代碼行數:16,代碼來源:RingerUtils.java

示例3: onResume

import android.app.NotificationManager; //導入方法依賴的package包/類
@Override
protected void onResume() {
    super.onResume();

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        NotificationManager mNotificationManager = (NotificationManager) getApplication().getSystemService(Context.NOTIFICATION_SERVICE);
        if (mNotificationManager.isNotificationPolicyAccessGranted()) {
            permissionStatus.setText("DND permission granted for Phone.");
        } else {
            permissionStatus.setText("To enable synchronization to Phone, please grant DND modification permissions to 'Wear DND Sync' application.");
        }
    }
}
 
開發者ID:rkkr,項目名稱:wear-dnd-sync,代碼行數:14,代碼來源:MainActivity.java

示例4: onMessageReceived

import android.app.NotificationManager; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equalsIgnoreCase(DND_SYNC_PREFIX)) {
        // Read the received ringer or dnd mode and convert it back to an integer
        int newMode = Integer.parseInt(new String(messageEvent.getData()));

        if (SEND_RINGER_MODE) {
            Log.d(TAG, "Received new ringer mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        } else {
            Log.d(TAG, "Received new dnd mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        }

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Check if the notification policy access has been granted for the app
        // This is needed to set modes that affect Do Not Disturb in Android N
        if (mNotificationManager.isNotificationPolicyAccessGranted()) {
            if (SEND_RINGER_MODE) {
                Log.d(TAG, "Attempting to set ringer mode " + newMode);

                AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

                if (newMode == AudioManager.RINGER_MODE_SILENT) {
                    audioManager.setRingerMode(newMode);
                } else {
                    // Set the saved "normal" value
                    audioManager.setRingerMode(getNormalRingerMode());
                }
            } else {
                Log.d(TAG, "Attempting to set dnd mode " + newMode);

                mNotificationManager.setInterruptionFilter(newMode);
            }
        } else {
            Log.d(TAG, "App is not allowed to change Do Not Disturb mode without applying workaround");
        }
    } else {
        super.onMessageReceived(messageEvent);
    }
}
 
開發者ID:blunden,項目名稱:DoNotDisturbSync,代碼行數:41,代碼來源:WearMessageListenerService.java

示例5: initAudioManager

import android.app.NotificationManager; //導入方法依賴的package包/類
private void initAudioManager() {
    mAudioManager = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);

    int mode = mAudioManager.getRingerMode();
    if (mode == AudioManager.RINGER_MODE_VIBRATE
            || mode == AudioManager.RINGER_MODE_SILENT) {
        // Normal mode will be audible and may vibrate according to user settings.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            NotificationManager n  = (NotificationManager) mAppContext.getSystemService(Context.NOTIFICATION_SERVICE);
            boolean isPolicyGranted = n != null && n.isNotificationPolicyAccessGranted();
            // fixme 7.0手機 如果沒有這個權限 直接調用setRingerMode會報出 Not allowed to change Do Not Disturb state的異常.
            if (isPolicyGranted) {
                mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            }
        } else {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
    }
    mAudioMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int audioCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    if (mAudioMaxVolume != 0) {
        mCurrentVolume = (int) (((float) audioCurrentVolume / (float) mAudioMaxVolume) * 100);
    }
    PlayerLog.d(TAG, "initAudioManager mCurrentVolume is " + mCurrentVolume +
            " , mAudioMaxVolume is " + mAudioMaxVolume +
            " , audioCurrentVolume is " + audioCurrentVolume);
}
 
開發者ID:xinpianchang,項目名稱:NSMPlayer-Android,代碼行數:28,代碼來源:VMoviePlayer.java

示例6: checkPermissionForRingtone

import android.app.NotificationManager; //導入方法依賴的package包/類
private static void checkPermissionForRingtone(Activity activity){
    NotificationManager notificationManager =
            (NotificationManager) activity.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && !notificationManager.isNotificationPolicyAccessGranted()) {

        Intent intent = new Intent(
                android.provider.Settings
                        .ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);

        activity.startActivity(intent);
    }
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:15,代碼來源:Utilities.java

示例7: onMessageReceived

import android.app.NotificationManager; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    Log.d(TAG, "onMessageReceived: " + messageEvent);

    switch (messageEvent.getPath()) {
        case PATH_DND:
            if (messageEvent.getData().length == 0)
                return;

            int state = (int) messageEvent.getData()[0];

            Log.d(TAG, "Target state: " + state);

            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                if (state != NotificationManager.INTERRUPTION_FILTER_ALL)
                    state = NotificationManager.INTERRUPTION_FILTER_ALARMS;
                if (state == (int) notificationManager.getCurrentInterruptionFilter())
                    return;

                if (notificationManager.isNotificationPolicyAccessGranted())
                    notificationManager.setInterruptionFilter(state);
            } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Intent intent = new Intent(LGHackService.ACTION_SET_STATE);
                intent.putExtra(LGHackService.EXTRA_STATE, (int) messageEvent.getData()[0]);
                sendBroadcast(intent);
            } else {
                AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
                state = state == 4 ?  AudioManager.RINGER_MODE_SILENT : AudioManager.RINGER_MODE_NORMAL;
                //INTERRUPTION_FILTER_ALARMS
                if (state == audioManager.getRingerMode())
                    return;
                audioManager.setRingerMode(state);
            }
            return;
        case PATH_DND_REGISTER:
            if (messageEvent.getData().length == 0)
                return;

            Intent connectIntent = new Intent(WEAR_CALLBACK_CONNECT);
            if (messageEvent.getData().length > 1) {
                DataMap config = DataMap.fromByteArray(messageEvent.getData());
                connectIntent.putExtra("permission", config.getBoolean("permission"));
            }
            sendBroadcast(connectIntent);
            Log.d(TAG, "Connected broadcast");
            return;
        case PATH_LOGS:
            if (messageEvent.getData().length == 0)
                return;

            Intent logIntent = new Intent(WEAR_CALLBACK_LOGS);
            logIntent.putExtra("log", new String(messageEvent.getData()));
            sendBroadcast(logIntent);
            Log.d(TAG, "Logs broadcast");
            return;
    }
}
 
開發者ID:rkkr,項目名稱:wear-dnd-sync,代碼行數:59,代碼來源:SettingsService.java

示例8: onMessageReceived

import android.app.NotificationManager; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equalsIgnoreCase(DND_SYNC_PREFIX)) {
        // Read the received ringer or dnd mode and convert it back to an integer
        int newMode = Integer.parseInt(new String(messageEvent.getData()));

        if (SEND_RINGER_MODE) {
            Log.d(TAG, "Received new ringer mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        } else {
            Log.d(TAG, "Received new dnd mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        }

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Check if the notification policy access has been granted for the app
        // This is needed to set modes that affect Do Not Disturb in Android N
        if (mNotificationManager.isNotificationPolicyAccessGranted() || Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            if (SEND_RINGER_MODE) {
                Log.d(TAG, "Attempting to set ringer mode " + newMode);

                AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

                if (newMode == AudioManager.RINGER_MODE_SILENT) {
                    audioManager.setRingerMode(newMode);
                } else {
                    // Set the saved "normal" value
                    audioManager.setRingerMode(getNormalRingerMode());
                }
            } else {
                Log.d(TAG, "Attempting to set dnd mode " + newMode);

                mNotificationManager.setInterruptionFilter(newMode);
            }
        } else {
            Log.i(TAG, "Unable to set new ringer mode due to lack of permissions on device");
            Log.i(TAG, "Launching permissions settings activity on the device");
            Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    } else {
        super.onMessageReceived(messageEvent);
    }
}
 
開發者ID:blunden,項目名稱:DoNotDisturbSync,代碼行數:45,代碼來源:WearMessageListenerService.java


注:本文中的android.app.NotificationManager.isNotificationPolicyAccessGranted方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。