diff options
author | volzhs <volzhs@gmail.com> | 2016-05-20 22:57:49 +0900 |
---|---|---|
committer | volzhs <volzhs@gmail.com> | 2016-05-20 22:57:49 +0900 |
commit | 160713d4d36ab4bd5f9b53d0d3e0c69d7e4960f7 (patch) | |
tree | 78686a17e29b4afd6b331b0d712690e3dc35cc0c | |
parent | 926495d8eb11de2878319ba54f30812fa1637d72 (diff) |
Supporting Android API 23 (Android 6.0)
If we update build gradle to use ``compileSdkVersion 23``,
``org.apache.http`` package causes error. (issue #4711)
We need to use ``useLibrary 'org.apache.http.legacy'`` to solve this problem.
To use ``useLibrary``, we need to use latest gradle also.
And now, we faced another problem with ``APK Expansion`` java sources.
```
/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadNotification.java
137 : mCurrentNotification.setLatestEventInfo(mContext, mCurrentTitle, mCurrentText, mContentIntent); // causes error
```
So, some of APK Expansion java sources are updated by referencing commits from https://github.com/danikula/Google-Play-Expansion-File
And dropped V3CustomNotification.java which was for android 3.0, since godot supports android 14 (4.0) above officially.
Unfortunately, another problem, The 'MissingTranslation' error was occurred.
So, build.gradle is updated to use ``disable 'MissingTranslation'``
Additionally, I updated ``buildToolsVersion``, ``targetSdkVersion`` to latest version.
I tested APK Expansion funtionality on Android 6.0 (Nexus 9, Nexus 6p) and Android 4.4 (Galaxy Note 2) with Google Developer console.
10 files changed, 40 insertions, 151 deletions
diff --git a/platform/android/build.gradle.template b/platform/android/build.gradle.template index 9461cd2e99..b960d396ee 100644 --- a/platform/android/build.gradle.template +++ b/platform/android/build.gradle.template @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.2.0' + classpath 'com.android.tools.build:gradle:1.3.1' } } @@ -25,10 +25,12 @@ android { lintOptions { abortOnError false + disable 'MissingTranslation' } - compileSdkVersion 19 - buildToolsVersion "19.1" + compileSdkVersion 23 + buildToolsVersion "23.0.3" + useLibrary 'org.apache.http.legacy' packagingOptions { exclude 'META-INF/LICENSE' @@ -36,7 +38,7 @@ android { } defaultConfig { minSdkVersion 14 - targetSdkVersion 19 + targetSdkVersion 23 } sourceSets { main { diff --git a/platform/android/java/res/layout/downloading_expansion.xml b/platform/android/java/res/layout/downloading_expansion.xml index 553155dcd3..d678d94eac 100644 --- a/platform/android/java/res/layout/downloading_expansion.xml +++ b/platform/android/java/res/layout/downloading_expansion.xml @@ -80,7 +80,7 @@ </RelativeLayout> <LinearLayout - android:id="@+id/downloaderDashboard" + android:id="@+id/downloadButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > diff --git a/platform/android/java/res/values-fa/strings.xml b/platform/android/java/res/values-fa/strings.xml index 450f9fe212..f1e29013c4 100644 --- a/platform/android/java/res/values-fa/strings.xml +++ b/platform/android/java/res/values-fa/strings.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <resources> <string name="godot_project_name_string">godot-project-name-fa</string> - <string name="testuf8">سلام</string> <string name="text_paused_cellular">آیا می خواهید بر روی اتصال داده همراه دانلود را شروع کنید؟ بر اساس نوع سطح داده شما این ممکن است برای شما هزینه مالی داشته باشد.</string> <string name="text_paused_cellular_2">اگر نمی خواهید بر روی اتصال داده همراه دانلود را شروع کنید ، دانلود به صورت خودکار در زمان دسترسی به وای-فای شروع می شود.</string> <string name="text_button_resume_cellular">ادامه دانلود</string> diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/Constants.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/Constants.java index ff2c6f535a..2af33b96b9 100644 --- a/platform/android/java/src/com/google/android/vending/expansion/downloader/Constants.java +++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/Constants.java @@ -33,6 +33,10 @@ public class Constants { public static final String EXP_PATH = File.separator + "Android" + File.separator + "obb" + File.separator; + // save to private app's data on Android 6.0 to skip requesting permission. + public static final String EXP_PATH_API23 = File.separator + "Android" + + File.separator + "data" + File.separator; + /** The intent that gets sent when the service must wake up for a retry */ public static final String ACTION_RETRY = "android.intent.action.DOWNLOAD_WAKEUP"; @@ -70,7 +74,7 @@ public class Constants { * The number of times that the download manager will retry its network * operations when no progress is happening before it gives up. */ - public static final int MAX_RETRIES = 5; + public static final int MAX_RETRIES = 10; /** * The minimum amount of time that the download manager accepts for diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/Helpers.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/Helpers.java index b4c28d36e7..ae3fe957cb 100644 --- a/platform/android/java/src/com/google/android/vending/expansion/downloader/Helpers.java +++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/Helpers.java @@ -19,6 +19,7 @@ package com.google.android.vending.expansion.downloader; import com.godot.game.R; import android.content.Context; +import android.os.Build; import android.os.Environment; import android.os.StatFs; import android.os.SystemClock; @@ -220,8 +221,8 @@ public class Helpers { static public String getSaveFilePath(Context c) { File root = Environment.getExternalStorageDirectory(); - String path = root.toString() + Constants.EXP_PATH + c.getPackageName(); - return path; + String path = Build.VERSION.SDK_INT >= 23 ? Constants.EXP_PATH_API23 : Constants.EXP_PATH; + return root.toString() + path + c.getPackageName(); } /** diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/CustomNotificationFactory.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/CustomNotificationFactory.java index 9a0ca02122..e2673a9dd7 100644 --- a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/CustomNotificationFactory.java +++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/CustomNotificationFactory.java @@ -25,6 +25,6 @@ public class CustomNotificationFactory { if (android.os.Build.VERSION.SDK_INT > 13) return new V14CustomNotification(); else - return new V3CustomNotification(); + throw new RuntimeException(); } } diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadNotification.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadNotification.java index d82b658bc3..a9f674803c 100644 --- a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadNotification.java +++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadNotification.java @@ -48,8 +48,8 @@ public class DownloadNotification implements IDownloaderClient { private IDownloaderClient mClientProxy; final ICustomNotification mCustomNotification; - private Notification mNotification; - private Notification mCurrentNotification; + private Notification.Builder mNotificationBuilder; + private Notification.Builder mCurrentNotificationBuilder; private CharSequence mLabel; private String mCurrentText; private PendingIntent mContentIntent; @@ -132,17 +132,14 @@ public class DownloadNotification implements IDownloaderClient { } mCurrentText = mContext.getString(stringDownloadID); mCurrentTitle = mLabel.toString(); - mCurrentNotification.tickerText = mLabel + ": " + mCurrentText; - mCurrentNotification.icon = iconResource; - mCurrentNotification.setLatestEventInfo(mContext, mCurrentTitle, mCurrentText, - mContentIntent); - if (ongoingEvent) { - mCurrentNotification.flags |= Notification.FLAG_ONGOING_EVENT; - } else { - mCurrentNotification.flags &= ~Notification.FLAG_ONGOING_EVENT; - mCurrentNotification.flags |= Notification.FLAG_AUTO_CANCEL; - } - mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification); + mCurrentNotificationBuilder.setTicker(mLabel + ": " + mCurrentText); + mCurrentNotificationBuilder.setSmallIcon(iconResource); + mCurrentNotificationBuilder.setContentTitle(mCurrentTitle); + mCurrentNotificationBuilder.setContentText(mCurrentText); + mCurrentNotificationBuilder.setContentIntent(mContentIntent); + mCurrentNotificationBuilder.setOngoing(ongoingEvent); + mCurrentNotificationBuilder.setAutoCancel(!ongoingEvent); + mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotificationBuilder.build()); } } @@ -154,10 +151,12 @@ public class DownloadNotification implements IDownloaderClient { } if (progress.mOverallTotal <= 0) { // we just show the text - mNotification.tickerText = mCurrentTitle; - mNotification.icon = android.R.drawable.stat_sys_download; - mNotification.setLatestEventInfo(mContext, mLabel, mCurrentText, mContentIntent); - mCurrentNotification = mNotification; + mNotificationBuilder.setTicker(mCurrentTitle); + mNotificationBuilder.setSmallIcon(android.R.drawable.stat_sys_download); + mNotificationBuilder.setContentTitle(mCurrentTitle); + mNotificationBuilder.setContentText(mCurrentText); + mNotificationBuilder.setContentIntent(mContentIntent); + mCurrentNotificationBuilder = mNotificationBuilder; } else { mCustomNotification.setCurrentBytes(progress.mOverallProgress); mCustomNotification.setTotalBytes(progress.mOverallTotal); @@ -166,9 +165,9 @@ public class DownloadNotification implements IDownloaderClient { mCustomNotification.setTicker(mLabel + ": " + mCurrentText); mCustomNotification.setTitle(mLabel); mCustomNotification.setTimeRemaining(progress.mTimeRemaining); - mCurrentNotification = mCustomNotification.updateNotification(mContext); + mCurrentNotificationBuilder = mCustomNotification.updateNotification(mContext); } - mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification); + mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotificationBuilder.build()); } public interface ICustomNotification { @@ -186,7 +185,7 @@ public class DownloadNotification implements IDownloaderClient { void setTimeRemaining(long timeRemaining); - Notification updateNotification(Context c); + Notification.Builder updateNotification(Context c); } /** @@ -219,8 +218,8 @@ public class DownloadNotification implements IDownloaderClient { mContext.getSystemService(Context.NOTIFICATION_SERVICE); mCustomNotification = CustomNotificationFactory .createCustomNotification(); - mNotification = new Notification(); - mCurrentNotification = mNotification; + mNotificationBuilder = new Notification.Builder(ctx); + mCurrentNotificationBuilder = mNotificationBuilder; } diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/V14CustomNotification.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/V14CustomNotification.java index 2e049a4d47..56b2331e31 100644 --- a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/V14CustomNotification.java +++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/V14CustomNotification.java @@ -58,7 +58,7 @@ public class V14CustomNotification implements DownloadNotification.ICustomNotifi } @Override - public Notification updateNotification(Context c) { + public Notification.Builder updateNotification(Context c) { Notification.Builder builder = new Notification.Builder(c); builder.setContentTitle(mTitle); if (mTotalKB > 0 && -1 != mCurrentKB) { @@ -80,7 +80,7 @@ public class V14CustomNotification implements DownloadNotification.ICustomNotifi builder.setContentIntent(mPendingIntent); builder.setOnlyAlertOnce(true); - return builder.getNotification(); + return builder; } @Override diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/V3CustomNotification.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/V3CustomNotification.java deleted file mode 100644 index 94e21de7ca..0000000000 --- a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/V3CustomNotification.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * 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.google.android.vending.expansion.downloader.impl; - -import com.godot.game.R; -import com.google.android.vending.expansion.downloader.Helpers; - -import android.app.Notification; -import android.app.PendingIntent; -import android.content.Context; -import android.graphics.BitmapFactory; -import android.view.View; -import android.widget.RemoteViews; - -public class V3CustomNotification implements DownloadNotification.ICustomNotification { - - CharSequence mTitle; - CharSequence mTicker; - int mIcon; - long mTotalBytes = -1; - long mCurrentBytes = -1; - long mTimeRemaining; - PendingIntent mPendingIntent; - Notification mNotification = new Notification(); - - @Override - public void setIcon(int icon) { - mIcon = icon; - } - - @Override - public void setTitle(CharSequence title) { - mTitle = title; - } - - @Override - public void setTotalBytes(long totalBytes) { - mTotalBytes = totalBytes; - } - - @Override - public void setCurrentBytes(long currentBytes) { - mCurrentBytes = currentBytes; - } - - @Override - public Notification updateNotification(Context c) { - Notification n = mNotification; - - n.icon = mIcon; - - n.flags |= Notification.FLAG_ONGOING_EVENT; - - if (android.os.Build.VERSION.SDK_INT > 10) { - n.flags |= Notification.FLAG_ONLY_ALERT_ONCE; // only matters for - // Honeycomb - } - - // Build the RemoteView object - RemoteViews expandedView = new RemoteViews( - c.getPackageName(), - R.layout.status_bar_ongoing_event_progress_bar); - - expandedView.setTextViewText(R.id.title, mTitle); - // look at strings - expandedView.setViewVisibility(R.id.description, View.VISIBLE); - expandedView.setTextViewText(R.id.description, - Helpers.getDownloadProgressString(mCurrentBytes, mTotalBytes)); - expandedView.setViewVisibility(R.id.progress_bar_frame, View.VISIBLE); - expandedView.setProgressBar(R.id.progress_bar, - (int) (mTotalBytes >> 8), - (int) (mCurrentBytes >> 8), - mTotalBytes <= 0); - expandedView.setViewVisibility(R.id.time_remaining, View.VISIBLE); - expandedView.setTextViewText( - R.id.time_remaining, - c.getString(R.string.time_remaining_notification, - Helpers.getTimeRemaining(mTimeRemaining))); - expandedView.setTextViewText(R.id.progress_text, - Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes)); - expandedView.setImageViewResource(R.id.appIcon, mIcon); - n.contentView = expandedView; - n.contentIntent = mPendingIntent; - return n; - } - - @Override - public void setPendingIntent(PendingIntent contentIntent) { - mPendingIntent = contentIntent; - } - - @Override - public void setTicker(CharSequence ticker) { - mTicker = ticker; - } - - @Override - public void setTimeRemaining(long timeRemaining) { - mTimeRemaining = timeRemaining; - } - -} diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index 1f208f8fb6..a28750abae 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -464,7 +464,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC // Build the full path to the app's expansion files try { - expansion_pack_path = Environment.getExternalStorageDirectory().toString() + "/Android/obb/"+this.getPackageName(); + expansion_pack_path = Helpers.getSaveFilePath(getApplicationContext()); expansion_pack_path+="/"+"main."+getPackageManager().getPackageInfo(getPackageName(), 0).versionCode+"."+this.getPackageName()+".obb"; } catch (Exception e) { e.printStackTrace(); |