MCPcopy Create free account
hub / github.com/M66B/FairEmail / _share

Method _share

app/src/main/java/eu/faircode/email/Helper.java:1135–1186  ·  view source on GitHub ↗
(Context context, Uri uri, String type, String name)

Source from the content-addressed store, hash-verified

1133 }
1134
1135 private static void _share(Context context, Uri uri, String type, String name) {
1136 Log.i("uri=" + uri + " type=" + type);
1137
1138 // Build intent
1139 Intent intent = new Intent(Intent.ACTION_VIEW);
1140 intent.setDataAndTypeAndNormalize(uri, type);
1141 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
1142
1143 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
1144 boolean share_task = prefs.getBoolean("share_task", false);
1145 if (share_task)
1146 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1147
1148 if (launchAdjacent(context, true))
1149 intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
1150
1151 if (!TextUtils.isEmpty(name))
1152 intent.putExtra(Intent.EXTRA_TITLE, Helper.sanitizeFilename(name));
1153 Log.i("Intent=" + intent + " type=" + type);
1154
1155 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
1156 // Get targets
1157 List<ResolveInfo> ris = null;
1158 try {
1159 PackageManager pm = context.getPackageManager();
1160 int flags = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ? 0 : PackageManager.MATCH_ALL);
1161 ris = pm.queryIntentActivities(intent, flags);
1162 for (ResolveInfo ri : ris) {
1163 Log.i("Target=" + ri);
1164 context.grantUriPermission(ri.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
1165 }
1166 } catch (Throwable ex) {
1167 Log.e(ex);
1168 /*
1169 java.lang.RuntimeException: Package manager has died
1170 at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:571)
1171 at android.app.ApplicationPackageManager.queryIntentActivities(ApplicationPackageManager.java:557)
1172 at eu.faircode.email.Helper.share(SourceFile:489)
1173 */
1174 }
1175
1176 // Check if viewer available
1177 if (ris == null || ris.size() == 0)
1178 if (isTnef(type, null))
1179 viewFAQ(context, 155);
1180 else
1181 reportNoViewer(context, intent, null);
1182 else
1183 context.startActivity(getChooser(context, intent, true));
1184 } else
1185 context.startActivity(getChooser(context, intent, true));
1186 }
1187
1188 static boolean isTnef(String type, String name) {
1189 // https://en.wikipedia.org/wiki/Transport_Neutral_Encapsulation_Format

Callers 1

shareMethod · 0.95

Calls 12

iMethod · 0.95
launchAdjacentMethod · 0.95
sanitizeFilenameMethod · 0.95
eMethod · 0.95
isTnefMethod · 0.95
viewFAQMethod · 0.95
reportNoViewerMethod · 0.95
getChooserMethod · 0.95
getBooleanMethod · 0.80
sizeMethod · 0.65
isEmptyMethod · 0.45
startActivityMethod · 0.45

Tested by

no test coverage detected