Browse Source

fixed opening of .love files when URL is entered in Chrome

fysx 12 years ago
parent
commit
539ca8d4f2
2 changed files with 64 additions and 52 deletions
  1. 53 48
      AndroidManifest.xml
  2. 11 4
      src/org/love2d/android/DownloadService.java

+ 53 - 48
AndroidManifest.xml

@@ -9,55 +9,60 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 
     <application
-        android:allowBackup="true"
-        android:icon="@drawable/ic_launcher"
+      android:allowBackup="true"
+      android:icon="@drawable/ic_launcher"
+      android:label="LÖVE for Android"
+      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
+      <service android:name=".DownloadService" />
+      <activity
+        android:name="GameActivity"
+        android:configChanges="orientation|screenSize"
         android:label="LÖVE for Android"
-        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
-        <service android:name=".DownloadService" />
-        <activity
-            android:name="GameActivity"
-            android:configChanges="orientation|screenSize"
-            android:label="LÖVE for Android"
-            android:screenOrientation="landscape" >
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-                <category android:name="tv.ouya.intent.category.GAME"/>
-            </intent-filter>
-        </activity>
-        <activity
-            android:name="GameActivity"
-            android:configChanges="orientation|screenSize"
-            android:screenOrientation="landscape" >
-            <intent-filter>
-                <action android:name="android.intent.action.VIEW" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <data android:scheme="file" />
-                <data android:scheme="content" />
-                <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" />
-                <data android:scheme="file" />
-                <data android:mimeType="*/*" />
-                <data android:pathPattern=".*\\.love" />
-                <data android:host="*" />
-            </intent-filter>
-        </activity>
-        <activity
-          android:name="DownloadActivity" 
-          android:noHistory="true" >
-            <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="http" />
-                <data android:scheme="https" />
-                <data android:host="*" />
-                <data android:pathPattern=".*\\.love" />
-            </intent-filter>
-        </activity>
+        android:screenOrientation="landscape" >
+        <intent-filter>
+          <action android:name="android.intent.action.MAIN" />
+          <category android:name="android.intent.category.LAUNCHER" />
+          <category android:name="tv.ouya.intent.category.GAME"/>
+        </intent-filter>
+      </activity>
+      <activity
+        android:name="GameActivity"
+        android:configChanges="orientation|screenSize"
+        android:screenOrientation="landscape" >
+        <intent-filter>
+          <action android:name="android.intent.action.VIEW" />
+          <category android:name="android.intent.category.DEFAULT" />
+          <data android:scheme="file" />
+          <data android:scheme="content" />
+          <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" />
+          <data android:scheme="file" />
+          <data android:mimeType="*/*" />
+          <data android:pathPattern=".*\\.love" />
+          <data android:host="*" />
+        </intent-filter>
+      </activity>
+      <activity
+        android:name="DownloadActivity" 
+        android:noHistory="true" >
+        <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="http"
+            android:host="*"
+            android:pathPrefix="*"
+            android:mimeType="*/*"
+            android:pathPattern=".*\\.love" />
+          <data android:scheme="https"
+            android:host="*"
+            android:pathPrefix="*"
+            android:pathPattern=".*\\.love" />
+        </intent-filter>
+      </activity>
     </application>
 
     <!-- Android 2.3.3 -->

+ 11 - 4
src/org/love2d/android/DownloadService.java

@@ -22,7 +22,7 @@ public class DownloadService extends IntentService {
 
     @Override
     public void onDestroy() {
-    	Log.d("DownloadService", "ending");
+    	Log.d("DownloadService", "destroying");
     	unregisterReceiver(downloadReceiver);
     }
     
@@ -33,7 +33,7 @@ public class DownloadService extends IntentService {
         String url = intent.getStringExtra("url");
         Uri uri = Uri.parse(url);
 
-        Log.d("DownloadActivity", "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));
         request.setDescription("LÖVE Game Download");
@@ -42,8 +42,8 @@ public class DownloadService extends IntentService {
         
        	// in order for this if to run, you must use the android 3.2 to compile your app
         	if (Build.VERSION.SDK_INT >= 11) {
-        	    request.allowScanningByMediaScanner();
-        	    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+						DownloadRequestSettings_API11 settings = new DownloadRequestSettings_API11();
+						settings.setup (request);
         	}
         	request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, uri.getLastPathSegment());
         // get download service and enqueue file
@@ -87,3 +87,10 @@ public class DownloadService extends IntentService {
     	}
     };     
 }
+
+class DownloadRequestSettings_API11 {
+	public static void setup (DownloadManager.Request request) {
+		request.allowScanningByMediaScanner();
+		request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+	}
+}