forked from love2d/love-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in AuahDark/love-android-sdl2/java-fix (pull request love2d#22)
Various fixes related to manifest and Java code.
- Loading branch information
Showing
6 changed files
with
182 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 61 additions & 7 deletions
68
love/src/main/java/org/love2d/android/DownloadActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,78 @@ | ||
package org.love2d.android; | ||
|
||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.Manifest; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import androidx.core.app.ActivityCompat; | ||
|
||
public class DownloadActivity extends Activity { | ||
public static final int EXTERNAL_STORAGE_REQUEST_CODE = 2; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
Uri uri = this.getIntent().getData(); | ||
if (android.os.Build.VERSION.SDK_INT >= 29 || | ||
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) | ||
{ | ||
runDownloader(); | ||
finish(); | ||
} else { | ||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_REQUEST_CODE); | ||
} | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
||
if (uri.getScheme().equals("http")) { | ||
String url = uri.toString(); | ||
Intent intent = new Intent(this, DownloadService.class); | ||
intent.putExtra("url", url); | ||
startService(intent); | ||
if (grantResults.length > 0) { | ||
Log.d("DownloadActivity", "Received a request permission result"); | ||
|
||
if (requestCode == EXTERNAL_STORAGE_REQUEST_CODE) { | ||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
runDownloader(); | ||
finish(); | ||
} else { | ||
Log.d("DownloadActivity", "Did not get permission."); | ||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { | ||
showExternalStoragePermissionMissingDialog(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
finish(); | ||
protected void showExternalStoragePermissionMissingDialog() { | ||
AlertDialog dialog = new AlertDialog.Builder(this) | ||
.setTitle("Storage Permission Missing") | ||
.setMessage("LÖVE for Android will not be able to download games without storage permission.") | ||
.setNeutralButton("Continue", new DialogInterface.OnClickListener() { | ||
public void onClick(DialogInterface dialog, int whichButton) { | ||
dialog.dismiss(); | ||
finish(); | ||
} | ||
}) | ||
.create(); | ||
dialog.show(); | ||
} | ||
|
||
protected void runDownloader() | ||
{ | ||
Intent intent = getIntent(); | ||
|
||
if (intent != null) { | ||
Uri uri = intent.getData(); | ||
Intent targetIntent = new Intent(this, DownloadService.class); | ||
targetIntent.putExtra("url", uri.toString()); | ||
startService(targetIntent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.