Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added InternalHttpDownloadStrategy

  • Loading branch information...
commit c0cc6554795b1017e0f7b3332dbfd61782c8efc6 1 parent 707ab0d
Mark Murphy authored
View
6 demo/src/com/commonsware/cwac/updater/demo/UpdaterDemoActivity.java
@@ -16,11 +16,13 @@
import android.app.Activity;
import android.app.Notification;
+import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import com.commonsware.cwac.updater.ConfirmationStrategy;
import com.commonsware.cwac.updater.DownloadStrategy;
+import com.commonsware.cwac.updater.InternalHttpDownloadStrategy;
import com.commonsware.cwac.updater.NotificationConfirmationStrategy;
import com.commonsware.cwac.updater.SimpleHttpDownloadStrategy;
import com.commonsware.cwac.updater.SimpleHttpVersionCheckStrategy;
@@ -73,6 +75,10 @@ ConfirmationStrategy buildPreDownloadConfirmationStrategy() {
}
DownloadStrategy buildDownloadStrategy() {
+ if (Build.VERSION.SDK_INT>=11) {
+ return(new InternalHttpDownloadStrategy());
+ }
+
return(new SimpleHttpDownloadStrategy());
}
View
2  project.properties
@@ -8,5 +8,5 @@
# project structure.
# Project target.
-target=android-8
+target=android-14
android.library=true
View
39 src/com/commonsware/cwac/updater/InternalHttpDownloadStrategy.java
@@ -0,0 +1,39 @@
+/***
+Copyright (c) 2012 CommonsWare, LLC
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may
+not use this file except in compliance with the License. You may obtain
+a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */
+
+package com.commonsware.cwac.updater;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.OutputStream;
+import android.content.Context;
+
+public class InternalHttpDownloadStrategy extends
+ SimpleHttpDownloadStrategy {
+ @Override
+ protected File getDownloadFile(Context ctxt) {
+ File updateDir=new File(ctxt.getFilesDir(), ".CWAC-Update");
+
+ updateDir.mkdirs();
+
+ return(new File(updateDir, "update.apk"));
+ }
+
+ @Override
+ protected OutputStream openDownloadFile(Context ctxt, File apk)
+ throws FileNotFoundException {
+ return(ctxt.openFileOutput("update.apk",
+ Context.MODE_WORLD_READABLE));
+ }
+}
View
16 src/com/commonsware/cwac/updater/SimpleHttpDownloadStrategy.java
@@ -15,8 +15,10 @@
package com.commonsware.cwac.updater;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
+import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.content.Context;
@@ -43,7 +45,7 @@ public Uri downloadAPK(Context ctxt, String url) throws Exception {
if (status == 200) {
InputStream is=conn.getInputStream();
- FileOutputStream f=new FileOutputStream(apk);
+ OutputStream f=openDownloadFile(ctxt, apk);
byte[] buffer=new byte[4096];
int len1=0;
@@ -64,7 +66,7 @@ public Uri downloadAPK(Context ctxt, String url) throws Exception {
conn.disconnect();
}
- return(Uri.fromFile(apk));
+ return(getDownloadUri(ctxt, apk));
}
@Override
@@ -77,7 +79,7 @@ public void writeToParcel(Parcel dest, int flags) {
// no-op
}
- private static File getDownloadFile(Context ctxt) {
+ protected File getDownloadFile(Context ctxt) {
File updateDir=
new File(ctxt.getExternalFilesDir(null), ".CWAC-Update");
@@ -85,6 +87,14 @@ private static File getDownloadFile(Context ctxt) {
return(new File(updateDir, "update.apk"));
}
+
+ protected OutputStream openDownloadFile(Context ctxt, File apk) throws FileNotFoundException {
+ return(new FileOutputStream(apk));
+ }
+
+ protected Uri getDownloadUri(Context ctxt, File apk) {
+ return(Uri.fromFile(apk));
+ }
public static final Parcelable.Creator<SimpleHttpDownloadStrategy> CREATOR=
new Parcelable.Creator<SimpleHttpDownloadStrategy>() {
Please sign in to comment.
Something went wrong with that request. Please try again.