Login tweaks, fix crash on requestion location
This commit is contained in:
parent
6e31aff823
commit
f1ea64c5a9
1 changed files with 6 additions and 5 deletions
|
|
@ -16,8 +16,6 @@ import com.getcapacitor.BridgeActivity;
|
||||||
import com.getcapacitor.JSObject;
|
import com.getcapacitor.JSObject;
|
||||||
import com.getcapacitor.PluginCall;
|
import com.getcapacitor.PluginCall;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class MainActivity extends BridgeActivity {
|
public class MainActivity extends BridgeActivity {
|
||||||
|
|
||||||
private PluginCall locationRequest = null;
|
private PluginCall locationRequest = null;
|
||||||
|
|
@ -45,11 +43,14 @@ public class MainActivity extends BridgeActivity {
|
||||||
System.out.println("Android: Geolocation permission is: "+ permission);
|
System.out.println("Android: Geolocation permission is: "+ permission);
|
||||||
Databridge.sendAnswerTo(pluginCall, "" + permission);
|
Databridge.sendAnswerTo(pluginCall, "" + permission);
|
||||||
});
|
});
|
||||||
|
Databridge.addResponder("open:login", pluginCall -> {
|
||||||
|
// We got a request - open the browser on 'app.mapcomplete.org/land' to login in the browser, then pass the token along
|
||||||
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://app.mapcomplete.org/land.html"));
|
||||||
|
startActivity(browserIntent);
|
||||||
|
});
|
||||||
Databridge.addResponder("request:login", pluginCall -> {
|
Databridge.addResponder("request:login", pluginCall -> {
|
||||||
// We got a request - open the browser on 'app.mapcomplete.org/land' to login in the browser, then pass the token along
|
// We got a request - open the browser on 'app.mapcomplete.org/land' to login in the browser, then pass the token along
|
||||||
this.authRequest = pluginCall;
|
this.authRequest = pluginCall;
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://app.mapcomplete.org/land.html"));
|
|
||||||
startActivity(browserIntent);
|
|
||||||
if (this.loginToken != null) {
|
if (this.loginToken != null) {
|
||||||
pluginCall.resolve(this.loginToken);
|
pluginCall.resolve(this.loginToken);
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +138,7 @@ public class MainActivity extends BridgeActivity {
|
||||||
) {
|
) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
if (requestCode == GeolocationBridge.requestCode) {
|
if (requestCode == GeolocationBridge.requestCode) {
|
||||||
if (this.locationRequest != null) {
|
if (this.locationRequest != null && grantResults.length > 0) {
|
||||||
// We've only requested "FINE_LOCATION"
|
// We've only requested "FINE_LOCATION"
|
||||||
var granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
var granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
|
||||||
Log.i("Geolocation", "Got fine location permission: " + granted);
|
Log.i("Geolocation", "Got fine location permission: " + granted);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue