Skip to content

Commit 32d7ac4

Browse files
author
Adelmo Freitas
committed
[Android] Fix intent empty when package/class is passed from JS
1 parent 014da1a commit 32d7ac4

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

cordova-plugin-nativeview.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "cordova-plugin-nativeview"
19-
s.version = "1.0.2"
19+
s.version = "1.0.5"
2020
s.summary = "Start or Back to a native screen/page from app or other app"
2121

2222
# This description is used to generate tags and improve search results.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-nativeview",
3-
"version": "1.0.2",
3+
"version": "1.0.5",
44
"types": "./types/index.d.ts",
55
"description": "Start or Back to a native screen/page",
66
"author": {

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
44
id="cordova-plugin-nativeview"
5-
version="1.0.2">
5+
version="1.0.5">
66
<name>Cordova NativeView Plugin</name>
77
<description>
88
Start or Back to a UIViewController(ios)/Activity(Android)

src/android/br/com/mfdeveloper/cordova/NativeView.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ protected Intent configureIntent(JSONArray args, JSONObject activityParams, Call
280280
intent.setPackage(targetPackage);
281281
}
282282

283-
intentFromClass(intent, activityParams, callbackContext);
283+
intent = intentFromClass(intent, activityParams, callbackContext);
284284

285285
intent = intentFromComponent(intent, activityParams, callbackContext);
286286
}
@@ -342,33 +342,27 @@ protected Intent intentFromUri(Intent intent, JSONObject activityParams, Callbac
342342

343343
protected Intent intentFromClass(Intent intent, JSONObject activityParams, CallbackContext callbackContext) throws JSONException {
344344

345-
if (activityParams.has("className")) {
345+
if (activityParams.has("className") && activityParams.has("packageName")) {
346346

347-
Activity activity = null;
348-
349-
if (!activityParams.has("packageName")
350-
|| activityParams.getString("packageName").contains(cordova.getActivity().getPackageName())) {
351-
activity = cordova.getActivity();
352-
}
353-
354-
if(activity != null) {
355-
try {
347+
try {
356348

357-
Class<?> activityClass = Class.forName(activityParams.getString("packageName") + "." + activityParams.getString("className"));
358-
intent = new Intent(activity, activityClass);
359-
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
349+
intent = new Intent(activityParams.optString("packageName") + "." + activityParams.getString("className"));
350+
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
360351

361-
}catch (Exception clsErr) {
362-
JSONObject error = errorResult(clsErr);
352+
}catch (Exception clsErr) {
353+
JSONObject error = errorResult(clsErr);
363354

364-
callbackContext.error(error);
365-
clsErr.printStackTrace();
366-
}
367-
}else{
368-
ComponentName component = new ComponentName(activityParams.getString("packageName"), activityParams.getString("className"));
369-
intent = new Intent().setComponent(component);
355+
callbackContext.error(error);
356+
clsErr.printStackTrace();
370357
}
358+
}else{
359+
JSONObject error = new JSONObject();
360+
error.put("message", "The params 'packageName' and 'className' is required");
361+
error.put("sucess", false);
362+
363+
callbackContext.error(error);
371364
}
365+
372366
return intent;
373367
}
374368

0 commit comments

Comments
 (0)