-
Notifications
You must be signed in to change notification settings - Fork 29.5k
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: pluginsSupport for writing, building, and running plugin packagesSupport for writing, building, and running plugin packagesengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.team-engineOwned by Engine teamOwned by Engine teamtriaged-engineTriaged by Engine teamTriaged by Engine team
Description
Steps to Reproduce
- Create a Flutter package in java
- In plugin class add a Activity result listener
- In onMethodCall call startActivityForResult
- In Activity called, at a certain point, call setResult and finish
Issue is the `onActivityResult' plugin is not triggered when Activity child call finish.
here's the code of parent MyBarcodeScannerPlugin ...
public class MyBarcodeScannerPlugin implements MethodCallHandler, PluginRegistry.ActivityResultListener {
private final Activity activity;
private Result result;
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "my_barcode_scanner");
final MyBarcodeScannerPlugin plugin = new MyBarcodeScannerPlugin(registrar.activity());
channel.setMethodCallHandler(plugin);
registrar.addActivityResultListener(plugin);
}
private MyBarcodeScannerPlugin(Activity activity) {
this.activity = activity;
}
@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("scan")) {
this.result = result;
showBarcodeView(activity);
} else {
result.notImplemented();
}
}
private void showBarcodeView(Activity activity) {
Intent intent = new Intent(activity, MyBarcodeScannerActivity.class);
activity.startActivityForResult(intent, 100);
}
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
// IT DOES NOT FIRE !
if (requestCode == 100) {
if (resultCode == Activity.RESULT_OK) {
this.result.success("");
} else {
String errorCode = data.getStringExtra("ERROR_CODE");
this.result.error(errorCode, null, null);
}
return true;
}
return false;
}
}And here's the child activity that finish when user deny permission...
public class MyBarcodeScannerActivity extends AppCompatActivity {
...
...
private void finishWithError(String errorCode) {
Intent intent = new Intent();
intent.putExtra("ERROR_CODE", errorCode);
setResult(Activity.RESULT_CANCELED, intent);
finish();
}
...
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case REQUEST_CAMERA:
if (grantResults.length > 0) {
boolean cameraAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
if (cameraAccepted){
}else {
finishWithError("PERMISSION_NOT_GRANTED");
}
}
break;
}
}
}flutter doctor -v
[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Versione 10.0.16299.904], locale it-IT)
• Flutter version 1.0.0 at C:\dati\Flutter\flutter
• Framework revision 5391447fae (8 weeks ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at C:/Users/...
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = C:/Users/...
• Java binary at: C:\dati\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
[√] Android Studio (version 3.1)
• Android Studio at C:\dati\Android\Android Studio
• Flutter plugin version 29.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
[√] IntelliJ IDEA Community Edition (version 2018.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.4
• Flutter plugin version 25.0.2
• Dart plugin version 181.4892.1
[√] VS Code, 64-bit edition (version 1.23.1)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 2.13.2
[√] Connected device (1 available)
• Redmi Note 5 • 8614d893 • android-arm64 • Android 8.1.0 (API 27)
SAGARSURI
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: pluginsSupport for writing, building, and running plugin packagesSupport for writing, building, and running plugin packagesengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.team-engineOwned by Engine teamOwned by Engine teamtriaged-engineTriaged by Engine teamTriaged by Engine team