File indexing completed on 2024-05-12 05:46:27
0001 /* 0002 * Copyright (C) 2007-2008 OpenIntents.org 0003 * 0004 * Licensed under the Apache License, Version 2.0 (the "License"); 0005 * you may not use this file except in compliance with the License. 0006 * You may obtain a copy of the License at 0007 * 0008 * http://www.apache.org/licenses/LICENSE-2.0 0009 * 0010 * Unless required by applicable law or agreed to in writing, software 0011 * distributed under the License is distributed on an "AS IS" BASIS, 0012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0013 * See the License for the specific language governing permissions and 0014 * limitations under the License. 0015 * 0016 * This file was modified by Sharaf Zaman <sharafzaz121@gmail.com> from 0017 * following original file: https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java 0018 */ 0019 0020 package org.krita.android; 0021 0022 import android.content.Context; 0023 import android.net.Uri; 0024 import android.os.Environment; 0025 import android.provider.DocumentsContract; 0026 0027 0028 @SuppressWarnings("unused") 0029 public class FileUtils { 0030 private FileUtils() {} 0031 0032 public static boolean isExternalStorageDocument(Uri uri) { 0033 return "com.android.externalstorage.documents".equals(uri.getAuthority()); 0034 } 0035 0036 public static String getPath(final Context context, final Uri uri) { 0037 if (DocumentsContract.isDocumentUri(context, uri) && isExternalStorageDocument(uri)) { 0038 final String docId = DocumentsContract.getDocumentId(uri); 0039 final String[] split = docId.split(":"); 0040 final String type = split[0]; 0041 0042 if ("primary".equalsIgnoreCase(type)) { 0043 return Environment.getExternalStorageDirectory() + "/" + split[1]; 0044 } 0045 } 0046 return uri.toString(); 0047 } 0048 }