Fixed crashing import

Thanks Google for your excellent documentation, ... not!
This commit is contained in:
M66B 2016-07-23 15:38:42 +02:00
parent c0d95e3562
commit 96d06f49c8
1 changed files with 4 additions and 2 deletions

View File

@ -912,7 +912,8 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
Log.i(TAG, "Reading URI=" + data.getData());
ContentResolver resolver = getContentResolver();
String[] streamTypes = resolver.getStreamTypes(data.getData(), "*/*");
AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(data.getData(), streamTypes[0], null);
String streamType = (streamTypes == null || streamTypes.length == 0 ? "*/*" : streamTypes[0]);
AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(data.getData(), streamType, null);
in = descriptor.createInputStream();
out = new FileOutputStream(hosts);
@ -975,7 +976,8 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
Log.i(TAG, "Reading URI=" + data.getData());
ContentResolver resolver = getContentResolver();
String[] streamTypes = resolver.getStreamTypes(data.getData(), "*/*");
AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(data.getData(), streamTypes[0], null);
String streamType = (streamTypes == null || streamTypes.length == 0 ? "*/*" : streamTypes[0]);
AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(data.getData(), streamType, null);
in = descriptor.createInputStream();
xmlImport(in);
return null;