Hi everyone,
Here’s my code:
[extern(Android) ForeignInclude(Language.Java,
"android.location.LocationManager",
"android.content.Context",
"android.app.Activity"
)]
public class Location : NativeModule
{
// ...
[Foreign(Language.Java)]
static extern(Android) bool Test()
@{
LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
return manager.isProviderEnabled( LocationManager.GPS_PROVIDER );
@}
}
And then it notifies: “cannot find symbol” at getSystemService method. What should i do? Thanks.
Hi David!
The issue here is the getSystemService
method belongs to the Activity. The easiest way to get the App’s root activity is to use the com.fuse.Activity.getRootActivity()
method.
So your code becomes:
[extern(Android) ForeignInclude(Language.Java,
"android.location.LocationManager",
"android.content.Context",
"android.app.Activity")]
public class Location : NativeModule
{
// ...
[Foreign(Language.Java)]
static extern(Android) bool Test()
@{
Activity activity = com.fuse.Activity.getRootActivity();
LocationManager manager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
return manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
@}
}
You can also get the activity in Uno using the Android.ActivityUtils
package (which we really need to document
)
you add "Android.ActivityUtils"
to your unoproj
file, and then call
Java.Object activity = Android.ActivityUtils.GetRootActivity();
You can also launch activities from there, see here: https://gist.github.com/cbaggers/489e2533570f246e32157e0018cab95c for an example
I hope this helps
Anytime! thanks for posting your result.