mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #1181 from deltachat/fix-android9-share
use Intent.ACTION_VIEW from an Activity-context
This commit is contained in:
@@ -648,7 +648,7 @@ public class ConversationItem extends LinearLayout
|
||||
|
||||
context.startActivity(intent);
|
||||
} else if (slide.getUri() != null) {
|
||||
dcContext.openForViewOrShare(slide.getDcMsgId(), Intent.ACTION_VIEW);
|
||||
dcContext.openForViewOrShare(context, slide.getDcMsgId(), Intent.ACTION_VIEW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class ProfileDocumentsFragment
|
||||
return;
|
||||
}
|
||||
|
||||
dcContext.openForViewOrShare(dcMsg.getId(), Intent.ACTION_VIEW);
|
||||
dcContext.openForViewOrShare(getActivity(), dcMsg.getId(), Intent.ACTION_VIEW);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.thoughtcrime.securesms.connect;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -148,7 +149,17 @@ public class ApplicationDcContext extends DcContext {
|
||||
|
||||
public static HashMap<String, Integer> sharedFiles = new HashMap<>();
|
||||
|
||||
public void openForViewOrShare(int msg_id, String cmd) {
|
||||
public void openForViewOrShare(Context activity,
|
||||
int msg_id, String cmd) {
|
||||
|
||||
if(!(activity instanceof Activity)) {
|
||||
// would be nicer to accepting only Activity objects,
|
||||
// however, typically in Android just Context objects are passed around (as this normally does not make a difference).
|
||||
// Accepting only Activity here would force callers to cast, which would easily result in even more ugliness.
|
||||
Toast.makeText(context, "openForViewOrShare() expects an Activity object", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
DcMsg msg = getMsg(msg_id);
|
||||
String path = msg.getFile();
|
||||
String mimeType = msg.getFilemime();
|
||||
@@ -175,22 +186,14 @@ public class ApplicationDcContext extends DcContext {
|
||||
mimeType = checkMime(path, mimeType);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, mimeType);
|
||||
if( Build.VERSION.SDK_INT <= 23 ) {
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
} else {
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
activity.startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType(mimeType);
|
||||
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
if( Build.VERSION.SDK_INT <= 23 ) {
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
} else {
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
}
|
||||
context.startActivity(Intent.createChooser(intent, context.getString(R.string.chat_share_with_title)));
|
||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
activity.startActivity(Intent.createChooser(intent, context.getString(R.string.chat_share_with_title)));
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
Toast.makeText(context, String.format("%s (%s)", context.getString(R.string.no_app_to_handle_data), mimeType), Toast.LENGTH_LONG).show();
|
||||
|
||||
Reference in New Issue
Block a user