Question
Estes
US
Last activity: 7 Aug 2023 10:35 EDT
How to Call a Custom Module Android Activity from PMC plugin 8.4.3
We recently upgraded from 8.2.7 to 8.4.3 .With the documentation we are able to call the methods from custom module .our requirement is to integrate with third party android module we use for scanning .With the upgrade Android devkit has changed so sdk classes also have changed .What i am looking is how to get the current Activity context and call an Android custom module Activity from a plugin method .
Can any one suggest the methods or sample code that can be used.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
PL
Hi, these guides may be helpful while developing custom modules for Android:
https://collaborate.pega.com/discussion/authoring-android-custom-modules-pega-mobile-client
https://collaborate.pega.com/discussion/invoking-pega-mobile-client-custom-modules-pega-platform-ui
Thanks,
Mateusz
Estes
US
Thanks for the response!
I am able to call plugin module and do basic things .Where I am stuck is calling another android activity from within this plugin KT file .Previous versions plugin file used to have a context object which is used to call another Activity.
we have scanbot API which is a custom android module built in kotlin so we are trying to call the scanbot activity from webviewplugin.Grey area is how to preprare an Intent and call this other activity with out having access to Android Context object.
Pegasystems Inc.
PL
You can get a context out of the webview that is available in the plugin class. And for starting an activity (for result, I assume) you can use our Results.startActivityForResult()
Please refer to the example below for how it's used
You can get a context out of the webview that is available in the plugin class. And for starting an activity (for result, I assume) you can use our Results.startActivityForResult()
Please refer to the example below for how it's used
@Suppress("UNUSED")
@JavaScriptPlugin(PLUGIN_NAME)
class ReportingPlugin(webView: PMCWebView) : WebViewPlugin(webView) {
private val job = SupervisorJob()
private val scope = CoroutineScope(Dispatchers.Default + job)
@JavaScriptAPI
fun reportVehicleDamage(options: JavaScriptValue, promise: JavaScriptPromise) {
webView?.context?.let {
val intent = Intent(it, OtherActivity::class.java)
val dataToSend = "someData"
intent.putExtra(OtherActivity.REPORT_EXTRA, dataToSend)
scope.launch {
val result = Results.startActivityForResult(it, intent)
if (result.isSuccessful()) {
val data = result.data?.extras?.getString(OtherActivity.REPORT_EXTRA) ?: run {
promise.reject(JavaScriptError("Missing result data"))
return@launch
}
promise.resolve(JavaScriptValue(data))
} else {
PMCLog.d("ReportingPlugin", "Unsuccessful result")
promise.reject(JavaScriptError("Activity cancelled"))
}
}
}
}
override fun onDestroy() {
super.onDestroy()
job.cancel()
}
companion object {
internal const val PLUGIN_NAME = "reporting"
}
}
Estes
US
Very much appreciate the response Radoslaw.
I am using the same code as above no compilation errors but when i execute the method in the plug in which i am calling ScanbotActivity . app is just crashing without giving much information .Any pointers to look .
look at the code below
@JavaScriptAPI fun openCamera(options: JavaScriptValue, promise: JavaScriptPromise) { webView?.context?.let { val intent = Intent(it, ScanbotActivity::class.java) val dataToSend = "someData" intent.putExtra(ScanbotActivity.REPORT_EXTRA, dataToSend) scope.launch { val result = Results.startActivityForResult(it, intent) if (result.isSuccessful()) { val data = result.data?.extras?.getString(ScanbotActivity.REPORT_EXTRA) ?: run { promise.reject(JavaScriptError("Missing result data")) return@launch } promise.resolve(JavaScriptValue(data)) } else { PMCLog.d("ReportingPlugin", "Unsuccessful result") promise.reject(JavaScriptError("Activity cancelled")) } } }
Estes
US
getting this error message .
getting this error message .
020-10-30 13:57:34.335 29827-29827/com.pega.devkit E/AndroidRuntime: FATAL EXCEPTION: main Process: com.pega.devkit, PID: 29827 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pega.devkit/com.pega.scanbotmodule.ScanbotActivity}: java.lang.IllegalStateException: textView must not be null at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3139) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3282) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1970) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7156) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975) Caused by: java.lang.IllegalStateException: textView must not be null at com.pega.scanbotmodule.ScanbotActivity.onCreate(ScanbotActivity.kt:146) at android.app.Activity.performCreate(Activity.java:7335) at android.app.Activity.performCreate(Activity.java:7326) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3282) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1970) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7156) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975) 2020-10-30 13:57:34.367 29827-29827/com.pega.devkit I/Process: Sending signal. PID: 29827 SIG: 9
Toyota Motors North America
US
Thanks Mateusz for publishing article on new Client modules.
But, I am not seeing any documentation related to "How to Migrate Existing Custom modules compiled in Mobile Client 7.41 into New mobile client 8.X"
As i see clear difference in the way we implement older versions and newer version.
Will u be able to provide any documentation how easily migrate these modules to newer versions, as we already have hte project code in place. Pega Should not force developer to develop from new as new Custom Module.
Appreciate your help.