Skip to content

Commit

Permalink
Make AndroidNet#openURI compatible with targetSdk 30, fixes libgdx#6377
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStahlfelge committed Feb 8, 2021
1 parent 4b1212b commit 3843be9
Showing 1 changed file with 11 additions and 17 deletions.
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 3843be9

Please sign in to comment.