Ensure the user has permission to access ringtones (#1313)
This commit is contained in:
parent
a708a1755b
commit
86efb2d321
3 changed files with 47 additions and 19 deletions
|
|
@ -69,7 +69,9 @@ public class NotificationPreferencesModule extends ReactContextBaseJavaModule {
|
|||
}
|
||||
|
||||
Uri defaultUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION);
|
||||
result.putString("defaultUri", Uri.decode(defaultUri.toString()));
|
||||
if (defaultUri != null) {
|
||||
result.putString("defaultUri", Uri.decode(defaultUri.toString()));
|
||||
}
|
||||
result.putString("selectedUri", mNotificationPreference.getNotificationSound());
|
||||
result.putBoolean("shouldVibrate", mNotificationPreference.getShouldVibrate());
|
||||
result.putBoolean("shouldBlink", mNotificationPreference.getShouldBlink());
|
||||
|
|
|
|||
|
|
@ -1,12 +1,36 @@
|
|||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import {NativeModules} from 'react-native';
|
||||
import {NativeModules, PermissionsAndroid} from 'react-native';
|
||||
|
||||
const {NotificationPreferences} = NativeModules;
|
||||
|
||||
const defaultPreferences = {
|
||||
sounds: [],
|
||||
shouldBlink: false,
|
||||
shouldVibrate: true
|
||||
};
|
||||
|
||||
export default {
|
||||
getPreferences: NotificationPreferences.getPreferences,
|
||||
getPreferences: async () => {
|
||||
try {
|
||||
const hasPermission = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
|
||||
let granted;
|
||||
if (!hasPermission) {
|
||||
granted = await PermissionsAndroid.request(
|
||||
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE
|
||||
);
|
||||
}
|
||||
|
||||
if (hasPermission || granted === PermissionsAndroid.RESULTS.GRANTED) {
|
||||
return await NotificationPreferences.getPreferences();
|
||||
}
|
||||
|
||||
return defaultPreferences;
|
||||
} catch (error) {
|
||||
return defaultPreferences;
|
||||
}
|
||||
},
|
||||
setNotificationSound: NotificationPreferences.setNotificationSound,
|
||||
setShouldVibrate: NotificationPreferences.setShouldVibrate,
|
||||
setShouldBlink: NotificationPreferences.setShouldBlink,
|
||||
|
|
|
|||
|
|
@ -119,22 +119,24 @@ class NotificationSettings extends PureComponent {
|
|||
const {currentUser, intl, navigator, theme} = this.props;
|
||||
|
||||
NotificationPreferences.getPreferences().then((notificationPreferences) => {
|
||||
navigator.push({
|
||||
backButtonTitle: '',
|
||||
screen: 'NotificationSettingsMobile',
|
||||
title: intl.formatMessage({id: 'mobile.notification_settings.mobile_title', defaultMessage: 'Mobile Notifications'}),
|
||||
animated: true,
|
||||
navigatorStyle: {
|
||||
navBarTextColor: theme.sidebarHeaderTextColor,
|
||||
navBarBackgroundColor: theme.sidebarHeaderBg,
|
||||
navBarButtonColor: theme.sidebarHeaderTextColor,
|
||||
screenBackgroundColor: theme.centerChannelBg
|
||||
},
|
||||
passProps: {
|
||||
currentUser,
|
||||
onBack: this.saveNotificationProps,
|
||||
notificationPreferences
|
||||
}
|
||||
requestAnimationFrame(() => {
|
||||
navigator.push({
|
||||
backButtonTitle: '',
|
||||
screen: 'NotificationSettingsMobile',
|
||||
title: intl.formatMessage({id: 'mobile.notification_settings.mobile_title', defaultMessage: 'Mobile Notifications'}),
|
||||
animated: true,
|
||||
navigatorStyle: {
|
||||
navBarTextColor: theme.sidebarHeaderTextColor,
|
||||
navBarBackgroundColor: theme.sidebarHeaderBg,
|
||||
navBarButtonColor: theme.sidebarHeaderTextColor,
|
||||
screenBackgroundColor: theme.centerChannelBg
|
||||
},
|
||||
passProps: {
|
||||
currentUser,
|
||||
onBack: this.saveNotificationProps,
|
||||
notificationPreferences
|
||||
}
|
||||
});
|
||||
});
|
||||
}).catch((e) => {
|
||||
Alert.alert('There was a problem getting the device preferences', e.message);
|
||||
|
|
|
|||
Loading…
Reference in a new issue