Skip to content

Commit

Permalink
Merged in AuahDark/love-android-sdl2/java-fix (pull request love2d#22)
Browse files Browse the repository at this point in the history
Various fixes related to manifest and Java code.
  • Loading branch information
MikuAuahDark authored and slime73 committed Aug 10, 2019
2 parents 8d71234 + 8186794 commit 376ae96
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 71 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ android {
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "org.love2d.android"
versionCode 26
versionName "11.1"
versionCode 27
versionName "11.2"
minSdkVersion 14
targetSdkVersion 28
}
Expand Down
42 changes: 30 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.love2d.android.executable"
android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!-- Allow writing to external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />

<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />
Expand All @@ -14,18 +13,20 @@
android:allowBackup="true"
android:icon="@drawable/love"
android:label="LÖVE for Android"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
android:usesCleartextTraffic="true" >
<service android:name="org.love2d.android.DownloadService" />
<activity
android:name="org.love2d.android.GameActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation"
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation"
android:label="LÖVE for Android"
android:launchMode="singleTop"
android:screenOrientation="landscape" >
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:resizeableActivity="false"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="tv.ouya.intent.category.GAME"/>
<category android:name="tv.ouya.intent.category.GAME" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
Expand All @@ -36,10 +37,27 @@
<data android:pathPattern=".*\\.love" />
<data android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:host="*" />
<data android:mimeType="application/x-love-game" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:host="*" />
<data android:mimeType="application/octet-stream" />
</intent-filter>
</activity>
<activity
android:name="org.love2d.android.DownloadActivity"
android:noHistory="true" >
android:noHistory="true"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
2 changes: 0 additions & 2 deletions love/src/jni/love/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ LOCAL_STATIC_LIBRARIES := libvorbis libogg libtheora libmodplug libfreetype libl
# $(info liblove: include dirs $(LOCAL_C_INCLUDES))
# $(info liblove: src files $(LOCAL_SRC_FILES))

SDL_PATH := ../SDL2-2.0.9
LOCAL_SRC_FILES += $(SDL_PATH)/src/main/android/SDL_android_main.c
LOCAL_LDLIBS := -lz -lGLESv1_CM -lGLESv2 -ldl -landroid
LOCAL_LDFLAGS := -Wl,--allow-multiple-definition

Expand Down
68 changes: 61 additions & 7 deletions love/src/main/java/org/love2d/android/DownloadActivity.java
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);
}
}
}
4 changes: 2 additions & 2 deletions love/src/main/java/org/love2d/android/DownloadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ protected void onHandleIntent(Intent intent) {
String url = intent.getStringExtra("url");
Uri uri = Uri.parse(url);

Log.d("DownloadService", "Downloading from url: " + url + "file = " + uri.getLastPathSegment());
Log.d("DownloadService", "Downloading from url: " + url + " file = " + uri.getLastPathSegment());

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDescription("LÖVE Game Download");
request.setTitle(uri.getLastPathSegment());
request.setMimeType("application/x-love-game");
Expand Down
Loading

0 comments on commit 376ae96

Please sign in to comment.