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:pathPattern=".*\\.e49"
android:host="*"/> android:host="*"/>
<data android:scheme="file" <!--<data android:scheme="file"-->
android:mimeType="*/*" <!--android:mimeType="*/*"-->
android:pathPattern=".*\\.e38" <!--android:pathPattern=".*\\.e38"-->
android:host="*"/> <!--android:host="*"/>-->
<data android:scheme="file" <!--<data android:scheme="file"-->
android:mimeType="*/*" <!--android:mimeType="*/*"-->
android:pathPattern=".*\\.e39" <!--android:pathPattern=".*\\.e39"-->
android:host="*"/> <!--android:host="*"/>-->
<data android:scheme="file" <!--<data android:scheme="file"-->
android:mimeType="*/*" <!--android:mimeType="*/*"-->
android:pathPattern=".*\\.e48" <!--android:pathPattern=".*\\.e48"-->
android:host="*"/> <!--android:host="*"/>-->
<data android:scheme="file" <!--<data android:scheme="file"-->
android:mimeType="*/*" <!--android:mimeType="*/*"-->
android:pathPattern=".*\\.e49" <!--android:pathPattern=".*\\.e49"-->
android:host="*"/> <!--android:host="*"/>-->
</intent-filter> </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>
<activity <activity
android:name="org.emulator.forty.eight.SettingsActivity" 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", ""); String documentToOpenUrl = sharedPreferences.getString("lastDocument", "");
@ -180,13 +180,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (documentToOpenUri != null) { if (documentToOpenUri != null) {
String scheme = documentToOpenUri.getScheme(); String scheme = documentToOpenUri.getScheme();
if(scheme != null && scheme.compareTo("file") == 0) { if(scheme != null && scheme.compareTo("file") == 0) {
// documentToOpenUrl = documentToOpenUri.getPath();
// isFileAndNeedPermission = true; // isFileAndNeedPermission = true;
// File file = new File(documentToOpenUri.toString());
File file = new File(documentToOpenUri.toString()); // //Uri uri = FileProvider.getUriForFile(this, "androidx.core.content.FileProvider", file /* file whose Uri is required */);
//Uri uri = FileProvider.getUriForFile(this, "androidx.core.content.FileProvider", file /* file whose Uri is required */); // documentToOpenUrl = uri.getPath();
Uri uri = getImageContentUri(this, file); documentToOpenUrl = null;
documentToOpenUrl = uri.getPath();
} else } else
documentToOpenUrl = documentToOpenUri.toString(); documentToOpenUrl = documentToOpenUri.toString();
} }
@ -220,31 +218,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
drawer.openDrawer(GravityCompat.START); 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() { private void updateMRU() {
Menu menu = navigationView.getMenu(); Menu menu = navigationView.getMenu();
MenuItem recentsMenuItem = menu.findItem(R.id.nav_item_recents); MenuItem recentsMenuItem = menu.findItem(R.id.nav_item_recents);

View file

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