This commit is contained in:
dgis 2019-02-13 19:00:24 +00:00
parent 79f9977dcb
commit d68014524e
3 changed files with 79 additions and 160 deletions

View file

@ -44,84 +44,23 @@
android:pathPattern=".*\\.e49"
android:host="*"/>
<data android:scheme="file"
android:mimeType="*/*"
android:pathPattern=".*\\.e38"
android:host="*"/>
<data android:scheme="file"
android:mimeType="*/*"
android:pathPattern=".*\\.e39"
android:host="*"/>
<data android:scheme="file"
android:mimeType="*/*"
android:pathPattern=".*\\.e48"
android:host="*"/>
<data android:scheme="file"
android:mimeType="*/*"
android:pathPattern=".*\\.e49"
android:host="*"/>
<!--<data android:scheme="file"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e38"-->
<!--android:host="*"/>-->
<!--<data android:scheme="file"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e39"-->
<!--android:host="*"/>-->
<!--<data android:scheme="file"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e48"-->
<!--android:host="*"/>-->
<!--<data android:scheme="file"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e49"-->
<!--android:host="*"/>-->
</intent-filter>
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.VIEW" />-->
<!--<category android:name="android.intent.category.DEFAULT" />-->
<!--<category android:name="android.intent.category.BROWSABLE" />-->
<!--&lt;!&ndash;<data android:scheme="content" />&ndash;&gt;-->
<!--&lt;!&ndash;<data android:mimeType="*/*" />&ndash;&gt;-->
<!--&lt;!&ndash;<data android:pathPattern=".*\\.e48" />&ndash;&gt;-->
<!--&lt;!&ndash;<data android:host="*" />&ndash;&gt;-->
<!---->
<!--<data android:scheme="content"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e38"-->
<!--android:host="*"/>-->
<!--<data android:scheme="content"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e39"-->
<!--android:host="*"/>-->
<!--<data android:scheme="content"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e48"-->
<!--android:host="*"/>-->
<!--<data android:scheme="content"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e49"-->
<!--android:host="*"/>-->
<!--<data android:scheme="file"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e38"-->
<!--android:host="*"/>-->
<!--<data android:scheme="file"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e39"-->
<!--android:host="*"/>-->
<!--<data android:scheme="file"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e48"-->
<!--android:host="*"/>-->
<!--<data android:scheme="file"-->
<!--android:mimeType="*/*"-->
<!--android:pathPattern=".*\\.e49"-->
<!--android:host="*"/>-->
<!--</intent-filter>-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.VIEW" />-->
<!--<category android:name="android.intent.category.DEFAULT" />-->
<!--<category android:name="android.intent.category.BROWSABLE" />-->
<!--<data android:scheme="file" />-->
<!--<data android:mimeType="*/*" />-->
<!--<data android:pathPattern=".*\\.kml" />-->
<!--<data android:host="*" />-->
<!--</intent-filter>-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.VIEW" />-->
<!--<category android:name="android.intent.category.DEFAULT" />-->
<!--<category android:name="android.intent.category.BROWSABLE" />-->
<!--<data android:scheme="content" />-->
<!--<data android:mimeType="*/*" />-->
<!--<data android:pathPattern=".*\\.kml" />-->
<!--<data android:host="*" />-->
<!--</intent-filter>-->
</activity>
<activity
android:name="org.emulator.forty.eight.SettingsActivity"

View file

