don't use fileprovider when opening files on android M and below
This commit is contained in:
parent
d2c475d501
commit
1dc55f72e3
|
@ -11,6 +11,7 @@ import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.support.v4.content.FileProvider;
|
import android.support.v4.content.FileProvider;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
|
@ -716,21 +717,30 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
if (mime == null) {
|
if (mime == null) {
|
||||||
mime = "*/*";
|
mime = "*/*";
|
||||||
}
|
}
|
||||||
Uri uri = FileProvider.getUriForFile(activity,"eu.siacs.conversations.files",file);
|
Uri uri;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
try {
|
||||||
|
uri = FileProvider.getUriForFile(activity, "eu.siacs.conversations.files", file);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
Toast.makeText(activity,activity.getString(R.string.no_permission_to_access_x,file.getAbsolutePath()), Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
openIntent.setDataAndType(uri, mime);
|
||||||
|
openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
} else {
|
||||||
|
uri = Uri.fromFile(file);
|
||||||
|
}
|
||||||
openIntent.setDataAndType(uri, mime);
|
openIntent.setDataAndType(uri, mime);
|
||||||
openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
||||||
PackageManager manager = activity.getPackageManager();
|
PackageManager manager = activity.getPackageManager();
|
||||||
List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0);
|
List<ResolveInfo> info = manager.queryIntentActivities(openIntent, 0);
|
||||||
if (infos.size() == 0) {
|
if (info.size() == 0) {
|
||||||
openIntent.setDataAndType(Uri.fromFile(file),"*/*");
|
openIntent.setDataAndType(Uri.fromFile(file),"*/*");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
getContext().startActivity(openIntent);
|
getContext().startActivity(openIntent);
|
||||||
return;
|
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
//ignored
|
Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showLocation(Message message) {
|
public void showLocation(Message message) {
|
||||||
|
|
|
@ -679,4 +679,5 @@
|
||||||
<string name="me">Me</string>
|
<string name="me">Me</string>
|
||||||
<string name="contact_asks_for_presence_subscription">Contact asks for presence subscription</string>
|
<string name="contact_asks_for_presence_subscription">Contact asks for presence subscription</string>
|
||||||
<string name="allow">Allow</string>
|
<string name="allow">Allow</string>
|
||||||
|
<string name="no_permission_to_access_x">No permission to access %s</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue