amap_location_fluttify
This commit is contained in:
70
android/build.gradle
Normal file
70
android/build.gradle
Normal file
@ -0,0 +1,70 @@
|
||||
group 'me.yohom.amap_location_fluttify'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.1.2'
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
if (project.android.hasProperty("namespace")) {
|
||||
namespace = "me.yohom.amap_location_fluttify"
|
||||
}
|
||||
compileSdkVersion 31
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
main.jniLibs.srcDir 'libs'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
lintOptions {
|
||||
disable 'InvalidPackage'
|
||||
}
|
||||
compileOptions {
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
packagingOptions {
|
||||
merge 'res/values/values.xml'
|
||||
merge 'AndroidManifest.xml'
|
||||
merge 'R.txt'
|
||||
merge 'classes.jar'
|
||||
merge 'proguard.txt'
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
consumerProguardFiles "proguard-rules.pro"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
||||
implementation 'androidx.annotation:annotation:1.1.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
compileOnly rootProject.findProject(":foundation_fluttify")
|
||||
// flutter plugin dependency
|
||||
|
||||
// sdk dependency
|
||||
api 'com.amap.api:location:6.1.0'
|
||||
}
|
1
android/settings.gradle
Normal file
1
android/settings.gradle
Normal file
@ -0,0 +1 @@
|
||||
rootProject.name = 'amap_location_fluttify'
|
29
android/src/main/AndroidManifest.xml
Normal file
29
android/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="me.yohom.amap_location_fluttify">
|
||||
<!--用于进行网络定位-->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<!--用于访问GPS定位-->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<!--用于获取运营商信息,用于支持提供运营商信息相关的接口-->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<!--用于访问wifi网络信息,wifi信息会用于进行网络定位-->
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<!--用于获取wifi的获取权限,wifi信息会用来进行网络定位-->
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
||||
<!--用于访问网络,网络定位需要上网-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<!--用于读取手机当前的状态-->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
||||
<!--用于写入缓存数据到扩展存储卡-->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<!--用于申请调用A-GPS模块-->
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
|
||||
<!--用于申请获取蓝牙信息进行室内定位-->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||
|
||||
<application>
|
||||
<service android:name="com.amap.api.location.APSService"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,154 @@
|
||||
//////////////////////////////////////////////////////////
|
||||
// GENERATED BY FLUTTIFY. DO NOT EDIT IT.
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
package me.yohom.amap_location_fluttify;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.app.Activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.common.PluginRegistry.Registrar;
|
||||
import io.flutter.plugin.common.StandardMethodCodec;
|
||||
import io.flutter.plugin.platform.PlatformViewRegistry;
|
||||
|
||||
import me.yohom.amap_location_fluttify.sub_handler.*;
|
||||
import me.yohom.amap_location_fluttify.sub_handler.custom.SubHandlerCustom;
|
||||
import me.yohom.foundation_fluttify.core.FluttifyMessageCodec;
|
||||
|
||||
import static me.yohom.foundation_fluttify.FoundationFluttifyPluginKt.getEnableLog;
|
||||
import static me.yohom.foundation_fluttify.FoundationFluttifyPluginKt.getHEAP;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public class AmapLocationFluttifyPlugin implements FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
|
||||
|
||||
private static List<Map<String, Handler>> handlerMapList;
|
||||
|
||||
// v1 android embedding for compatible
|
||||
public static void registerWith(Registrar registrar) {
|
||||
final MethodChannel channel = new MethodChannel(registrar.messenger(), "me.yohom/amap_location_fluttify", new StandardMethodCodec(new FluttifyMessageCodec()));
|
||||
|
||||
AmapLocationFluttifyPlugin plugin = new AmapLocationFluttifyPlugin();
|
||||
|
||||
BinaryMessenger messenger = registrar.messenger();
|
||||
PlatformViewRegistry platformViewRegistry = registrar.platformViewRegistry();
|
||||
Activity activity = registrar.activity();
|
||||
|
||||
plugin.messenger = messenger;
|
||||
plugin.platformViewRegistry = platformViewRegistry;
|
||||
|
||||
handlerMapList = new ArrayList<>();
|
||||
handlerMapList.add(SubHandler0.getSubHandler(messenger));
|
||||
handlerMapList.add(SubHandler1.getSubHandler(messenger));
|
||||
handlerMapList.add(SubHandler2.getSubHandler(messenger));
|
||||
handlerMapList.add(SubHandlerCustom.instance.getSubHandler(messenger, registrar.activity()));
|
||||
|
||||
channel.setMethodCallHandler(plugin);
|
||||
|
||||
// register platform view
|
||||
|
||||
}
|
||||
|
||||
private BinaryMessenger messenger;
|
||||
private PlatformViewRegistry platformViewRegistry;
|
||||
|
||||
// v2 android embedding
|
||||
@Override
|
||||
public void onAttachedToEngine(FlutterPluginBinding binding) {
|
||||
if (getEnableLog()) {
|
||||
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onAttachedToEngine@" + binding);
|
||||
}
|
||||
|
||||
final MethodChannel channel = new MethodChannel(binding.getBinaryMessenger(), "me.yohom/amap_location_fluttify", new StandardMethodCodec(new FluttifyMessageCodec()));
|
||||
|
||||
messenger = binding.getBinaryMessenger();
|
||||
platformViewRegistry = binding.getPlatformViewRegistry();
|
||||
|
||||
handlerMapList = new ArrayList<>();
|
||||
handlerMapList.add(SubHandler0.getSubHandler(messenger));
|
||||
handlerMapList.add(SubHandler1.getSubHandler(messenger));
|
||||
handlerMapList.add(SubHandler2.getSubHandler(messenger));
|
||||
|
||||
channel.setMethodCallHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromEngine(FlutterPluginBinding binding) {
|
||||
if (getEnableLog()) {
|
||||
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onDetachedFromEngine@" + binding);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToActivity(ActivityPluginBinding binding) {
|
||||
if (getEnableLog()) {
|
||||
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onAttachedToActivity@" + binding);
|
||||
}
|
||||
Activity activity = binding.getActivity();
|
||||
|
||||
handlerMapList.add(SubHandlerCustom.instance.getSubHandler(messenger, activity));
|
||||
|
||||
// register platform view
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromActivity() {
|
||||
if (getEnableLog()) {
|
||||
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onDetachedFromActivity");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
|
||||
if (getEnableLog()) {
|
||||
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onReattachedToActivityForConfigChanges@" + binding);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromActivityForConfigChanges() {
|
||||
if (getEnableLog()) {
|
||||
Log.d("fluttify-java", "AmapLocationFluttifyPlugin::onDetachedFromActivityForConfigChanges");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMethodCall(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result methodResult) {
|
||||
Handler handler = null;
|
||||
for (Map<String, Handler> handlerMap : handlerMapList) {
|
||||
if (handlerMap.containsKey(methodCall.method)) {
|
||||
handler = handlerMap.get(methodCall.method);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (handler != null) {
|
||||
try {
|
||||
handler.call(methodCall.arguments, methodResult);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
methodResult.error(e.getMessage(), null, null);
|
||||
}
|
||||
} else {
|
||||
methodResult.notImplemented();
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public static interface Handler {
|
||||
void call(Object args, MethodChannel.Result methodResult) throws Exception;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,192 @@
|
||||
//////////////////////////////////////////////////////////
|
||||
// GENERATED BY FLUTTIFY. DO NOT EDIT IT.
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
package me.yohom.amap_location_fluttify.sub_handler.custom;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.amap.api.fence.GeoFence;
|
||||
import com.amap.api.fence.GeoFenceClient;
|
||||
import com.amap.api.location.DPoint;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.common.StandardMethodCodec;
|
||||
import me.yohom.amap_location_fluttify.AmapLocationFluttifyPlugin.Handler;
|
||||
import me.yohom.foundation_fluttify.core.FluttifyMessageCodec;
|
||||
|
||||
import static me.yohom.foundation_fluttify.FoundationFluttifyPluginKt.getEnableLog;
|
||||
import static me.yohom.foundation_fluttify.FoundationFluttifyPluginKt.getHEAP;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public class SubHandlerCustom {
|
||||
static final String GEOFENCE_BROADCAST_ACTION = "com.location.apis.geofencedemo.broadcast";
|
||||
|
||||
public static final SubHandlerCustom instance = new SubHandlerCustom();
|
||||
|
||||
private SubHandlerCustom() { }
|
||||
|
||||
public Map<String, Handler> getSubHandler(BinaryMessenger messenger, android.app.Activity activity) {
|
||||
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
filter.addAction(GEOFENCE_BROADCAST_ACTION);
|
||||
|
||||
final BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (GEOFENCE_BROADCAST_ACTION.equals(intent.getAction())) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
Log.d(GEOFENCE_BROADCAST_ACTION, "收到围栏消息: " + bundle); //获取Bundle
|
||||
//获取围栏行为:
|
||||
int status = bundle.getInt(GeoFence.BUNDLE_KEY_FENCESTATUS);
|
||||
//获取自定义的围栏标识:
|
||||
String customId = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
|
||||
//获取围栏ID:
|
||||
String fenceId = bundle.getString(GeoFence.BUNDLE_KEY_FENCEID);
|
||||
//获取当前有触发的围栏对象:
|
||||
GeoFence fence = bundle.getParcelable(GeoFence.BUNDLE_KEY_FENCE);
|
||||
|
||||
Map<String, Object> arguments = new HashMap<>();
|
||||
arguments.put("status", status);
|
||||
arguments.put("customId", customId);
|
||||
arguments.put("fenceId", fenceId);
|
||||
arguments.put("fence", fence);
|
||||
|
||||
new MethodChannel(messenger, "com.amap.api.fence.GeoFenceClient::addGeoFenceX::Callback", new StandardMethodCodec(new FluttifyMessageCodec()))
|
||||
.invokeMethod("Callback::com.amap.api.fence.GeoFenceClient::addGeoFenceX", arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
activity.registerReceiver(receiver, filter);
|
||||
|
||||
return new HashMap<String, Handler>() {{
|
||||
put("com.amap.api.fence.GeoFenceClient::addCircleGeoFenceX", (rawArgs, methodResult) -> {
|
||||
// args
|
||||
Map<String, Object> args = (Map<String, Object>) rawArgs;
|
||||
|
||||
GeoFenceClient __this__ = (GeoFenceClient) args.get("__this__");
|
||||
int activeAction = (int) args.get("activeAction");
|
||||
DPoint center = (DPoint) args.get("center");
|
||||
Double radius = (Double) args.get("radius");
|
||||
String customId = (String) args.get("customId");
|
||||
|
||||
// invoke native method
|
||||
try {
|
||||
__this__.setActivateAction(activeAction);
|
||||
__this__.createPendingIntent(GEOFENCE_BROADCAST_ACTION);
|
||||
__this__.addGeoFence(center, radius.floatValue(), customId);
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
if (getEnableLog()) {
|
||||
Log.d("Current HEAP: ", getHEAP().toString());
|
||||
}
|
||||
methodResult.error(throwable.getMessage(), null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
methodResult.success("success");
|
||||
});
|
||||
put("com.amap.api.fence.GeoFenceClient::addPoiGeoFenceX", (rawArgs, methodResult) -> {
|
||||
// args
|
||||
Map<String, Object> args = (Map<String, Object>) rawArgs;
|
||||
|
||||
GeoFenceClient __this__ = (GeoFenceClient) args.get("__this__");
|
||||
int activeAction = (int) args.get("activeAction");
|
||||
String keyword = (String) args.get("keyword");
|
||||
String poiType = (String) args.get("poiType");
|
||||
String city = (String) args.get("city");
|
||||
int size = (int) args.get("size");
|
||||
String customId = (String) args.get("customId");
|
||||
|
||||
// invoke native method
|
||||
try {
|
||||
__this__.setActivateAction(activeAction);
|
||||
__this__.createPendingIntent(GEOFENCE_BROADCAST_ACTION);
|
||||
__this__.addGeoFence(keyword, poiType, city, size, customId);
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
if (getEnableLog()) {
|
||||
Log.d("Current HEAP: ", getHEAP().toString());
|
||||
}
|
||||
methodResult.error(throwable.getMessage(), null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
methodResult.success("success");
|
||||
});
|
||||
put("com.amap.api.fence.GeoFenceClient::addPolygonGeoFenceX", (rawArgs, methodResult) -> {
|
||||
// args
|
||||
Map<String, Object> args = (Map<String, Object>) rawArgs;
|
||||
GeoFenceClient __this__ = (GeoFenceClient) args.get("__this__");
|
||||
int activeAction = (int) args.get("activeAction");
|
||||
|
||||
List<DPoint> polygon = (List<DPoint>) args.get("polygon");
|
||||
|
||||
String customId = (String) args.get("customId");
|
||||
|
||||
// invoke native method
|
||||
try {
|
||||
__this__.setActivateAction(activeAction);
|
||||
__this__.createPendingIntent(GEOFENCE_BROADCAST_ACTION);
|
||||
__this__.addGeoFence(polygon, customId);
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
if (getEnableLog()) {
|
||||
Log.d("Current HEAP: ", getHEAP().toString());
|
||||
}
|
||||
methodResult.error(throwable.getMessage(), null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
methodResult.success("success");
|
||||
});
|
||||
put("com.amap.api.fence.GeoFenceClient::addDistrictGeoFenceX", (rawArgs, methodResult) -> {
|
||||
// args
|
||||
Map<String, Object> args = (Map<String, Object>) rawArgs;
|
||||
|
||||
GeoFenceClient __this__ = (GeoFenceClient) args.get("__this__");
|
||||
int activeAction = (int) args.get("activeAction");
|
||||
String keyword = (String) args.get("keyword");
|
||||
String customId = (String) args.get("customId");
|
||||
|
||||
// invoke native method
|
||||
try {
|
||||
__this__.setActivateAction(activeAction);
|
||||
__this__.createPendingIntent(GEOFENCE_BROADCAST_ACTION);
|
||||
|
||||
__this__.addGeoFence(keyword, customId);
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
if (getEnableLog()) {
|
||||
Log.d("Current HEAP: ", getHEAP().toString());
|
||||
}
|
||||
methodResult.error(throwable.getMessage(), null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
methodResult.success("success");
|
||||
});
|
||||
put("com.amap.api.fence.GeoFenceClient::unregisterBroadcastReceiver", (rawArgs, methodResult) -> {
|
||||
try {
|
||||
activity.unregisterReceiver(receiver);
|
||||
if (getEnableLog()) Log.d("GeoFenceClient", "取消注册围栏广播");
|
||||
methodResult.success("success");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
methodResult.error(e.getMessage(), e.getMessage(), e.getMessage());
|
||||
}
|
||||
});
|
||||
}};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user