From 1ec5c5ea4199e6e6dcf83a13b495a2c6abdb971e Mon Sep 17 00:00:00 2001 From: akaessens <24660231+akaessens@users.noreply.github.com> Date: Tue, 27 Apr 2021 19:41:10 +0200 Subject: [PATCH] Fix Android 11 intent handling related https://developer.android.com/about/versions/11/privacy/package-visibility closes #32 --- .../akdev/nofbeventscraper/EventAdapter.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/akdev/nofbeventscraper/EventAdapter.java b/app/src/main/java/com/akdev/nofbeventscraper/EventAdapter.java index b4a6c1d..42abbc7 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/EventAdapter.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/EventAdapter.java @@ -2,6 +2,7 @@ package com.akdev.nofbeventscraper; import android.app.Dialog; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -14,6 +15,7 @@ import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import androidx.recyclerview.widget.RecyclerView; @@ -116,8 +118,12 @@ public class EventAdapter extends Uri intent_uri = Uri.parse(map_search); Intent map_intent = new Intent(Intent.ACTION_VIEW, intent_uri); - if (map_intent.resolveActivity(view.getContext().getPackageManager()) != null) { + + try { view.getContext().startActivity(map_intent); + } catch (ActivityNotFoundException e) { + Toast toast=Toast.makeText(view.getContext(),"no App installed", Toast.LENGTH_SHORT); + toast.show(); } } }; @@ -145,8 +151,11 @@ public class EventAdapter extends String desc = event.url + "\n\n" + event.description; intent.putExtra(CalendarContract.Events.DESCRIPTION, desc); - if (intent.resolveActivity(view.getContext().getPackageManager()) != null) { + try { view.getContext().startActivity(intent); + } catch (ActivityNotFoundException e) { + Toast toast=Toast.makeText(view.getContext(),"no App installed", Toast.LENGTH_SHORT); + toast.show(); } } }); @@ -213,7 +222,12 @@ public class EventAdapter extends share_intent.setType("text/plain"); share_intent.putExtra(Intent.EXTRA_TEXT, event.url); - view.getContext().startActivity(Intent.createChooser(share_intent, null)); + try { + view.getContext().startActivity(share_intent); + } catch (ActivityNotFoundException e) { + Toast toast=Toast.makeText(view.getContext(),"no App installed", Toast.LENGTH_SHORT); + toast.show(); + } } }); }