fix(android): resolve DailyNotification plugin registration issue
- Move plugin registration before super.onCreate() in MainActivity - Create dedicated dailynotification module for proper plugin structure - Add comprehensive logging for plugin registration debugging - Update Vue components with enhanced plugin detection and logging - Fix TypeScript errors in HomeView.vue for proper build The plugin was not being loaded because registration happened after BridgeActivity initialization. Moving registerPlugin() before super.onCreate() ensures the plugin is available when Capacitor loads plugins. Resolves simplified status dialog issue by ensuring native plugin is properly registered and accessible to JavaScript layer.
This commit is contained in:
@@ -16,6 +16,10 @@ android {
|
||||
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
@@ -40,6 +44,7 @@ dependencies {
|
||||
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
||||
implementation project(':capacitor-cordova-android-plugins')
|
||||
implementation project(':dailynotification')
|
||||
}
|
||||
|
||||
apply from: 'capacitor.build.gradle'
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.timesafari.dailynotification.test;
|
||||
|
||||
import com.getcapacitor.JSObject;
|
||||
import com.getcapacitor.Plugin;
|
||||
import com.getcapacitor.PluginCall;
|
||||
import com.getcapacitor.PluginMethod;
|
||||
import com.getcapacitor.annotation.CapacitorPlugin;
|
||||
|
||||
@CapacitorPlugin(name = "DailyNotification")
|
||||
public class DailyNotificationPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
// Log that the plugin has loaded
|
||||
System.out.println("DN|PLUGIN_LOAD_START");
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void echo(PluginCall call) {
|
||||
String value = call.getString("value");
|
||||
JSObject ret = new JSObject();
|
||||
ret.put("value", value);
|
||||
call.resolve(ret);
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void checkStatus(PluginCall call) {
|
||||
JSObject ret = new JSObject();
|
||||
ret.put("status", "OK from native plugin");
|
||||
call.resolve(ret);
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void scheduleNotification(PluginCall call) {
|
||||
String title = call.getString("title");
|
||||
String message = call.getString("message");
|
||||
JSObject ret = new JSObject();
|
||||
ret.put("scheduleResult", "Notification '" + title + "' scheduled with message '" + message + "'");
|
||||
call.resolve(ret);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,24 @@
|
||||
package com.timesafari.dailynotification.test;
|
||||
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
import com.timesafari.dailynotification.DailyNotificationPlugin;
|
||||
|
||||
public class MainActivity extends BridgeActivity {}
|
||||
public class MainActivity extends BridgeActivity {
|
||||
@Override
|
||||
public void onCreate(android.os.Bundle savedInstanceState) {
|
||||
android.util.Log.d("MainActivity", "MainActivity.onCreate() called - START");
|
||||
|
||||
// Register the DailyNotification plugin BEFORE calling super.onCreate()
|
||||
android.util.Log.d("MainActivity", "Registering DailyNotification plugin...");
|
||||
try {
|
||||
registerPlugin(DailyNotificationPlugin.class);
|
||||
android.util.Log.d("MainActivity", "DailyNotification plugin registered successfully");
|
||||
} catch (Exception e) {
|
||||
android.util.Log.e("MainActivity", "Failed to register DailyNotification plugin", e);
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
android.util.Log.d("MainActivity", "MainActivity.onCreate() - after super.onCreate()");
|
||||
android.util.Log.d("MainActivity", "MainActivity.onCreate() called - END");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user