Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.1+7

* Android: Fix ImagePickerPlugin#onCreate cast context may be cause exeception.
Comment thread
liujingtech marked this conversation as resolved.
Outdated

## 0.6.1+6

* Define clang module for iOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,25 @@ public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

@Override
public void onActivityDestroyed(Activity activity) {
if (activity == registrar.activity()) {
((Application) registrar.context()).unregisterActivityLifecycleCallbacks(this);
if (activity == registrar.activity()
&& registrar.activity().getApplicationContext() != null) {
((Application) registrar.activity().getApplicationContext())
.unregisterActivityLifecycleCallbacks(
this); // Use getApplicationContext() to avoid casting failures
}
}

@Override
public void onActivityStopped(Activity activity) {}
};

if (this.registrar != null) {
((Application) this.registrar.context())
.registerActivityLifecycleCallbacks(this.activityLifecycleCallbacks);
if (this.registrar != null
&& this.registrar.context() != null
&& this.registrar.context().getApplicationContext() != null) {
((Application) this.registrar.context().getApplicationContext())
.registerActivityLifecycleCallbacks(
this
.activityLifecycleCallbacks); // Use getApplicationContext() to avoid casting failures.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ public void onResiter_WhenAcitivityIsNull_ShouldNotCrash() {
"No exception thrown when ImagePickerPlugin.registerWith ran with activity = null", true);
}

@Test
public void onConstructor_WhenContextTypeIsActivity_ShouldNotCrash() {
// When you use Module to dependency, the type of Context will be Application.but when you use AAR to dependency on this plugin, the type of Context will be Activity.
Comment thread
liujingtech marked this conversation as resolved.
Outdated
when(mockRegistrar.context()).thenReturn(mockActivity);
new ImagePickerPlugin(mockRegistrar, mockImagePickerDelegate);
assertTrue(
"No exception thrown when ImagePickerPlugin() ran with context instanceof Activity", true);
}

private MethodCall buildMethodCall(final int source) {
final Map<String, Object> arguments = new HashMap<>();
arguments.put("source", source);
Expand Down