@ -165,7 +165,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
android.os.Debug.waitForDebugger();
//android.os.Debug.waitForDebugger();
String documentToOpenUrl = sharedPreferences.getString("lastDocument", "");
@ -180,13 +180,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (documentToOpenUri != null) {
String scheme = documentToOpenUri.getScheme();
if(scheme != null && scheme.compareTo("file") == 0) {
// documentToOpenUrl = documentToOpenUri.getPath();
// isFileAndNeedPermission = true;
File file = new File(documentToOpenUri.toString());
//Uri uri = FileProvider.getUriForFile(this, "androidx.core.content.FileProvider", file /* file whose Uri is required */);
Uri uri = getImageContentUri(this, file);
documentToOpenUrl = uri.getPath();
// File file = new File(documentToOpenUri.toString());
// //Uri uri = FileProvider.getUriForFile(this, "androidx.core.content.FileProvider", file /* file whose Uri is required */);
// documentToOpenUrl = uri.getPath();
documentToOpenUrl = null;
} else
documentToOpenUrl = documentToOpenUri.toString();
}
@ -220,31 +218,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
drawer.openDrawer(GravityCompat.START);
}
public static Uri getImageContentUri(Context context, File imageFile) {
String filePath = imageFile.getAbsolutePath();
String filePath = imageFile.getAbsolutePath();
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Images.Media._ID },
MediaStore.Images.Media.DATA + "=? ",
new String[] { filePath }, null);
if (cursor != null && cursor.moveToFirst()) {
int id = cursor.getInt(cursor
.getColumnIndex(MediaStore.MediaColumns._ID));
Uri baseUri = Uri.parse("content://media/external/images/media");
return Uri.withAppendedPath(baseUri, "" + id);
} else {
if (imageFile.exists()) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, filePath);
return context.getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} else {
return null;
}
}}
private void updateMRU() {
Menu menu = navigationView.getMenu();
MenuItem recentsMenuItem = menu.findItem(R.id.nav_item_recents);

View file

@ -8,34 +8,66 @@ import android.provider.MediaStore;
import android.provider.OpenableColumns;
public class Utils {
public static String getFileName(Context context, String url) {
Uri uri = Uri.parse(url);
static String getFileName(Context context, String url) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst())
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
} finally {
cursor.close();
Uri uri = Uri.parse(url);
if(uri != null) {
String scheme = uri.getScheme();
if (scheme != null && scheme.equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
if(cursor != null) {
try {
if (cursor.moveToFirst())
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
} finally {
cursor.close();
}
}
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
if (result == null) {
result = uri.getPath();
if(result != null) {
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
}
}
return result;
}
public static String getFilePath(Context context, String url) {
Uri uri = Uri.parse(url);
String result = null;
if (uri.getScheme().equals("content")) {
// //Cursor cursor = context.getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
// Cursor cursor = context.getContentResolver().query(uri, new String[] { android.provider.MediaStore.Files.FileColumns.DATA }, null, null, null);
// public static String getFilePath(Context context, String url) {
// Uri uri = Uri.parse(url);
// String result = null;
// if (uri.getScheme().equals("content")) {
//// //Cursor cursor = context.getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
//// Cursor cursor = context.getContentResolver().query(uri, new String[] { android.provider.MediaStore.Files.FileColumns.DATA }, null, null, null);
//// try {
//// if (cursor != null && cursor.moveToFirst()) {
//// result = cursor.getString(0);
//// //result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
//// }
//// } finally {
//// cursor.close();
//// }
//
////https://stackoverflow.com/questions/13209494/how-to-get-the-full-file-path-from-uri
//// String wholeID = DocumentsContract.getDocumentId(uri);
//// String id = wholeID.split(":")[1];
//// String[] column = { MediaStore.Images.Media.DATA };
//// //String[] column = { MediaStore.Files.FileColumns.DATA };
//// String sel = MediaStore.Images.Media._ID + "=?";
//// Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column, sel, new String[]{ id }, null);
//// //Cursor cursor = context.getContentResolver().query(MediaStore.Files.get, column, sel, new String[]{ id }, null);
//// int columnIndex = cursor.getColumnIndex(column[0]);
//// if (cursor.moveToFirst()) {
//// result = cursor.getString(columnIndex);
//// }
//// cursor.close();
//
//
// Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
// try {
// if (cursor != null && cursor.moveToFirst()) {
// result = cursor.getString(0);
@ -44,34 +76,9 @@ public class Utils {
// } finally {
// cursor.close();
// }
//https://stackoverflow.com/questions/13209494/how-to-get-the-full-file-path-from-uri
// String wholeID = DocumentsContract.getDocumentId(uri);
// String id = wholeID.split(":")[1];
// String[] column = { MediaStore.Images.Media.DATA };
// //String[] column = { MediaStore.Files.FileColumns.DATA };
// String sel = MediaStore.Images.Media._ID + "=?";
// Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column, sel, new String[]{ id }, null);
// //Cursor cursor = context.getContentResolver().query(MediaStore.Files.get, column, sel, new String[]{ id }, null);
// int columnIndex = cursor.getColumnIndex(column[0]);
// if (cursor.moveToFirst()) {
// result = cursor.getString(columnIndex);
// }
// cursor.close();
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(0);
//result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
if (result == null)
result = url;
return result;
}
// }
// if (result == null)
// result = url;
// return result;
// }
}