|
30 | 30 | import java.io.FileOutputStream; |
31 | 31 | import java.io.InputStream; |
32 | 32 | import java.io.OutputStream; |
| 33 | +import java.net.URISyntaxException; |
33 | 34 |
|
34 | 35 | public class IntentHelper { |
| 36 | + private static final String TAG = "IntentHelper"; |
| 37 | + |
| 38 | + public static void openUri(Context context, String uri) { |
| 39 | + if (uri.startsWith("intent://")) { |
| 40 | + try { |
| 41 | + startActivity(context, Intent.parseUri(uri, Intent.URI_INTENT_SCHEME), false); |
| 42 | + } catch (URISyntaxException | ActivityNotFoundException e) { |
| 43 | + Log.e(TAG, "Failed launch of " + uri, e); |
| 44 | + } |
| 45 | + } else openUrl(context, uri); |
| 46 | + } |
| 47 | + |
35 | 48 | public static void openUrl(Context context, String url) { |
36 | 49 | openUrl(context, url, false); |
37 | 50 | } |
@@ -227,7 +240,7 @@ public static void openFileTo(CompatActivity compatActivity, File destination, |
227 | 240 | callback.onReceived(destination, null, RESPONSE_ERROR); |
228 | 241 | return; |
229 | 242 | } |
230 | | - Log.d("IntentHelper", "FilePicker returned " + uri); |
| 243 | + Log.d(TAG, "FilePicker returned " + uri); |
231 | 244 | if ("http".equals(uri.getScheme()) || |
232 | 245 | "https".equals(uri.getScheme())) { |
233 | 246 | callback.onReceived(destination, uri, RESPONSE_URL); |
@@ -259,15 +272,15 @@ public static void openFileTo(CompatActivity compatActivity, File destination, |
259 | 272 | Files.copy(inputStream, outputStream); |
260 | 273 | success = true; |
261 | 274 | } catch (Exception e) { |
262 | | - Log.e("IntentHelper", "failed copy of " + uri, e); |
| 275 | + Log.e(TAG, "failed copy of " + uri, e); |
263 | 276 | Toast.makeText(compatActivity, |
264 | 277 | R.string.file_picker_failure, |
265 | 278 | Toast.LENGTH_SHORT).show(); |
266 | 279 | } finally { |
267 | 280 | Files.closeSilently(inputStream); |
268 | 281 | Files.closeSilently(outputStream); |
269 | 282 | if (!success && destination.exists() && !destination.delete()) |
270 | | - Log.e("IntentHelper", "Failed to delete artefact!"); |
| 283 | + Log.e(TAG, "Failed to delete artefact!"); |
271 | 284 | } |
272 | 285 | callback.onReceived(destination, uri, success ? RESPONSE_FILE : RESPONSE_ERROR); |
273 | 286 | }); |
|
0 commit comments