Google map android studio leaked service connection - android

I am doing a simple app that has to do with maps in Android studio. When I run it with the release key,
keytool -list -v -keystore C:\Users\Theodosios\maps.jks -alias mapsalias -storepass
larissa -keypass larissa
the map doesn't run correctly. If I use the debug.kestore though everything works fine.The message in the output is
01-06 00:17:00.904: E/ActivityThread(1665):
Service com.google.android.gms.backup.BackupTransportService has leaked
ServiceConnection com.google.android.gms.http.f#3c9e1e50
that was originally bound here.
01-06 00:17:00.904: E/ActivityThread(1665):
android.app.ServiceConnectionLeaked: Service
com.google.android.gms.backup.BackupTransportService has leaked ServiceConnection
com.google.android.gms.http.f#3c9e1e50
that was originally bound here
01-06 00:17:00.904: E/ActivityThread(1665): at
android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:966)
01-06 00:17:00.904:
E/ActivityThread(1665):
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1768)
I took the code code of the MainActivity from google.It's pretty straight forward.
public class MainActivity extends ActionBarActivity {
GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createMapView();
addMarker();
}
/**
* Initialises the mapview
*/
private void createMapView(){
/**
* Catch the null pointer exception that
* may be thrown when initialising the map
*/
try {
if(null == googleMap){
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.mapView)).getMap();
/**
* If the map is still null after attempted initialisation,
* show an error to the user
*/
if(null == googleMap) {
Toast.makeText(getApplicationContext(),
"Error creating map", Toast.LENGTH_SHORT).show();
}
}
} catch (NullPointerException exception){
Log.e("mapApp", exception.toString());
}
}
private void addMarker(){
/** Make sure that the map has been initialised **/
if(null != googleMap){
Marker marker1= googleMap.addMarker(new MarkerOptions()
.position(new LatLng(39.648141,22.413155))
.title("Marker")
.draggable(true)
);
}
}
}
In the manifest file I add the necessary permissions.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="map.example.com.myapplication" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY KEY FROM GOOLE API CONSOLE GOES HERE" />
</application>
</manifest>

Related

Android: HERE map positioning manager getposition() always return Lat: 17976931348623200..,Lon: 17976931348623200

I am new to HERE maps currently trying to get current user location from Positioning manager , getlocation() method, but my code always return below information
com.nokia.maps.GeoPositionImpl[coordinate=GeoCoordinate [Latitude=-179769313486232000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 Longitude=-179769313486232000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 Altitude=1073741824.000000 Valid=FALSE]]
Below is my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//requestPermissions();
// Search for the Map Fragment
final MapFragment mapFragment = (MapFragment)
getFragmentManager().findFragmentById(R.id.mapfragment);
// initialize the Map Fragment and
// retrieve the map that is associated to the fragment
mapFragment.init(new OnEngineInitListener() {
#Override
public void onEngineInitializationCompleted(
OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
// now the map is ready to be used
map = mapFragment.getMap();
onMapFragmentInitializationCompleted();
} else {
System.out.println("ERROR: Cannot initialize MapFragment");
System.out.println("ERROR: Cannot initialize Map Fragment: " + error.toString());
}
}
});
}
private void onMapFragmentInitializationCompleted() {
PositioningManager posManager;
MapContainer placesContainer = null;
// retrieve a reference of the map from the map fragment
// map = mapFragment.getMap();
// start the position manager
posManager = PositioningManager.getInstance();
posManager.start(PositioningManager.LocationMethod.GPS_NETWORK);
GeoPosition position = posManager.getPosition();
GeoCoordinate cor = position.getCoordinate();
// Set a pedestrian friendly map scheme
map.setMapScheme(Map.Scheme.PEDESTRIAN_DAY);
// Display position indicator
map.getPositionIndicator().setVisible(true);
placesContainer = new MapContainer();
map.addMapObject(placesContainer);
// Set the map center coordinate to the current position
map.setCenter(posManager.getPosition().getCoordinate(), Map.Animation.NONE);
map.setZoomLevel(14);
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.benz.event.navigation">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="navigation"
android:hardwareAccelerated="true"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.here.android.maps.appid" android:value="MY ID"/>
<meta-data android:name="com.here.android.maps.apptoken" android:value="MY TOKEN"/>
<meta-data android:name="com.here.android.maps.license.key" android:value="MY KEY"/>
<!--
Embed the HERE Map Service.
For more information, see the HERE SDK Developer's Guide
-->
<service
android:name="com.here.android.mpa.service.MapService"
android:label="HereMapService"
android:process="global.Here.Map.Service.v2"
android:exported="true" >
<intent-filter>
<action android:name="com.here.android.mpa.service.MapService" >
</action>
</intent-filter>
</service>
</application>
</manifest>
Any help/hint will save my day
Thanks
Valid=FALSE Implies your device does not have a GPS lock. Is your device indoors and unable to obtain a position? Second, please check to see if your application has the positioning permission.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION " />

Unable to view googlemap in Maps activity

I am trying to build a location based MAP app and when I try to execute my App, I can view my Markers added to the Mapsactivity, however i don't Map on the activity
I can confirm that I have provide the correct Map key for my activity getting the key from console.developer.com and enabling Google Maps for Android API
Please suggest what could be wrong here
MapsActivity
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private final String TAG = "MapActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
Log.d(TAG, "inside create Fragment");
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Log.d(TAG, "outside create Fragment");
}
#Override
public void onMapReady(GoogleMap map) {
SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Double mLat = Double.parseDouble(preferences.getString("latitude",""));
Double mLon = Double.parseDouble(preferences.getString("longtitude",""));
Log.d(TAG, preferences.getString("latitude",""));
Log.d(TAG, preferences.getString("longtitude",""));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLat,mLon), 20));
map.addMarker(new MarkerOptions().position(new LatLng(mLat,mLon)));
//map.setMyLocationEnabled(true);
}
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity android:name=".MyGames"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key"/>
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.wesport.MainActivity"/>
</activity>
</application>
Activity_maps.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity"/>
Image from the emulator
Probably you show desert on the map.
Try change:
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLat,mLon), 20));
to
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLat, mLon), 5));

