Merge pull request #3034 from jason-simmons/gradle_flx_refresh
Support "flutter refresh" in the Gradle-based sample project
This commit is contained in:
parent
f7e6100b08
commit
379c563b62
@ -6,6 +6,8 @@ package com.example.flutter;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -76,6 +78,20 @@ public class ExampleActivity extends Activity {
|
|||||||
flutterView.onResume();
|
flutterView.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
// Reload the Flutter Dart code when the activity receives an intent
|
||||||
|
// from the "flutter refresh" command.
|
||||||
|
// This feature should only be enabled during development. Use the
|
||||||
|
// debuggable flag as an indicator that we are in development mode.
|
||||||
|
if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
|
||||||
|
if (Intent.ACTION_RUN.equals(intent.getAction())) {
|
||||||
|
flutterView.runFromBundle(intent.getDataString(),
|
||||||
|
intent.getStringExtra("snapshot"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void sendGetRandom() {
|
private void sendGetRandom() {
|
||||||
JSONObject message = new JSONObject();
|
JSONObject message = new JSONObject();
|
||||||
try {
|
try {
|
||||||
|
@ -418,7 +418,7 @@ class AndroidDevice extends Device {
|
|||||||
@override
|
@override
|
||||||
bool isSupported() => true;
|
bool isSupported() => true;
|
||||||
|
|
||||||
Future<bool> refreshSnapshot(AndroidApk apk, String snapshotPath) async {
|
Future<bool> refreshSnapshot(String activity, String snapshotPath) async {
|
||||||
if (!FileSystemEntity.isFileSync(snapshotPath)) {
|
if (!FileSystemEntity.isFileSync(snapshotPath)) {
|
||||||
printError('Cannot find $snapshotPath');
|
printError('Cannot find $snapshotPath');
|
||||||
return false;
|
return false;
|
||||||
@ -432,7 +432,7 @@ class AndroidDevice extends Device {
|
|||||||
'-d', _deviceBundlePath,
|
'-d', _deviceBundlePath,
|
||||||
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP
|
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP
|
||||||
'--es', 'snapshot', _deviceSnapshotPath,
|
'--es', 'snapshot', _deviceSnapshotPath,
|
||||||
apk.launchActivity,
|
activity,
|
||||||
]);
|
]);
|
||||||
runCheckedSync(cmd);
|
runCheckedSync(cmd);
|
||||||
return true;
|
return true;
|
||||||
|
@ -20,6 +20,10 @@ class RefreshCommand extends FlutterCommand {
|
|||||||
|
|
||||||
RefreshCommand() {
|
RefreshCommand() {
|
||||||
usesTargetOption();
|
usesTargetOption();
|
||||||
|
|
||||||
|
argParser.addOption('activity',
|
||||||
|
help: 'The Android activity that will be told to reload the Flutter code.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -49,11 +53,19 @@ class RefreshCommand extends FlutterCommand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String activity = argResults['activity'];
|
||||||
|
if (activity == null) {
|
||||||
|
if (applicationPackages.android != null) {
|
||||||
|
activity = applicationPackages.android.launchActivity;
|
||||||
|
} else {
|
||||||
|
printError('Unable to find the activity to be refreshed.');
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AndroidDevice device = deviceForCommand;
|
AndroidDevice device = deviceForCommand;
|
||||||
|
|
||||||
bool success = await device.refreshSnapshot(
|
bool success = await device.refreshSnapshot(activity, snapshotPath);
|
||||||
applicationPackages.android, snapshotPath
|
|
||||||
);
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
printError('Error refreshing snapshot on $device.');
|
printError('Error refreshing snapshot on $device.');
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user