I have been following a tutorial however it is quite old and uses the deprecated googleApiClient. Weirdly though, when I use
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
It works as should do by displaying the location on the map. I assumed it wouldn't work and when debugging before it wouldn't build.
I have tried to impelement a new way using the updating version whereby the fusedLocationApi isn't included.
Attached are the working version with fusedLocationApi & googleClientApi, and the newer code which builds but isn't showing the location on the map when the app builds.
Maybe there is something missing in the updated code that isn't producing the location to show on the map??
I'm new to Android to any help appreciated :)
Old Working Version - https://pastebin.com/VG4AUJrv
Updated Not Working Version - https://pastebin.com/xa674c5f
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
{
// add here
fusedLocationProviderClient?.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper())
mMap.isMyLocationEnabled = true
}else
{
checkLocationPermission()
}
}
Your problem is here.
When you grant an application permission it will not perform a location search so you need to write a method to do it if you have granted it permission.
Related
I'm making a location-tracking app. This is the first time I'm programming in Java and I have no idea how to update the deprecated methods. I see that Android Studio is trying its best to explain how to use the current methods, but I still keep messing it up.
LocationRequest locationRequest;
locationRequest = new LocationRequest(); // LocationRequest() is deprecated
// How often does the default location check occur?
locationRequest.setInterval(1000 * DEFAULT_UPDATE_INTERVAL); //.setInterval() is deprecated
// How often does the location check occur when set to the most frequent update?
locationRequest.setFastestInterval(1000 * FAST_UPDATE_INTERVAL); // setFastestInterval is deprecated
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
// setPriority() is deprecated
// PRIORITY_BALANCED_POWER_ACCURACY constant is deprecated
sw_gps.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (sw_gps.isChecked()) {
// most accurate - use GPS
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// .setPriority method deprecated and PRIORITY_HIGH_ACCURACY constant deprecated
tv_sensor.setText("Using GPS sensors");
} else {
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
tv_sensor.setText("Using Towers + WiFi");
// .setPriority and PRIORITY_BALANCED_POWER_ACCURACY are deprecated
}
}
});
So how do I fix this? The error messages I'm get when hovering over setPriority, and the constants is:
This method is deprecated. Use LocationRequest.Builder.setIntervalMillis(long) instead. May be removed in a future release.
This constant is deprecated. Use Priority.PRIORITY_HIGH_ACCURACY instead.
This constant is deprecated. Use Priority.PRIORITY_BALANCED_POWER_ACCURACY instead.
I'm sorry if this is not very readable. It's my first time using Java to build an android app and this is the best way I could formulate the question.
Thanks in advance.
Try using LocationRequest.Builder
Below code for creating location request
Kotlin
LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 10000)
.apply {
setWaitForAccurateLocation(false)
setMinUpdateIntervalMillis(IMPLICIT_MIN_UPDATE_INTERVAL)
setMaxUpdateDelayMillis(100000)
}.build()
Java
new LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 10000)
.setWaitForAccurateLocation(false)
.setMinUpdateIntervalMillis(IMPLICIT_MIN_UPDATE_INTERVAL)
.setMaxUpdateDelayMillis(100000)
.build()
Read more about here https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder
This morning I woke up with a nasty surprise, my app with over 30k installations was removed from the playstore for no reason. Since I had to fix some things, I took the opportunity to recompile it for the new android versions and I encountered the following problem. In practice, the function that at the first start takes care of requesting permissions, no longer recognizes me "Manifest.permission.CAPTURE_VIDEO_OUTPUT", which is access to the camera (the app works with qr code, so you can understand how important it is ). Could you help me?
public void request_permission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.INTERNET, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.CAPTURE_VIDEO_OUTPUT, Manifest.permission.GET_ACCOUNTS}, 1);
} else {
ActivityCompat.requestPermissions(base.this, new String[]{Manifest.permission.INTERNET, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.CAPTURE_VIDEO_OUTPUT, Manifest.permission.GET_ACCOUNTS}, 1);
}
}
this is my build.gradle
I have touched nothing form first version of app, i just have update gradle, targetsdk versione and pressed "run".
I want to open another app in a second screen(POS) so kindly help me to run another app in side second screen. I got the code for Oreo but I need this to work from Lollipop to latest.
ActivityOptions options = null;
Intent launchApp = MyApplication.getInstance().getActivity().getPackageManager().getLaunchIntentForPackage(packageInfo.packageName);
launchApp.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
options = ActivityOptions.makeBasic().setLaunchDisplayId(1);
MyApplication.getInstance().getActivity().startActivity(launchApp, options.toBundle());
}
}
Android did not support showing multiple apps very well back on Android 5.0. All that you could do was:
Have one app use both screens, either by default mirroring or by using Presentation; or
Use something like my PresentationService to have your app use the secondary display from the background, while a "regular" app uses the primary display
You may wish to discuss your ideas with the device manufacturer, to see if they have other device-specific alternatives.
I have some new questions in today's citymaps development.
In the Android studio,if I develop the code for citymap, there are always no logs showing but for others that does not happen. Why?
According to the citymaps official website, to create a map instance with CitymapsMapFragment, but in the sample project which citymaps provides, it uses SupportCitymapsMpaFragment ,What is the difference between them?
When the map is loading complete, is it automatically positioning to the current position or some other default position? Where is it?
If I open the GPS location,I can locate to the current position and show a blue arrow quickly, but too much power consumption,are there any other location way like network or base station location?
Code follows:
CitymapsMapFragment fragment = (CitymapsMapFragment)fragmentManager.findFragmentById(R.id.map);
if (fragment != null) {
fragment.setMapViewListener(this);
}
I did not find the fragment have the method setMapViewListener but setMapViewReadyListener,does it right?
Other code:
CitymapsMapView mapView = new CitymapsMapView(this, options, this);
When I add animate in additional methods like this:
mapView.setMapPosition(position, 300, new MapViewAnimationListener() {
#Override
public void onAnimationEnd(boolean completed) {
Log.d("SomeApp", "Move Complete!");
}
});
the project fails and exits,I tried to surround the code with try-catch block to catch exception for purpose, but nothing shows in logcat view. Why?
I am developer on the Citymaps project. I will do my best to answer all your questions
1) If you are not receiving log statements, this is likely an issue with your own application, IDE, or device configuration. In our own application, which uses the Citymaps SDK, we have no issues with logging.
2) Prior to using the Citymaps SDK, it is highly advisable that you familiarize yourself with fragments, but the short version is that SupportCitymapsMapFragment extends from the Fragment class in the v4 support library.
3) It is up to you to set the default position the map.
4) If you create a class which implements from the LocationSource interface, and then call mapView.setLocationSource, you can modify the behaviors of the map's location services. For an example, have a look at CitymapsLocationSource.java, which is the default implementation for this interface used by the SDK.
As for the exception you are having, you have not provided nearly enough information. Please show a stack trace, and I may be able to help.
Thank you for using our SDK, feel free to post again with any more questions.
is there any way for my application to get the user's Android Version or API Level ? .. because i am working on an app that supports API 9 (2.3 Gingerbread) .. and since API 9 does not support DialogFragments even with android.support.v4.app.DialogFragment imported, i decided to do an if else statement instead
if (the users Android Version is Lower than API 11)
{
i will show a new class instead of a Dialog Fragment containing all information about the developer
}
else if (the users Android Version is Higher than or equal to API 11)
{
my dialog fragment will show up containing all information about the developer
}
i hope anyone can help me out about this, thanks :)
Use Build.VERSION.SDK_INT to get the API level. You can then compare it against values in Build.VERSION_CODES:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// do something cool
}
Standard how to execute code for different versions.
Android provides a unique code for each platform version in the Build constants class. Use these codes within your app to build conditions that ensure the code that depends on higher API levels is executed only when those APIs are available on the system.
#SuppressWarnings("deprecation")
// We use the new method when supported
#SuppressLint("NewApi")
// We check which build version we are using.
#Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mapView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
} else {
mapView.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
}
Try this:
Build.VERSTION.RELEASE
http://developer.android.com/reference/android/os/Build.VERSION.html