This commit is contained in:
Pieter Vander Vennet 2024-11-18 20:41:53 +01:00
parent 0cb1cbb35d
commit 9102d6ef87
6 changed files with 64 additions and 50 deletions

View file

@ -1,26 +0,0 @@
package com.getcapacitor.myapp;
import static org.junit.Assert.*;
import android.content.Context;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.getcapacitor.app", appContext.getPackageName());
}
}

View file

@ -33,9 +33,7 @@
<!-- Include one or more domains that should be verified. -->
<data android:host="app.mapcomplete.org" />
<data android:path="/land.html" />
</intent-filter>
</activity>
<provider
@ -52,5 +50,4 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

View file

@ -0,0 +1,51 @@
package org.mapcomplete;
import android.util.Log;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
@CapacitorPlugin(name = "Echo")
public class Databridge extends Plugin {
private final Map<String, Consumer<PluginCall>> responders;
private static Consumer<PluginCall> answer(String answer) {
JSObject ret = new JSObject();
ret.put("value", answer);
Log.i("databridge","Resolving call");
return (PluginCall call) -> call.resolve(ret);
}
/**
* A responder will be activated if the native code asks for it.
* Use call.setKeepAlive(true) for multiple responses
* @param responders
*/
public Databridge(Map<String, Consumer<PluginCall>> responders) {
this.responders = responders;
responders.put("meta", Databridge.answer("capacitator-shell 0.0.1;"));
}
@PluginMethod()
public void request(PluginCall call) {
String key = call.getString("key");
Log.i("databridge","Got a call: "+key);
var c= this.responders.get(key);
if(c != null){
c.accept(call);
}else{
call.reject("ERROR: no responder installed for "+key);
}
}
}

View file

@ -1,5 +1,15 @@
package org.mapcomplete;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
public class MainActivity extends BridgeActivity {}
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerPlugin(Databridge.class);
}
}

View file

@ -1,18 +0,0 @@
package com.getcapacitor.myapp;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}

View file

@ -1,5 +1,5 @@
ext {
minSdkVersion = 22
minSdkVersion = 24
compileSdkVersion = 34
targetSdkVersion = 34
androidxActivityVersion = '1.8.0'
@ -13,4 +13,4 @@ ext {
androidxJunitVersion = '1.1.5'
androidxEspressoCoreVersion = '3.5.1'
cordovaAndroidVersion = '10.1.1'
}
}