question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android openURI(...) not working on Android 11

See original GitHub issue

Issue details

Android’s openURI is not working on Android 11 anymore. Calling openURI(...) does nothing. There is no error thrown.

Version of LibGDX and/or relevant dependencies

Latest stable release 1.9.13. The Android project has to be set to Android 11 (30).

Suggestion for Code Fix

A quick test showed the following code works. The live wallpaper flag needs to be set. Also, does this really need to run via UI thread as in libGDX’s example?

try {
   // open with the correct activity if any 
   startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
   return true;
}
catch (Exception e) {
   // ... log error...
   return false;
}

Please select the affected platforms

  • [x ] Android 11
  • iOS
  • HTML/GWT
  • Windows
  • Linux
  • MacOS

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
MrStahlfelgecommented, Feb 7, 2021

Ah found it, it is not precaution but to make openUri threadsafe: https://github.com/libgdx/libgdx/pull/59#issuecomment-9296572 I don’t see much benefit in having a UI operation threadsafe though.

1reaction
MrStahlfelgecommented, Feb 7, 2021

I was able to reproduce this with a fresh emulator, too. The code @noblemaster gave in the OP works for me, too, or a slightly different variant:

	public boolean openURI (String URI) {
		final Uri uri = Uri.parse(URI);
		try {
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			// LiveWallpaper and Daydream applications need this flag
			if (!(app.getContext() instanceof Activity)) {
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			}
			app.startActivity(intent);
			return true;
		} catch (ActivityNotFoundException e) {
			return false;
		}
	}

According to stackoverflow, using the queries is needed when you need to know if there are applications, but not start them. We don’t have the situation here, and I am sure runOnUiThread is not needed. It was not introduced because of crash reports but from the beginning, probably out of precaution (5ef9a9ef)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simple AndroidApp to open a web link is not working
On Android 11 and above there are limitation to querying other packages. ... getPackageManager()) fails and the startActivity() is not ...
Read more >
Device.OpenURI not working on Android 9? - MSDN - Microsoft
I loaded up my app in an Android 9 emulator, and sure enough, it doesn't open ... OpenUri(uri); worked fine, using a URI...
Read more >
Common Intents - Android Developers
An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view...
Read more >
url_launcher | Flutter Package - Pub.dev
A Flutter plugin for launching a URL. Android, iOS, Linux, macOS, Web, Windows. Support, SDK 16+, 9.0+, Any ...
Read more >
Android API level 30 is here in 3651 - Solar2D Forums
... 3651 since 3650 had issues with Google License Checking Android API level 30 Android introduced breaking change in Android 11 (api 30) ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found