The premise
Plugins directory structure
Marked with the number 1: represents the logic that interacts with the native (where native functionality is obtained)
Labeled with the number 2: Native data capture, equivalent to an interface exposed to native data, used for flutter side calls
The example directory is the place to test
Permission to apply for
Apply for permission on Android
PackageManager. PERMISSION_GRANTED: have permission PackageManager. PERMISSION_DENIED: without permission
Permissions: ActivityCompat. CheckSelfPermission (mContext, Manifest. Permission. ACCESS_FINE_LOCATION) access request: / / the mContext here must be for the Activity type ActivityCompat. RequestPermissions (mContext, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION },code);
There is a problem: you cannot find an object of type Activity. Solution: You need to implement the interface ActivityAware class in the Plugin class and then pull out the Activity class
Open position monitor (interval of 1 s, spacing of 5 meters to monitor a) locationManager. RequestLocationUpdates (PROVIDER, 1000, 5, the listener, mContext getMainLooper ());
LocationListener listener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};
Copy the code
When the data is taken out: type ‘_InternalLinkedHashMap<Object? , Object? >’ is not a subtype of type ‘Map