0

I have made an appWidget with a collection view. And in order to handle a click event on each view of the collection view, I used 'setPendingIntentTemplate' and 'setOnClickFillInIntent'. It is working fine in a normal case. It opens up the target activity by sending the intent upon click. But if an invalid uri (it is just not a valid uri for the target activity, but in syntax, it is a valid uri.) is injected to the intent for it, the widget just simply doesn't handle the click event. It doesn't throw any exception or return any error.

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
view.setOnClickFillInIntent(R.id.image, intent);

Is there any way to catch this error (the click event is not being handled due to the intent with an invalid uri)? - So that, I can switch to different code to handle the situation.

juniano
  • 354
  • 4
  • 13
  • Have you put this code in `try..catch` block? – Apurva Mar 03 '15 at 15:03
  • Yes I did, but nothing happened. And also traced back to the source code of it. It doesn't seem to throw any exception. – juniano Mar 03 '15 at 15:35
  • logcat doesn't show anything since it doesn't throw any exception. I turned all logcat options on but unfortunately, couldn't find anything relevant. – juniano Mar 03 '15 at 16:45

1 Answers1

0

I was able to get a solution for this problem from another forum I also posted the same question.

Basically, exception handling for an Intent which is already executed is not possible.

But, there is a way to check if a target component (activity, service or receiver) exists for the intent before adding a PendingIntent

getPackageManager().queryIntentActivities( intent, flags )

If this returns an empty array, that means there is no activity that can be executed by the intent. With this method, you can determine whether you add a PendingIntent or not.

juniano
  • 354
  • 4
  • 13