ota_update 2.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 92

ota_update #

pub package

Flutter plugin implementing OTA update.
On Android it downloads the file (with progress reporting) and triggers app installation intent.
On iOS it opens safari with specified ipa url. (not yet functioning)

Usage #

To use this plugin, add ota_update as a dependency in your pubspec.yaml file.

Example #

// IMPORT PACKAGE
import 'package:ota_update/ota_update.dart';

  // RUN OTA UPDATE 
  // START LISTENING FOR DOWNLOAD PROGRESS REPORTING EVENTS
  try {
    //LINK CONTAINS APK OF FLUTTER HELLO WORLD FROM FLUTTER SDK EXAMPLES
    //destinationFileName is optional
    OtaUpdate().execute('https://internal1.4q.sk/flutter_hello_world.apk', destinationFilename: 'flutter_hello_world.apk').listen(
      (OtaEvent event) {
        print('EVENT: ${event.status} : ${event.value}');
      },
    );
  } catch (e) {
    print('Failed to make OTA update. Details: $e');
  }

Android #

Add following provider referrence to AndroidManifest.xml inside <application> node.

<provider
    android:name="sk.fourq.otaupdate.OtaUpdateFileProvider"
    android:authorities="${applicationId}.ota_update_provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/filepaths" />
</provider>

See AndroidManifest.xml in example

Also, create the file android/src/main/res/xml/filepaths.xml with following contents. This will allow plugin to access the downloads folder to start the update.

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_download" path="Download"/>
</paths>

See filepaths.xml in example

Note

Google Play Protect may in some cases cause problems with installation.

Statuses #

  • DOWNLOADING:
    • status for events during downloading phase
    • event value is download progress percentage
  • INSTALLING:
    • event status that is sent just before triggering installation intent
    • event value is null
  • ALREADY_RUNNING_ERROR:
    • sent when 'execute' method is called before previous run finished
    • event value is null
  • PERMISSION_NOT_GRANTED_ERROR:
    • sent when user refused to grant required permissions
    • event value is null.
  • INTERNAL_ERROR:
    • sent in all other error cases
    • event value is underlying error message

TODO #

  • restrict download to specific connection type (mobile, wifi)

Contribution and Support #

  • Contributions are welcome!
  • If you want to contribute code please create a PR
  • If you find a bug or want a feature, please fill an issue

2.2.1 #

  • Intent to install downloaded APK is now dispatched before dispatching INSTALLING event to flutter. This change should solve race condition if application programatically exits on INSTALLING event (APP could exit before intent was dispatched and installation would not start in that case).

2.2.0 #

  • Reporting of download errors

2.1.1 #

  • Added flag FLAG_ACTIVITY_NEW_TASK to intent ACTION_INSTALL_PACKAGE in Android implementation

2.1.0 #

  • Added support for custom filename

2.0.3 #

  • Updated example to AndroidX
  • Updated link to APK used in example
  • Improved logging in Android implementation
  • Fixed negative progress values in case of big APK

2.0.2 #

  • Fixed division by zero error

2.0.1 #

  • fixed crash in case of missing progressSink

2.0.0 #

  • fixed crash on flutter 1.7 (by kmtong)
  • added ability to override provider authority (by kmtong)
  • changed default authority to be dynamic to support multiple apps with ota_update out of the box. Please note that this is breaking change. To migrate plase update your provider authority in AndroidManifest to ${applicationId}.ota_update_provider

1.0.3 #

  • fixed compatibility for older Android APIs (by zileyuan)

1.0.2 #

  • ios syntax error fix (by tchunwei)

1.0.1 #

  • migration of embeded example to AndroidX
  • Upgraded Gradle to latest version

1.0.0 #

  • migration to AndroidX and boost compileVersion to 28 (by tchunwei)

0.1.3 #

  • extended Android FileProvider to prevent possible conflicts with other plugins that also use FileProvider.

0.1.2 #

  • fixing NullPointerException when onRequestPermissionsResult was triggered by different plugin than this one

0.1.1 #

  • refactor to use streams only as communication channel
  • documentation changes

0.1.0 #

  • Initial release

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:ota_update/ota_update.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  OtaEvent currentEvent;

  @override
  void initState() {
    super.initState();
    tryOtaUpdate();
  }

  Future<void> tryOtaUpdate() async {
    try {
      //LINK CONTAINS APK OF FLUTTER HELLO WORLD FROM FLUTTER SDK EXAMPLES
      OtaUpdate()
          .execute('https://internal1.4q.sk/flutter_hello_world.apk', destinationFilename: 'flutter_hello_world.apk')
          .listen(
        (OtaEvent event) {
          setState(() => currentEvent = event);
        },
      );
    } catch (e) {
      print('Failed to make OTA update. Details: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    if (currentEvent == null) {
      return Container();
    }
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text(
              'OTA status: ${currentEvent.status} : ${currentEvent.value} \n'),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ota_update: ^2.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ota_update/ota_update.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Format lib/ota_update.dart.

Run flutter format to format lib/ota_update.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8