here map PositioningManager.getInstance() singleton null object?

Issue: ProjectManager.getInstance(); gives null object, I am clueless I have done the code as below,
Activity class & Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="proj.Mobi">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.here.android.maps.appid" android:value="WcIOjXKhgYk8" />
<meta-data android:name="com.here.android.maps.apptoken" android:value="XaRs1SILAVi2sw" />
<meta-data android:name="com.here.android.maps.license.key" android:value="phEpi5ZL3jiNTElgM3ldzrJTeevoNeYY47oE9eSzgJfySv=" />
</application>
</manifest>
I am creating class of map activity below, I have created the PositioningManager.getInstance() it gives null object by Toast popup
public class MainActivity extends AppCompatActivity {
// map embedded in the map fragment
private Map map = null;
// map fragment embedded in this activity
private MapFragment mapFragment = null;
private PositioningManager positioningManager = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Positioning Manager
positioningManager = PositioningManager.getInstance();
if (positioningManager == null) {
Toast.makeText(MainActivity.this, " Positioning Null", Toast.LENGTH_LONG).show();
}
// Search for the map fragment to finish setup by calling init().
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
mapFragment.init(new OnEngineInitListener() {
#Override
public void onEngineInitializationCompleted(
OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
// retrieve a reference of the map from the map fragment
map = mapFragment.getMap();
// Set the map center to the Vancouver region (no animation)
map.setCenter(new GeoCoordinate(12.9172, 77.5738, 0.0),
Map.Animation.NONE);
// Set the zoom level to the average between min and max
map.setZoomLevel(
(map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
} else {
System.out.println("ERROR: Cannot initialize Map Fragment");
Toast.makeText(MainActivity.this, "Error:" + error.toString(), Toast.LENGTH_LONG).show();
}
}
});
}
}
Everything that's HERE Maps related needs to happen after initialization. This is applicable for everything related to the HERE MobileSDK.
Try getting the PositioningManager inside your EngineInitListener.onEngineInitializationCompleted (and keep in mind, once you get the instance, you also have to call start on it to receive any events)

Android setUpMapIfNeeded(); gives null pointer exception

So i just created a new google maps activity and it gives me a null pointer exception if i try to run my application
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setUpMapIfNeeded();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
this is my layout
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context="android.ehb.be.lab4sqlliteex.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
it is just auto-generated by android studio when i added my activity.
My class extends FragmentActivity
this is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="#string/google_maps_key"/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBxMzLA6jjVtPQEHOrOPTRzKnjPu6bKKGA"
/>
<activity
android:name="android.ehb.be.lab4sqlliteex.MapsActivity"
android:label="#string/title_activity_maps">
</activity>
<activity
android:name=".BucketListActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AlbumsActivity"
android:label="Albums"
android:parentActivityName=".BucketListActivity">
</activity>
</application>
Anybody an idea how to fix this?
This is the error i get:
java.lang.RuntimeException: Unable to start activity ComponentInfo{android.ehb.be.lab4sqlliteex/android.ehb.be.lab4sqlliteex.MapsActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2641)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.ehb.be.lab4sqlliteex.MapsActivity.setUpMapIfNeeded(MapsActivity.java:46)
at android.ehb.be.lab4sqlliteex.MapsActivity.onCreate(MapsActivity.java:18)
You need to call in onCreate(): setContentView(R.layout.main_layout).
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
setUpMapIfNeeded();
}
Please make sure that you extend ActionBarActivity
public class Contact_Us extends ActionBarActivity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_us);
setUpMapIfNeeded();
}

Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

I'm developing app in that i need show google map using Google Map V2.
I'm getting following error and automatically app stoped.
Unable to start activity ComponentInfo{com.example.getlocation/com.example.getlocation.Show}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
My Minsdk is 12.
Show.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
public class Show extends Activity {
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
Show.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.getlocation.Show" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.getlocation"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.getlocation.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.getlocation.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBCMyxIOHjpFyElj67osKbJwsZ8FrEN3Jg" />
<activity
android:name=".Show"
android:label="#string/title_activity_show" >
</activity>
</application>
</manifest>
I tried a lot but still getting same error...
Thanks in advance.

Categories

Resources