Skip to content

Commit

Permalink
Make AndroidNet#openURI compatible with targetSdk 30, fixes #6377 (#6408
Browse files Browse the repository at this point in the history
)

* Make AndroidNet#openURI compatible with targetSdk 30, fixes #6377
  • Loading branch information
MrStahlfelge committed Feb 9, 2021
1 parent a5cded4 commit 69066f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGES
@@ -1,6 +1,7 @@
[1.9.15]
- Scene2d.ui: Added new ParticleEffectActor to use particle effects on Stage
- API addition: iOS: Added HdpiMode option to IOSApplicationConfiguration to allow users to set whether they want to work in logical or raw pixels (default logical).
- Fix for #6377 Gdx.net.openURI not working with targetSdk 30

[1.9.14]
- [BREAKING CHANGE] iOS: IOSUIViewController has been moved to its own separate class
Expand Down
Expand Up @@ -17,8 +17,8 @@
package com.badlogic.gdx.backends.android;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;

import com.badlogic.gdx.Net;
Expand Down Expand Up @@ -71,24 +71,18 @@ public Socket newClientSocket (Protocol protocol, String host, int port, SocketH

@Override
public boolean openURI (String URI) {
boolean result = false;
final Uri uri = Uri.parse(URI);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
PackageManager pm = app.getContext().getPackageManager();
if (pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
app.runOnUiThread(new Runnable() {
@Override
public void run () {
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);
}
});
result = true;
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;
}
return result;
}

}

0 comments on commit 69066f1

Please sign in to comment.