Java Code Examples for android.provider.Settings#ACTION_MANAGE_WRITE_SETTINGS
The following examples show how to use
android.provider.Settings#ACTION_MANAGE_WRITE_SETTINGS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From music_player with Open Software License 3.0 | 6 votes |
private void setAsRingtone(final Activity context, int position) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(context)) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + context.getPackageName())); context.startActivity(intent); } else { File music = new File(MyApplication.getMusicListNow().get(position).getMusicData()); // path is a file to /sdcard/media/ringtone ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, music.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, MyApplication.getMusicListNow().get(position).getMusicTitle()); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.ARTIST, MyApplication.getMusicListNow().get(position).getMusicArtist()); values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false); //Insert it into the database Uri uri = MediaStore.Audio.Media.getContentUriForPath(music.getAbsolutePath()); context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + music.getAbsolutePath() + "\"", null); Uri newUri = context.getContentResolver().insert(uri, values); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri); Toast.makeText(context, "已成功设置为来电铃声", Toast.LENGTH_SHORT).show(); //Snackbar // Snackbar.make(mLayout, "已成功设置为来电铃声", Snackbar.LENGTH_LONG).show(); } }
Example 2
Source File: FloatingBallUtils.java From RelaxFinger with GNU General Public License v2.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.M) public static boolean checkPermissionWrite(){ if(!Settings.System.canWrite(context)){ Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); MyApplication.getMainThreadHandler().post(new Runnable() { @Override public void run() { Toast.makeText(context,"屏幕旋转需要修改系统设置权限!",Toast.LENGTH_SHORT).show(); } }); return false; }else { return true; } }
Example 3
Source File: PermissionUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.M) private static void startWriteSettingsActivity(final Activity activity, final int requestCode) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + Utils.getApp().getPackageName())); if (!UtilsBridge.isIntentAvailable(intent)) { launchAppDetailsSettings(); return; } activity.startActivityForResult(intent, requestCode); }
Example 4
Source File: SwapWorkflowActivity.java From fdroidclient with GNU General Public License v3.0 | 5 votes |
@TargetApi(23) public void requestWriteSettingsPermission() { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intent, REQUEST_WRITE_SETTINGS_PERMISSION); }
Example 5
Source File: SettingsUtils.java From talkback with Apache License 2.0 | 5 votes |
/** * Requests system settings writing permission if the parent context needs. * * @param context The parent context * @return {@code true} has the permission; {@code false} need to request the permission */ public static boolean requestWriteSettingsPermission(Context context) { boolean hasWritePermission = Settings.System.canWrite(context); if (hasWritePermission) { return true; } // Starting in M, we need the user to manually allow the app to modify system settings. Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + context.getPackageName())); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return false; }
Example 6
Source File: HostSettingProfile.java From DeviceConnect-Android with MIT License | 5 votes |
@Override public boolean onRequest(final Intent request, final Intent response) { final String serviceId = getServiceID(request); final Integer time = getTime(request); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Settings.System.canWrite(getContext())) { onPutDisplaySleepInternal(request, response, serviceId, time); } else { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getContext().getPackageName())); IntentHandlerActivity.startActivityForResult(getContext(), intent, new ResultReceiver(new Handler(Looper.getMainLooper())) { @Override protected void onReceiveResult(final int resultCode, final Bundle resultData) { if (Settings.System.canWrite(getContext())) { onPutDisplaySleepInternal(request, response, serviceId, time); } else { MessageUtils.setIllegalServerStateError(response, "WRITE_SETTINGS permisson not granted"); } sendResponse(response); } }); return false; } } else { onPutDisplaySleepInternal(request, response, serviceId, time); } return true; }
Example 7
Source File: HostSettingProfile.java From DeviceConnect-Android with MIT License | 5 votes |
@Override public boolean onRequest(final Intent request, final Intent response) { final String serviceId = getServiceID(request); final Double level = getLightLevel(request); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Settings.System.canWrite(getContext())) { onPutDisplayLightInternal(request, response, serviceId, level); } else { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getContext().getPackageName())); IntentHandlerActivity.startActivityForResult(getContext(), intent, new ResultReceiver(new Handler(Looper.getMainLooper())) { @Override protected void onReceiveResult(final int resultCode, final Bundle resultData) { if (Settings.System.canWrite(getContext())) { onPutDisplayLightInternal(request, response, serviceId, level); } else { MessageUtils.setIllegalServerStateError(response, "WRITE_SETTINGS permisson not granted"); } sendResponse(response); } }); return false; } } else { onPutDisplayLightInternal(request, response, serviceId, level); } return true; }
Example 8
Source File: PermissionUtils.java From SimpleSmsRemote with MIT License | 5 votes |
/** * Start activity in order to request permission for writing settings <br/> * * @param activity any activity */ @TargetApi(Build.VERSION_CODES.M) private static void RequestWriteSettingsPermission(Activity activity) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + activity.getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activity.startActivity(intent); }
Example 9
Source File: PermissionOperator.java From QuickDevFramework with Apache License 2.0 | 5 votes |
/** * 申请修改系统设置的权限 * @param activity 申请权限的Activity,Fragment申请权限请传入getActivity() * @param callback 申请权限回调 * */ @TargetApi(Build.VERSION_CODES.M) private void requestWriteSystemSettingsPermission(Activity activity, RequestPermissionCallback callback) { if (PermissionManager.hasWriteSystemSettingsPermission()) { if (callback != null) { callback.onGranted(); } return; } Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + activity.getPackageName())); activity.startActivityForResult(intent, WRITE_SETTINGS_PERMISSION_REQUEST_CODE ); currCallback = callback; }
Example 10
Source File: SettingsCompat.java From settingscompat with Apache License 2.0 | 5 votes |
public static void manageWriteSettings(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + context.getPackageName())); context.startActivity(intent); } }
Example 11
Source File: SettingsCompat.java From webrtc_android with MIT License | 5 votes |
public static void manageWriteSettings(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + context.getPackageName())); context.startActivity(intent); } }
Example 12
Source File: DisplayLightControllerImpl.java From lantern with Apache License 2.0 | 5 votes |
@Override public void requestSystemWritePermission() { // Request for permission if not yet granted if (!checkSystemWritePermission()) { if (isMarshmallowAndAbove()) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + activityWeakRef.get().getPackageName())); activityWeakRef.get().startActivity(intent); } } }
Example 13
Source File: FavouriteListAdapter.java From music_player with Open Software License 3.0 | 5 votes |
private void setAsRingtone(final Activity context, int position) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(context)) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + context.getPackageName())); context.startActivity(intent); } else { List<musicInfo> list = MyApplication.getTimessublist(); File music = new File(list.get(position).getMusicData()); // path is a file to /sdcard/media/ringtone ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, music.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, list.get(position).getMusicTitle()); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.ARTIST, list.get(position).getMusicArtist()); values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false); //Insert it into the database Uri uri = MediaStore.Audio.Media.getContentUriForPath(music.getAbsolutePath()); context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + music.getAbsolutePath() + "\"", null); Uri newUri = context.getContentResolver().insert(uri, values); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri); Toast.makeText(context, "已成功设置为来电铃声", Toast.LENGTH_SHORT).show(); //Snackbar // Snackbar.make(rootview, "已成功设置为来电铃声", Snackbar.LENGTH_LONG).setAction("好的", new View.OnClickListener() { // @Override // public void onClick(View v) { // } // }).show(); } }
Example 14
Source File: searchAdapter.java From music_player with Open Software License 3.0 | 5 votes |
private void setAsRingtone(final Activity context, int position) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(context)) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + context.getPackageName())); context.startActivity(intent); } else { // List<musicInfo> list = MyApplication.getMusicInfoArrayList(); File music = new File(musicInfoArrayList.get(position).getMusicData()); // path is a file to /sdcard/media/ringtone ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, music.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, musicInfoArrayList.get(position).getMusicTitle()); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.ARTIST, musicInfoArrayList.get(position).getMusicArtist()); values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false); //Insert it into the database Uri uri = MediaStore.Audio.Media.getContentUriForPath(music.getAbsolutePath()); context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + music.getAbsolutePath() + "\"", null); Uri newUri = context.getContentResolver().insert(uri, values); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri); //Snackbar Snackbar.make(rootview, "已成功设置为来电铃声", Snackbar.LENGTH_LONG).setAction("好的", new View.OnClickListener() { @Override public void onClick(View v) { } }).show(); } }
Example 15
Source File: playlistdetailAdapter.java From music_player with Open Software License 3.0 | 5 votes |
private void setAsRingtone(final Activity context, int position) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(context)) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + context.getPackageName())); context.startActivity(intent); } else { List<musicInfo> list = MyApplication.getBoxStore().boxFor(Playlist.class).query().equal(Playlist_.name, MyApplication.getCustomListNow()).build().findUnique().getMusicInfos(); File music = new File(list.get(position).getMusicData()); // path is a file to /sdcard/media/ringtone ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, music.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, list.get(position).getMusicTitle()); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.ARTIST, list.get(position).getMusicArtist()); values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false); //Insert it into the database Uri uri = MediaStore.Audio.Media.getContentUriForPath(music.getAbsolutePath()); context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + music.getAbsolutePath() + "\"", null); Uri newUri = context.getContentResolver().insert(uri, values); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri); Toast.makeText(context, "已成功设置为来电铃声", Toast.LENGTH_SHORT).show(); //Snackbar // Snackbar.make(rootview, "已成功设置为来电铃声", Snackbar.LENGTH_LONG).setAction("好的", new View.OnClickListener() { // @Override // public void onClick(View v) { // } // }).show(); } }
Example 16
Source File: FastScrollListAdapter.java From music_player with Open Software License 3.0 | 5 votes |
private void setAsRingtone(final Activity context, int position) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(context)) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + context.getPackageName())); context.startActivity(intent); } else { // List<musicInfo> list = MyApplication.getMusicInfoArrayList(); File music = new File(musicInfoArrayList.get(position).getMusicData()); // path is a file to /sdcard/media/ringtone ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, music.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, musicInfoArrayList.get(position).getMusicTitle()); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.ARTIST, musicInfoArrayList.get(position).getMusicArtist()); values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false); //Insert it into the database Uri uri = MediaStore.Audio.Media.getContentUriForPath(music.getAbsolutePath()); context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + music.getAbsolutePath() + "\"", null); Uri newUri = context.getContentResolver().insert(uri, values); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri); Toast.makeText(context, "已成功设置为来电铃声", Toast.LENGTH_SHORT).show(); // //Snackbar // Snackbar.make(rootview, "已成功设置为来电铃声", Snackbar.LENGTH_LONG).setAction("好的", new View.OnClickListener() { // @Override // public void onClick(View v) { // } // }).show(); } }
Example 17
Source File: RecentListAdapter.java From music_player with Open Software License 3.0 | 5 votes |
private void setAsRingtone(final Activity context, int position) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(context)) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + context.getPackageName())); context.startActivity(intent); } else { List<musicInfo> list = MyApplication.getDatesublist(); File music = new File(list.get(position).getMusicData()); // path is a file to /sdcard/media/ringtone ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, music.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, list.get(position).getMusicTitle()); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.ARTIST, list.get(position).getMusicArtist()); values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false); //Insert it into the database Uri uri = MediaStore.Audio.Media.getContentUriForPath(music.getAbsolutePath()); context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + music.getAbsolutePath() + "\"", null); Uri newUri = context.getContentResolver().insert(uri, values); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri); Toast.makeText(context, "已成功设置为来电铃声", Toast.LENGTH_SHORT).show(); //Snackbar // Snackbar.make(rootview, "已成功设置为来电铃声", Snackbar.LENGTH_LONG).setAction("好的", new View.OnClickListener() { // @Override // public void onClick(View v) { // } // }).show(); } }
Example 18
Source File: LocalMusicFragment.java From YCAudioPlayer with Apache License 2.0 | 5 votes |
/** * 设置为铃声 */ private void requestSetRingtone(AudioBean localMusic) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(getContext())) { ToastUtils.showShort(R.string.no_permission_setting); Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + getContext().getPackageName())); startActivityForResult(intent, 0); } else { setRingtone(localMusic); } }