Skip to content

Commit

Permalink
fixed android compile SDK version = 31 crash error,upgrade version c…
Browse files Browse the repository at this point in the history
…lick cancel crash error、
  • Loading branch information
rhyme committed Dec 6, 2021
1 parent 1c9c1d7 commit 0efc656
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 0.3.7
* fixed android compile SDK version = 31 crash error,upgrade version click cancel crash error、
## 0.3.6
* add android platform [androidStores][getVersionFromAndroidStore] methods.
## 0.3.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ static void createNotification(Context context, int id, String title, int curren
pauseIntent.setAction(UpgradeService.RECEIVER_PAUSE);
pauseIntent.putExtra(UpgradeManager.PARAMS_ID, id);
pauseIntent.putExtra(UpgradeManager.PARAMS_PACKAGE, context.getPackageName());


PendingIntent pausePendingIntent =
PendingIntent.getBroadcast(context, 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.getBroadcast(context, 0, pauseIntent, getPendingIntentFlag());
// PendingIntent.getBroadcast(context, 0, pauseIntent, PendingIntent.FLAG_IMMUTABLE);
boolean indeterminate = max_length == -1;

notification = new NotificationCompat.Builder(context, CHANNEL_NAME)
Expand All @@ -56,7 +59,8 @@ static void createNotification(Context context, int id, String title, int curren
installIntent.putExtra(UpgradeManager.PARAMS_PACKAGE, context.getPackageName());

PendingIntent installPendingIntent =
PendingIntent.getBroadcast(context, 0, installIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.getBroadcast(context, 0, installIntent,getPendingIntentFlag());
// PendingIntent.getBroadcast(context, 0, installIntent, PendingIntent.FLAG_IMMUTABLE);

notification = new NotificationCompat.Builder(context, CHANNEL_NAME)
.setSmallIcon(context.getApplicationInfo().icon)
Expand All @@ -71,7 +75,9 @@ static void createNotification(Context context, int id, String title, int curren
reStartIntent.putExtra(UpgradeManager.PARAMS_PACKAGE, context.getPackageName());

PendingIntent reStartPendingIntent =
PendingIntent.getBroadcast(context, 0, reStartIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.getBroadcast(context, 0, reStartIntent, getPendingIntentFlag());
// PendingIntent.getBroadcast(context, 0, reStartIntent, PendingIntent.FLAG_IMMUTABLE);

notification = new NotificationCompat.Builder(context, CHANNEL_NAME)
.setSmallIcon(context.getApplicationInfo().icon)
.setContentTitle(title)
Expand All @@ -85,7 +91,8 @@ static void createNotification(Context context, int id, String title, int curren
failedIntent.putExtra(UpgradeManager.PARAMS_PACKAGE, context.getPackageName());

PendingIntent reStartPendingIntent =
PendingIntent.getBroadcast(context, 0, failedIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.getBroadcast(context, 0, failedIntent, getPendingIntentFlag());
// PendingIntent.getBroadcast(context, 0, failedIntent, PendingIntent.FLAG_IMMUTABLE);
notification = new NotificationCompat.Builder(context, CHANNEL_NAME)
.setSmallIcon(context.getApplicationInfo().icon)
.setContentTitle(title)
Expand All @@ -109,6 +116,14 @@ static void createNotification(Context context, int id, String title, int curren
// notificationManager.notify(id, notification);
}

private static int getPendingIntentFlag() {
int pendingFlag = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= 31) {
pendingFlag = PendingIntent.FLAG_IMMUTABLE;
}
return pendingFlag;
}

static void removeNotification(Context context, long id) {
NotificationManagerCompat compat = NotificationManagerCompat.from(context);
compat.cancel((int) id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void handleNetworkChange(boolean isConnected) {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

if (intent == null) return super.onStartCommand(null, flags, startId);
Bundle bundle = intent.getExtras();
assert (bundle != null);
String url = bundle.getString(DOWNLOAD_URL);
Expand Down Expand Up @@ -190,7 +190,9 @@ public int onStartCommand(Intent intent, int flags, int startId) {
@Override
public void onDestroy() {
unregisterReceiver(actionReceiver);
runnable.handlerDownloadPause();
if (runnable != null) {
runnable.handlerDownloadPause();
}
super.onDestroy();
}

Expand Down
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.r_upgrade_example"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
1 change: 1 addition & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class _MyAppState extends State<MyApp> {
fileName: 'r_upgrade.apk',
isAutoRequestInstall: isAutoRequestInstall!,
notificationStyle: NotificationStyle.speechAndPlanTime,
useDownloadManager: true);
useDownloadManager: false);
upgradeMethod = UpgradeMethod.all;
setState(() {});
},
Expand Down
10 changes: 5 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.6.1"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -92,7 +92,7 @@ packages:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand All @@ -106,7 +106,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.4"
version: "0.3.6"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -153,7 +153,7 @@ packages:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.0"
version: "0.4.2"
typed_data:
dependency: transitive
description:
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.6.1"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -73,7 +73,7 @@ packages:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -127,7 +127,7 @@ packages:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.0"
version: "0.4.2"
typed_data:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: r_upgrade
description: A plugin for upgrade and install application ,Support Android and IOS.
version: 0.3.6
version: 0.3.7
homepage: https://github.com/rhymelph/r_upgrade

environment:
Expand Down

0 comments on commit 0efc656

Please sign in to comment.