I installed the HERE test product on my tablet (it's an old Android 5.1 tablet without GPS or Cellular data, just Wifi) and it worked well to (approximately) give my position using Wifi.
So I am attempting to program the same in my app.
Downloaded the HERE API, got a freemium license for my app name, input the lines in my manifest:
<meta-data
android:name="com.here.android.maps.appid"
android:value="itkC4uIay69MTXXXXXXX" />
<meta-data
android:name="com.here.android.maps.apptoken"
android:value="NdT8laoCmRysyh8XXXXXXX" />
Included the HERE-sdk in my build, and my Code compiles just fine.
I have code in my MainActivity.onCreate() [EDIT I have added in code to initialize the map engine as recommended by HERE support below]:
MapEngine.getInstance().init(this, new OnEngineInitListener() {
#Override
public void onEngineInitializationCompleted(Error error) {
if (error == Error.NONE) {
Logger.i(Tags.POSITION, "correctly started map engine");
PositioningManager pm = PositioningManager.getInstance();
PositioningManager.LocationStatus ls = pm.getLocationStatus(PositioningManager.LocationMethod.GPS_NETWORK);
if (ls == PositioningManager.LocationStatus.AVAILABLE) {
Logger.i(Tags.POSITION, "Positioning is available");
} else {
Logger.w(Tags.POSITION, "Positioning not available right now " + ls.toString());
}
pm.start(PositioningManager.LocationMethod.GPS_NETWORK);
} else {
Logger.i(Tags.POSITION, "Problem setting up map engine: " + error);
}
}
});
Then I have code running once per minute on a timer to check my current position:
GeoPosition pos = PositioningManager.getInstance().getPosition();
if (pos == null) {
Log.w("Positioning", "GeoPosition is Null");
} else {
GeoCoordinate coord = pos.getCoordinate();
Logger.i("Positioning", "Location: Latitude = " + coord.getLatitude() + ", Longitude = " + coord.getLongitude());
Logger.i("Positioning", "Accuracy = " + pos.getLatitudeAccuracy() + ", " + pos.getLongitudeAccuracy());
}
When I run I get logs like this:
2019-01-27 11:49:31.960 30112-30112/com.company.app I/: [main] INFO Positioning: correctly started map engine
2019-01-27 11:49:31.961 30112-30112/com.company.app W: [main] WARN Positioning: Positioning not available right now OUT_OF_SERVICE
Then, once per minute
2019-01-27 11:50:30.850 30112-30343/com.company.app W/: [Timer-2] WARN Positioning: GeoPosition is Null
In "Settings" on the tablet "Location" is turned "On" though it says "No apps have requested Location recently"
The logs contain no Errors or warnings, all permissions are requested in the Manifest
[EDIT] The worst thing is my simple test app (mentioned in my comment below), now works after I added in the initializaion of the MapEngine. To answer HERE's question, I really am not interested in using mapping just now, I only want to pull a current Longitude and Latitude to aid in finding my tablet if lost.
Anyone have a clue what I am doing wrong?
I have a few questions to ask, the answer on which will help us to understand what is going wrong.
Do you want to show a map or just using PositioningManager?
If using PositionManager only, do you initialize MapEngine initially?
If you don't use a Map, you have to do something like this since PositionManager doesn't initialize MapEngine itself.
ApplicationContext context = new ApplicationContext(getApplicationContext());
MapEngine.getInstance().init(context, new OnEngineInitListener() {
#Override
public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
} else {
}
}
});
Update: There is another test application on github that might be quite useful, no map using but position manager being used. Hope this helps!
https://github.com/heremaps/here-android-sdk-examples/tree/master/speed-limit-watcher
Related
In my Android Auto projection-type app I am trying to get info on the car I am attached to. Preferably manufacturer or other VHAL type parameters. Speed, tach, gear position etc would be nice too.
Is this possible in Android Auto?
I tried:
car = Car.createCar(getCarContext());
CarInfoManager carInfoManager = (CarInfoManager) car.getCarManager(Car.INFO_SERVICE);
but I get an exception on Car.createCar
I am trying this code in the onCreateSession in the CarAppService with no luck
Two previous answers to my question from other people got deleted. No idea why, but they gave me the hints I needed to fix the code and get it working.
in the CarAppService implementation, in the
public Session onCreateSession() {
at the end where I do:
return new Session() {
I have a block of code like this:
CarInfo carInfo =
getCarContext().getCarService(CarHardwareManager.class).getCarInfo();
mCarHardwareExecutor = ContextCompat.getMainExecutor(getCarContext());
OnCarDataAvailableListener<Model> mModelListener = data -> {
synchronized (this) {
String statusText = "" + data.getYear().getValue() + " " + data.getManufacturer().getValue() + " " + data.getName().getValue();
theSimpleAAScreen.setStatusText(statusText);
theSimpleAAScreen.invalidate();
}
/* get year, make, model */
try {
carInfo.fetchModel(mCarHardwareExecutor, mModelListener);
} catch (SecurityException e) {
Log.e(TAG, "No permission to get model");
}
theSimpleAAScreen is an object that is the android auto screen: I set a value for what to print and invalidate the screen so it redraws. There is probably a better / smoother way but this works and answers my question.
I migrated Google Play Billing Library in Android Studio from 3.0.3 (was working fine) to 4.0.0.
I've checked my Google Play Billing and all seems OK and the SKU status is ACTIVE (no red flags).
I've tried my best to follow migration instructions # https://developer.android.com/google/play/billing/integrate#establish_a_connection_to_google_play
So far, all I can muster is an OK connection to Google Play Billing, that is, after onBillingSetupFinished() method, the BillingClient.BillingResponseCode.OK responds nicely, without error messages.
My problem begins somehere with the call to querySkuDetailsAsync(): There is no response here, not even an error notification. The google website puts a lot of stress emphasis on this call so I sense this is where the fun begins.
I have provided the sample code with the problem. I have used many many fixes from Stack Overflow but now I'm really really stuck and really need this to work.
My problem code below:
'''
/*
//Using the following library in build.graddle for app module
dependencies {
def billing_version = "4.0.0"
implementation "com.android.billingclient:billing:$billing_version"
}
*/
StringBuilder builder4SKUInfo;
private void get_Subscribe2_Characters() {
Subscribe2_Characters_Button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//I Toggle Visibility of Views Here
billingClient.startConnection(new BillingClientStateListener() {
//Android Studio auto-prompts to generate onBillingSetupFinished & onBillingServiceDisconnected
#Override
public void onBillingSetupFinished(#NonNull BillingResult billingResultC) {
if (billingResultC.getResponseCode() == BillingClient.BillingResponseCode.OK) {
//BillingResponseCode is OK here: Works Just Fine!
//The problem starts below
String skuToSell = "MySKU_Character_001"; //In my project, the SKU is cut-pasted from Google Play Console
List<String> skuList = new ArrayList<> ();
skuList.add(skuToSell);
SkuDetailsParams.Builder params = SkuDetailsParams
.newBuilder()
.setSkusList(sku_Details) //
.setType(BillingClient.SkuType.SUBS);
billingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
#Override
public void onSkuDetailsResponse(#NonNull BillingResult billingResult, #NonNull List<SkuDetails> PurchaseDetailsList) {
//NOTHING! Not getting BillingResult
//Problem seems to at this point
if (PurchaseDetailsList.size() > 0) {
//NOTHING! Not getting size
for (SkuDetails PurchaseSKU_Info : PurchaseDetailsList) {
builder4SKUInfo = new StringBuilder(300);
if (PurchaseSKU_Info.getSku().contains("MySKU_Character_001")) {
String getSKUInfo = (
"\nTitle [Query]: " + PurchaseSKU_Info.getTitle()
+ "\n\nDetails: " + PurchaseSKU_Info.getDescription()
+ "\n\nDuration: " + PurchaseSKU_Info.getSubscriptionPeriod()
+ "\n\nPrice" + PurchaseSKU_Info.getPrice()
+ "\n\nAvoid Problems:\nUpdated Subscription Settings on Google Play"
+ "\n\nIMPORTANT: NOT Transferable"
+ "\n\n For this device only\n");
//+ "\nOther SKUs: " + SKU_Info.getSku()
//"001 = " + billingResultB.getResponseCode()
//+ "\nList Size: " + PurchaseDetailsList.size());
builder4SKUInfo.append(getSKUInfo); //The result I need to use elsewhere
}
}
} else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED) {
//No Google Play response for this
} else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.ITEM_NOT_OWNED) {
//No Google Play response for this
} else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED) {
//Do something about cancels
} else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.BILLING_UNAVAILABLE) {
//No Google Play response for this
} else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.SERVICE_DISCONNECTED) {
//No Google Play response for this
} else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.SERVICE_TIMEOUT) {
//No Google Play response for this
} else {
//Following Toast does not show
String SomethingWrong = "Somethings is Wrong" +
"\nUpdate Your Google Play Billing Info" +
"\nCheck Internet Connection";
Toast.makeText(KH.this, SomethingWrong, Toast.LENGTH_LONG).show();
}
}
});
}
}
#Override
public void onBillingServiceDisconnected() {
//Following Toast does not show
String BillingServiceDisconnected = "Billing Service Disconnected" +
"\nUpdate Your Google Play Billing Info" +
"\nCheck Internet Connection";
Toast.makeText(KH.this, BillingServiceDisconnected, Toast.LENGTH_LONG).show();
}
});
}
});
}
'''
So I braved to ask the folks at Google on the issue tracker page and they appropriately and promptly responded, "We now post the results to the background thread instead of the UIThread . . ."
Right away, I knew I had the wrong approach. If the result is delivered to background thread, I had to ditch the 3.x billing approach and start from scratch.
I reached back again to Google for an example and they sent me their GitHub # https://github.com/android/play-billing-samples/tree/main/TrivialDriveJava
The example is akin to an "Intent" but with a lot more code declaration than function selection: has several classes, methods and files to work through. So to fix billing 4.x, the easiest path was to just rip the example into my app, whittled down the errors, gray out methods I don't need and finally overlay my views, refactor classes (fix errors again) and create new user workflows.
Following #Maasaivatar's answer, it works after running the SkuDetailsResponseListener on the main thread:
billingClient.querySkuDetailsAsync(params.build(), (billingResult, list) ->
runOnUiThread(() -> {
// same code as before
}));
I am having trouble obtaining the "server", "mms_proxy", and "mms_port". I haven't found anything official anywhere from Google about why this is? I would assume if this is something I cannot do then that would be stated by Google.
The Android developer website shows the Telephony.Carriers class and all that is available but says nothing about restrictions of any kind so at this point I believe it is fair to assume I can access these rather than have to ask the user to find the APN values manually which will make many people give up instantly and not use my App.
Can we please try to find an official answer as to what is going on here, I have attempted to get this information in many ways all leading to very confusing errors that seemingly cannot be explained.
I am running Android 6.01 on the device ZTE Axon 7. The lowest api that my App will allow is api_21 and the Telephony.Carriers class in available from api_19 and up.
I have declared all then necessary permission in the Manifest file and since I am currently testing on sdk "M" (Android 6), I have also acquired the permissions explicitly at Runtime from the user.
This is the code inside my Activity that I run and receive a an error stating "Error getting Mms Carrier values"...this is the whole problem and where I have become stuck.
ContentResolver contentResolver = getContentResolver();
int index_ID;
final String[] PROJECT =
{
Telephony.Carriers.TYPE,
Telephony.Carriers.MMSC,
Telephony.Carriers.MMSPROXY,
Telephony.Carriers.MMSPORT,
};
grantMyUriPermission(activity, Telephony.Carriers.CONTENT_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
grantMyUriPermission(activity, Telephony.Carriers.CONTENT_URI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Cursor carriers_cursor = SqliteWrapper.query(activity, contentResolver,
Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), PROJECT, null, null, null);
if (carriers_cursor != null)
{
/*This crap below isn't needed for this situation but helps avoid ERROR*/
index_ID = carriers_cursor.getColumnIndex(Telephony.Carriers._ID);
//--------------------------------------------------------------------------------------
if (index_ID < 0 || !carriers_cursor.moveToFirst())
{
Log.i(TAG, "Error getting Mms Carrier values");
carriers_cursor.close();
return;
}
//--------------------------------------------------------------------------------------
do
{
//Confirm cursor has value assigned to it
Log.i(TAG, "cursor: "+ carriers_cursor);
//Get the available columns names
for (String item : carriers_cursor.getColumnNames())
{
//Name of each column available with Cursor
Log.i(TAG, "item: " + item);
//Attempt to get String value for each available column
try
{
//Use the name of the column, to get the index, to get the String value
Log.i(TAG, "getString(): " + carriers_cursor.getString(carriers_cursor.getColumnIndex(item)));
}
catch (Exception e)
{
Log.i(TAG, "Exception: " + e);
}
}
}
while (carriers_cursor.moveToNext());
carriers_cursor.close();
}
The Log output is:
I/SmsReceiveIntentService: Running grantMyUriPermission()
I/SmsReceiveIntentService: Running grantMyUriPermission()
I/NewConversationActivity: Error getting Mms Carrier values
And that's it! Nothing else to go on...?
A colleague of mine is currently working on implementing turn by turn directions into an app that is being developed for the company we are working in. I have been tasked with trying to assist him but neither of us have been able to make any progress.
He is using Mapbox to create the map. I have never used mapbox before so I am not much help.
He has code implemented that should give us turn by turn directions but it does not seem to be doing anything whatsoever.
Sorry if I am bringing up old questions or am not stating my situation clearly but this is the best I can explain myself. We have done much searching but nothing we found seems to help.
Here is the code that he has tried using that is supposed to implement turn by turn directions.
private void getRoute(Waypoint origin, Waypoint destination) throws ServicesException {
MapboxDirections client = new MapboxDirections.Builder()
.setOrigin(origin)
.setDestination(destination)
.setProfile(DirectionsCriteria.PROFILE_DRIVING)
.setSteps(true)
// .setOverview(DirectionsCriteria.OVERVIEW_FULL)
.setInstructions(DirectionsCriteria.INSTRUCTIONS_TEXT)
.setAccessToken("pk.eyJ1IjoibnRyY3N2ZyIsImEiOiJCUmc4OHhjIn0.shHWdNg3Q32QUHJ1nOCs3A")
.build();
client.enqueue(new retrofit.Callback<DirectionsResponse>() {
#Override
public void onResponse(Response<DirectionsResponse> response, Retrofit retrofit) {
// You can get the generic HTTP info about the response
Log.d(TAG, "Response code: " + response.code());
if (response.body() == null) {
Log.e(TAG, "No routes found, make sure you set the right user and access token.");
return;
} else if (response.body().getRoutes().size() < 1) {
Log.e(TAG, "No routes found");
return;
}
}
#Override
public void onFailure(Throwable t) {
Log.e(TAG, "Error: " + t.getMessage());
Toast.makeText(MainActivity.this, "Error: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
public void onResponse(Response<DirectionsResponse> call, Response<DirectionsResponse> response) {
// You can get the generic HTTP info about the response
Log.d(TAG, "Response code: " + response.code());
if (response.body() == null) {
Log.e(TAG, "No routes found, make sure you set the right user and access token.");
return;
} else if (response.body().getRoutes().size() < 1) {
Log.e(TAG, "No routes found");
return;
}
drawRoute(currentRoute);
}
private void drawRoute(DirectionsRoute route) {
// Convert LineString coordinates into LatLng[]
LineString lineString = LineString.fromPolyline(route.getGeometry(), Constants.OSRM_PRECISION_V5);
List<Position> coordinates = lineString.getCoordinates();
LatLng[] points = new LatLng[coordinates.size()];
for (int i = 0; i < coordinates.size(); i++) {
points[i] = new LatLng(
coordinates.get(i).getLatitude(),
coordinates.get(i).getLongitude());
}
Polyline polyline = mMapboxMap.addPolyline(new PolylineOptions()
.add(points)
.color(Color.RED)
.width(5));
directionsOn = true;
}
Any help would be very much appreciated.
Thanks in advance.
I'd highly recommend changing from Directions v4 to v5 found in Mapbox Java. Once you make the switch, you can work off this example found on our website. Make sure you are also passing in coordinates in the correct order, longitude is given first followed by latitude.
Dear friend mapbox provides detailed document with sample code snippets as well.
I have build a working app for my requirement by following mapbox turn by turn navigation documents.
please follow the link and let me know if you face any issues.
Link : https://www.mapbox.com/android-docs/navigation/overview/navigation-ui/
Here you can use NavigationView component to customise the mapbox turn by turn features.
I'm working on integrating Google Maps into the app I'm working on and I've had a rather unpleasant time doing it thus far. Regardless, I finally got a SupportMapFragment displaying a map and set a location and zoom level.
Here is the functional bits of my code thus far:
#Override
public void onActivityCreated( Bundle savedInstanceState ) {
super.onActivityCreated( savedInstanceState );
Location location = BundleChecker.getExtraOrThrow( KEY_LOCATION, new Bundle[] { savedInstanceState, getArguments() } );
setLocation( location );
if ( checkGooglePlayServicesStatus() == ConnectionResult.SUCCESS ) {
setMapFragment( new SupportMapFragment() );
getActivity().getSupportFragmentManager().beginTransaction().add( R.id.location_detail_mapFrame, getMapFragment() ).commit();
}
populateAddress();
attachButtonListeners();
Runnable initMap = new Runnable() {
#Override
public void run() {
if ( checkGooglePlayServicesStatus() == ConnectionResult.SUCCESS ) {
try {
GoogleMap map = getMapFragment().getMap();
LatLng latLng = getLocation().getAddress().getLatLng( getActivity() );
CameraUpdate update = CameraUpdateFactory.newLatLngZoom( latLng, DEFAULT_MAP_ZOOM );
map.animateCamera( update );
}
catch (IOException e) {
Log.e( TAG, e.getMessage(), e );
Toast.makeText( getActivity(), "Unable to find location", Toast.LENGTH_SHORT ).show();
}
}
}
};
Handler handler = new Handler();
handler.postDelayed( initMap, 200 );
}
Also, I wrote a simple convenience method to get a LatLng from my Address model that you may criticize as well:
/*
* Convenience method to easily check if there is a valid lat & lng in this address
*/
public boolean hasLatLng() {
return getLatitude() != null && getLongitude() != null;
}
/*
* Convenience method for use with Google Maps API
*/
public LatLng getLatLng( Context context ) throws IOException {
LatLng latLng = null;
if ( hasLatLng() ) {
latLng = new LatLng( getLatitude(), getLongitude() );
}
else {
String locationString = getStreet() + ", " + AddressUtil.makeCityStateZipString( this );
Geocoder geoCoder = new Geocoder( context );
try {
List<android.location.Address> matches = geoCoder.getFromLocationName( locationString, 2 );
if ( matches != null && matches.size() > 0 ) {
double lat = matches.get( 0 ).getLatitude();
double lng = matches.get( 0 ).getLongitude();
latLng = new LatLng( lat, lng );
}
}
catch (IOException e) {
throw new IOException( e );
}
}
return latLng;
}
I'm aware that this code is not ideal and needs to be refactored. This is my first time working with Google Maps so please feel free to offer suggestions as to how I might do that as well. I experienced a lot of problems when trying to use the MapFragment as a in my layout XML, so I'm creating it programmatically.
The heart of the matter:
I was getting some bogus address data from the staging server and this resulted in the Address#getLatLng method returning null which caused an exception when calling CameraUpdateFactory.newLatLngZoom. After I got this exception, I was no longer able to get map data from Google. The map fragment is blank now and messages are displayed in logcat:
05-21 18:11:42.903: I/Google Maps Android API(15747): Failed to contact Google servers. Another attempt will be made when connectivity is established.
05-21 18:11:43.093: E/Google Maps Android API(15747): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
I have created a new api key and replaced the current one in my manifest with no change. The only changes I had made to the above code were to account for a null LatLng and I have since undone those changes in a pointless attempt to get my code back to a functional state.
Additionally, to make things a bit stranger, I built the sample maps project that is included with the Google Play Services Extras and it works perfectly (has a separate API key, btw).
What might I have done wrong here? Am I overlooking something obvious?
This problem is usually derived from a problem in referencing google-play-service library.
Take a look at this blog post I wrote on how to integrate Google Maps in your application, especially the first 3 steps:
Google Maps API V2
another cause of this could be that you haven't configured the Google API Console properly, so I suggest you to take a look at this guide as well:
Google Maps API V2 Key
another reason that may cause this is if you have some kind of problem in your permissions in the manifest file. You can look at the first guide for the needed permissions as well.
Use Something like this:
Update the google play services in the SDK.
Manually uninstall the App from device and restart the device.
i have tried it and its going perfectly bro
Also do one thing get the new api key to edited the new sh1 code from https://code.google.com/apis/console/
you can get your sh1 code from window- preference-android-buid
Making Google maps work is a Googlemare. This worked for me:
-Update Google play services with the Android Manager
-Make a fresh apikey with: Sha1 keystore (Window->preferences->Android->Build) and project package name. Do this at: https://code.google.com/apis/console/
Somebody had changed the package name and was foiling the app!!
Try this before you need anger management therapy thanks to google maps.