I implemented a map method using the Google Maps API. Yesterday, it was working fine. Since then, I've made absolutely no changes whatsoever to eclipse, any map related method (including views and the MapActivity class) or anything in the its corresponding entry in the manifest - the only thing I changed was to add a splash screen, thereby changing the launcher activity from MyLITactivity to SplashActivity.
My API key is in the manifest, and I've included the uses-library entry in the manifest.
When I run the app, logcat shows this:
05-06 16:12:04.855: I/dalvikvm(753): Failed resolving Lcom/mad/mylit/MapActivity; interface 486 'Lcom/google/android/gms/maps/GoogleMap$OnMapClickListener;'
05-06 16:12:04.855: W/dalvikvm(753): Link of class 'Lcom/mad/mylit/MapActivity;' failed
05-06 16:12:04.855: E/dalvikvm(753): Could not find class 'com.mad.mylit.MapActivity', referenced from method com.mad.mylit.MyLITactivity.startMaps
05-06 16:12:04.855: W/dalvikvm(753): VFY: unable to resolve const-class 495 (Lcom/mad/mylit/MapActivity;) in Lcom/mad/mylit/MyLITactivity;
05-06 16:12:04.855: D/dalvikvm(753): VFY: replacing opcode 0x1c at 0x0002
My manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mad.mylit"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<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" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/lit_logo"
android:label="#string/app_name"
android:theme="#style/Theme.litac" >
<activity
android:name="com.mad.mylit.MyLITactivity"
android:label="#string/app_name"
android:theme="#style/Theme.litac" >
</activity>
<activity
android:name="com.mad.mylit.ItemListActivity"
android:label="#string/title_item_list" >
</activity>
<activity
android:name="com.mad.mylit.ItemDetailActivity"
android:label="#string/title_item_detail"
android:parentActivityName=".ItemListActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ItemListActivity" />
</activity>
<activity
android:name="com.mad.mylit.NewsDetailFragment"
android:label="#string/title_activity_news_detail_fragment" >
</activity>
<activity
android:name="com.mad.mylit.NewsListFragment"
android:label="#string/title_activity_news_list_fragment" >
</activity>
<activity
android:name="com.mad.mylit.NewsActivity"
android:label="#string/title_activity_news" >
</activity>
<activity
android:name="com.mad.mylit.DetailActivity"
android:label="SU News" >
</activity>
<activity
android:name="com.mad.mylit.TimetableActivity"
android:label="#string/title_activity_timetable" >
</activity>
<activity
android:name="com.mad.mylit.MoodleActivity"
android:label="#string/title_activity_moodle" >
</activity>
<activity
android:name="com.mad.mylit.SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxx" />
<activity
android:name="com.mad.mylit.MapActivity"
android:label="#string/title_activity_map"
android:parentActivityName="com.mad.mylit.MyLITactivity" >
android:theme="#style/Theme.litac"
android:uiOptions="splitActionBarWhenNarrow" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mad.mylit.MyLITactivity" />
</activity>
</application>
</manifest>
MapActivity:
public class MapActivity extends FragmentActivity implements OnMapClickListener, OnMapLongClickListener{
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
Location myLocation;
LocationManager locationManager;
String provider;
OnLocationChangedListener myLocationListener = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setupActionBar();
android.support.v4.app.FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
myMap.setMyLocationEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
myMap.setOnMapClickListener(this);
myMap.setOnMapLongClickListener(this);
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabled) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
}
public void activate(OnLocationChangedListener listener) {
myLocationListener = listener;
}
public void deactivate() {
myLocationListener = null;
}
private void setupActionBar() {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.maps, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.menu_legalnotices:
String LicenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(
getApplicationContext());
AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(MapActivity.this);
LicenseDialog.setTitle("Legal Notices");
LicenseDialog.setMessage(LicenseInfo);
LicenseDialog.show();
return true;
case R.id.itemid_1:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=Limerick Institute of Technology, Limerick"));
startActivity(i);
return true;
case R.id.itemid_2:
//TODO change to local map of LIT
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
public void onLocationChanged(Location location) {
myLocationListener.onLocationChanged(location);
LatLng latlng = new LatLng(location.getLatitude(),location.getLongitude());
myMap.animateCamera(CameraUpdateFactory.newLatLng(latlng));
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
#Override
public void onMapLongClick(LatLng point) {
//myMap.addMarker(new MarkerOptions().position(point).title(point.toString()));
}
#Override
public void onMapClick(LatLng point) {
//myMap.animateCamera(CameraUpdateFactory.newLatLng(point));
}
}
If I comment out the OnMapClickListener and OnMapLongClickListener implements (and their corresponding methods) the error disappears.
Solved: I removed and re-imported all libraries, fixed project properties and did a clean-build.
Still have no idea why it worked yesterday and not today...
Related
I'm doing a university project, and i've to show user location in the OSM map, and markers with data from Retrofit API.
I'm not worried about api data right now, but with my map that isn't showing.
All i got is this:MainMap
The coordinates here are random.
My map activity:
public class MapaPrincipal extends AppCompatActivity implements LocationListener {
private MapView osm;
private MapController mc;
private LocationManager locationManager;
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mapa_principal);
osm = (MapView) findViewById(R.id.mapView);
osm.setTileSource(TileSourceFactory.MAPNIK);
osm.setBuiltInZoomControls(true);
osm.setMultiTouchControls(true);
mc = (MapController) osm.getController();
GeoPoint center = new GeoPoint(14.1, 19.2);
mc.setZoom(12);
mc.animateTo(center);
addMarker(center);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// Activity#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for Activity#requestPermissions for more details.
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
public void addMarker(GeoPoint center){
Marker marker = new Marker(osm);
marker.setPosition(center);
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
osm.getOverlays().clear();
osm.getOverlays().add(marker);
osm.invalidate();
}
#Override
public void onLocationChanged(Location location) {
GeoPoint center = new GeoPoint(location.getLatitude(),location.getLongitude());
mc.animateTo(center);
addMarker(center);
}
#Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
#Override
public void onProviderEnabled(String s) {
}
#Override
public void onProviderDisabled(String s) {
}
#Override
protected void onDestroy() {
super.onDestroy();
if(locationManager!=null){
locationManager.removeUpdates(this);
}
}
}
My map layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical">
<org.osmdroid.views.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pt.ipp.estg.osm">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>
<activity android:name=".SignUpActivity" />
<activity android:name=".MapaPrincipal" />
</application>
</manifest>
Can someone help me?
I'm using this code, and I'm getting false value in
if(intent.getAction().equals(Intent.ACTION_SEARCH))
this condition, so Search view is not working. Appreciate any help.
MapsActivity
public class MapsActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor>,OnMapReadyCallback {
private GoogleMap mMap;
private PopupMenu supportMenuInflater;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMap = fragment.getMap();
Log.e("MAP"," load");
handleIntent(getIntent());
}
private void handleIntent(Intent intent){
Log.e("handle intent"," load"+intent);
Log.e("handle intent"," rate "+intent.getAction().equals(Intent.ACTION_SEARCH));
if(intent.getAction().equals(Intent.ACTION_SEARCH))
{
Log.e("handle intent"," if"+intent.getAction().equals(Intent.ACTION_SEARCH));
doSearch(intent.getStringExtra(SearchManager.QUERY));
}
else if(intent.getAction().equals(Intent.ACTION_VIEW))
{
Log.e("handle intent"," else if");
getPlace(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
}
else
{
Log.e("handle intent"," else");
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleIntent(intent);
}
private void doSearch(String query){
Log.e("Dosearch"," load "+query);
Bundle data = new Bundle();
data.putString("query", query);
getSupportLoaderManager().restartLoader(0, data, this);
}
private void getPlace(String query){
Log.e("getPlace"," load "+query);
Bundle data = new Bundle();
data.putString("query", query);
getSupportLoaderManager().restartLoader(1, data, this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu
getMenuInflater().inflate(R.menu.main, menu);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView search = (SearchView) menu.findItem(R.id.action_search).getActionView();
search.setIconifiedByDefault(false);
search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextChange(String query) {
doSearch(query);
return true;
}
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
});
}
return true;
}
#Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()){
case R.id.action_search:
onSearchRequested();
break;
}
return super.onMenuItemSelected(featureId, item);
}
#Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle query) {
CursorLoader cLoader = null;
if(arg0==0)
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.SEARCH_URI, null, null, new String[]{ query.getString("query") }, null);
else if(arg0==1)
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.DETAILS_URI, null, null, new String[]{ query.getString("query") }, null);
return cLoader;
}
#Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor c) {
showLocations(c);
}
#Override
public void onLoaderReset(Loader<Cursor> arg0) {
// TODO Auto-generated method stub
}
private void showLocations(Cursor c){
MarkerOptions markerOptions = null;
LatLng position = null;
mMap.clear();
while(c.moveToNext()){
markerOptions = new MarkerOptions();
position = new LatLng(Double.parseDouble(c.getString(1)),Double.parseDouble(c.getString(2)));
markerOptions.position(position);
markerOptions.title(c.getString(0));
mMap.addMarker(markerOptions);
}
if(position!=null){
CameraUpdate cameraPosition = CameraUpdateFactory.newLatLng(position);
mMap.animateCamera(cameraPosition);
}
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
Log.e("OnReady", String.valueOf(sydney));
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
Error Was in Manifest file
enter code here
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<!-- Protect the map component of the application using application signature -->
<permission
android:name="com.example.user.demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<!-- Allows to receive map -->
<uses-permission android:name="com.example.user.demo.MAPS_RECEIVE" />
<!-- Used by the Google Maps Android API V2 to download map tiles from Google Maps servers -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allows the Google Maps Android API V2 to cache map tile data in the device's external storage area -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Allows the Google Maps Android API V2 to use WiFi or mobile cell data (or both) to determine the device's location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Allows the Google Maps Android API V2 to use the Global Positioning System (GPS)
to determine the device's location to within a very small area -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Allows to contact Google Serves -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Google Maps Android API V2 requires OpenGL ES version 2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat" >
<activity
android:name=".MapsActivity"
android:label="#string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<!-- Points to searchable activity -->
<meta-data android:name="android.app.default_searchable"
android:value=".MainActivity" />
<!-- Points to searchable meta data -->
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<provider
android:name=".PlaceProvider"
android:authorities="com.example.user.demo.PlaceProvider"
android:exported="false" />
<!-- Specifies the Android API Key, which is obtained from Google API Console -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="--------------------------------" />
</application>
Hi I am trying to getting location(latitude and longitude) from Gps and set marker on google map but it is not working.In this code I am trying to get latitude and longitude from gps Location Listener method onLocationChanged but this method never calling not showing any toast.
public class MapsFragment extends Fragment implements OnMapReadyCallback, GoogleMap.OnMapLoadedCallback {
private static View view;
private SupportMapFragment mMap;
private static Double latitude = 28.6538100, longitude = 77.2289700;
GoogleMap gMap;
private static final int PERMISSION_REQUEST_CODE = 1;
private MinDisLocationListener locationListener;
private LocationManager lm;
public MapsFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
FragmentManager fm = getActivity().getSupportFragmentManager();
SupportMapFragment mMapFragment = (SupportMapFragment) getActivity()
.getSupportFragmentManager().findFragmentById(R.id.map);
locationListener = new MinDisLocationListener();
lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 2, this.locationListener);
} else {
requestPermission();
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 2, this.locationListener);
if (mMapFragment == null) {
mMapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map, mMapFragment).commit();
mMapFragment.getMapAsync(this);
}
view = inflater.inflate(R.layout.fragment_map, container, false);
return view;
}
#Override
public void onMapReady(GoogleMap map) {
gMap = map;
gMap.setOnMapLoadedCallback(this);
// drawMarker(latitude, longitude);
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(49.39, -124.83), 20));
gMap.addMarker(new MarkerOptions()
.position(new LatLng(37.7750, 122.4183))
.title("San Francisco")
.snippet("Population: 776733"));
gMap.getUiSettings().setZoomGesturesEnabled(true);
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
gMap.setMyLocationEnabled(true);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 2, this.locationListener);
} else {
requestPermission();
}
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FragmentManager fm = getChildFragmentManager();
mMap = (SupportMapFragment) fm.findFragmentById(R.id.map);
if (mMap != null) {
mMap = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map, mMap).commit();
mMap.getMapAsync(this);
}
}
private void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) {
Toast.makeText(getActivity(), "GPS permission allows us to access location data. Please allow in App Settings for additional functionality.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_CODE);
}
}
public void drawMarker(double lat, double lon) {
if (gMap != null) {
MarkerOptions marker = new MarkerOptions().position(new LatLng(lat, lon)).title(" Maps Tutorial").snippet("Android Ruler");
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(latitude, longitude)).zoom(12).build();
gMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
gMap.addMarker(marker);
}
}
#Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
gMap.setMyLocationEnabled(true);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,5000, 2, this.locationListener);
}
gMap.setMyLocationEnabled(true);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 2, this.locationListener);
} else {
}
break;
}
}
#Override
public void onResume() {
super.onResume();
FragmentManager fm = getChildFragmentManager();
mMap = (SupportMapFragment) fm.findFragmentById(R.id.map);
if (mMap != null) {
mMap = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map, mMap).commit();
mMap.getMapAsync(this);
}
}
#Override
public void onDestroyView() {
super.onDestroyView();
if (mMap != null) {
mMap = null;
}
}
#Override
public void onMapLoaded() {
}
public class MinDisLocationListener implements LocationListener {
#Override
public void onLocationChanged(Location location) {
Log.d("location", "onLocationChanged");
drawMarker(location.getLatitude(),location.getLongitude());
Toast.makeText(getActivity(), "onLocationChanged", Toast.LENGTH_SHORT).show();
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("location", "onStatusChanged");
Toast.makeText(getActivity(), "onStatusChanged", Toast.LENGTH_SHORT).show();
}
#Override
public void onProviderEnabled(String provider) {
Log.d("location", "onProviderEnabled");
Toast.makeText(getActivity(), "onProviderEnabled", Toast.LENGTH_SHORT).show();
}
#Override
public void onProviderDisabled(String provider) {
Log.d("location", "onProviderEnabled");
Toast.makeText(getActivity(), "onProviderEnabled", Toast.LENGTH_SHORT).show();
}
}
}
Msnifist File Is this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deltastar.catchme" >
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permisssion.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
- See more at:
http://www.theappguruz.com/blog/android-take-photo-camera-gallery-code-sample#sthash.PtrAvZrk.dpuf
<application
android:allowBackup="true"
android:icon="#drawable/ic_logo"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".LoginActivity" />
<activity
android:name=".RegisterActivity"
android:label="#string/register" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".OtpVerifyActivity"
android:label="#string/otp_verify" />
<activity android:name=".CreateProfileActivity" />
<activity android:name=".ChatMemberActivity" />
<activity android:name=".CreateGroup" />
<activity android:name=".AddMemberGroup" />
<activity android:name=".MeatPointName" />
<activity android:name=".MyMeeting" />
<activity android:name=".ChatActivity" />
<activity android:name=".GroupInfo" />
<activity
android:name=".MapChat"
android:label="#string/title_activity_map_chat" />
<activity android:name=".MyMeatingReq" />
<activity android:name=".UserProfile" />
<activity android:name=".MyProfile" />
<activity android:name=".SplashScreen" />
<activity android:name=".Settings" />
<activity
android:name=".DrawerDemo"
android:label="#string/title_activity_drawer_demo"
android:theme="#style/AppTheme" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MeetingPointLocation"
android:label="#string/title_activity_create_meating_point" />
<!--
ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
-->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".HomePage"
android:label="#string/title_activity_home_page"
android:theme="#style/AppTheme" />
<activity android:name=".MyLocation" />
<activity android:name="com.services.LocDemo" >
</activity>
</application>
</manifest>
fragment_map.xml
<FrameLayout 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.fragment.MapsFragment">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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" />
</FrameLayout>
Your code works perfect. You just have to move your device in the place where gps is available, because the place where you are testing your app may not have exposure to GPS satellite.
onLocationChanged() will be called once GPS is detected by the device
Check your project from there
http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial
But i think problem with manifest
Have you this
<permission android:name="tj.tajdev.mrking.whatisonindushanbe.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="tj.tajdev.mrking.whatisonindushanbe.permission.MAPS_RECEIVE" /> <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" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
And this
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
I am doing an application using the PreferenceFragmentCompat when i call the PreferenceFragmentCompat i am getting the error like java.lang.NoClassDefFoundError i am getting the confused what to do i have tried and checked some google suggestion it is not solving the problem please help to solve it
my Class which extends PreferenceFragmentCompat is as i am showing the code below
public class AutoAnswerPreferenceActivity extends PreferenceFragmentCompat implements OnSharedPreferenceChangeListener {
private AutoAnswerNotifier mNotifier;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
mNotifier = new AutoAnswerNotifier(getActivity());
mNotifier.updateNotification();
SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences();
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
/*PreferenceManager preferenceManager = getPreferenceManager();
preferenceManager.getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);*/
}
#Override
public void onDestroy() {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("enabled")) {
mNotifier.updateNotification();
}
}
#Override
public void onCreatePreferences(Bundle arg0, String arg1) {
// TODO Auto-generated method stub
}
and my fragment class is as shown below
public class AutoAnswarFragment extends Fragment {
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container, new AutoAnswerPreferenceActivity()).commit();
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new AutoAnswerPreferenceActivity ()).commit();
}
}
In Navigation Drawer i am calling the fragment to replace it as shown below
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new AutoAnswarFragment(),null).commit();
the manifest file is as shown below
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".NavigationDrawerMainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.koteswara.wise.autoanswer.AutoAnswerReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<receiver
android:name="com.koteswara.wise.autoanswer.AutoAnswerBootReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.koteswara.wise.autoanswer.AutoAnswerIntentService" />
<activity android:name="com.koteswara.wise.settings.GetCallerInfoActivity"
android:theme="#android:style/Theme.Dialog"
></activity>
</application>
please help to solve this i will be great full to you people. I am getting this error from the last one week
Here is my manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name="com.docuart.maps.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>
</application>
</manifest>
And Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="#+id/mapGoogle"
android:enabled="true"
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="my api key" />
</LinearLayout>
Here is my code:
public class MainActivity extends MapActivity {
private static final int MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1;//metre
private static final int MINIMUM_TIME_BETWEEN_UPDATES = 1000;//milisaniye
protected LocationManager locationManager;
MapView mView;
MapController mapController;
GeoPoint gPoint;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mView = (MapView) findViewById(R.id.mapGoogle);
mView.displayZoomControls(true);
mView.setBuiltInZoomControls(true);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES , MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new MyLocationListener());
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null){
gPoint = new GeoPoint((int)(location.getLatitude()*1000000),(int)(location.getLongitude()*1000000));
mapController = mView.getController();
mapController.animateTo(gPoint);
mapController.setZoom(14);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public class MyLocationListener implements LocationListener{
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
gPoint = new GeoPoint((int)(location.getLatitude()*1000000),(int)(location.getLongitude()*1000000));
mapController = mView.getController();
mapController.animateTo(gPoint);
mapController.setZoom(14);
}
#Override
public void onProviderDisabled(String provider) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}}
protected boolean isRouteDisplayed() {
return false;
}
}
Project running but i cant see my location. I cant find where is may fault. To see Screenshot: http://sdrv.ms/Wyf1Z1 Thank u for helping.
in your layout add your actual 2.0 auth api key in android:apiKey="my api key" />, which you must be reated from api key console .