I need some help...
My application can't show the map. I've enabled the API Key and try to create it many times, with new keystore.
Screenshot for result
The error code says:
12-14 03:47:45.527 31641-31956/tkj5a.dhiaulhaq.pnj.project_paksyamsi E/b: Authentication failed on the server.
12-14 03:47:45.527 31641-31956/tkj5a.dhiaulhaq.pnj.project_paksyamsi E/Google Maps Android API: Authorization failure. Please see
12-14 03:47:45.533 31641-31956/tkj5a.dhiaulhaq.pnj.project_paksyamsi E/Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: AIzaSyCLdUfhN9SoszJQiGzDF1rcOuV5P2RfcJs
Android Application (<cert_fingerprint>;<package_name>): 39:AD:91:AB:60:3D:34:22:1C:F3:36:4B:B6:98:6F:BB:61:5A:B5:60;tkj5a.dhiaulhaq.pnj.project_paksyamsi
And my layout:
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tkj5a.dhiaulhaq.pnj.project_paksyamsi">
<permission android:name="tkj5a.dhiaulhaq.pnj.project_paksyamsi.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="tkj5a.dhiaulhaq.pnj.project_paksyamsi.permission.MAPS_RECEIVE"/>
<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_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="tkj5a.dhiaulhaq.pnj.project_paksyamsi.permission.READ_GSERVICES"/>
<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"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapsActivity"
android:theme="#style/AppTheme.NoActionBar"></activity>
<activity android:name=".CheckInActivity"
android:theme="#style/AppTheme.NoActionBar"></activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCLdUfhN9SoszJQiGzDF1rcOuV5P2RfcJs"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
</application>
</manifest>
And here's the MapsActivity.java:
package tkj5a.dhiaulhaq.pnj.project_paksyamsi;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import java.util.ArrayList;
public class MapsActivity extends FragmentActivity {
private GoogleMap map;
private DBLokasi lokasi;
private ArrayList<DBLokasi> values;
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFrag=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
map=mapFrag.getMap();
map.setMyLocationEnabled(true);
Bundle b=this.getIntent().getExtras();
if (b.containsKey("longitude")){
final LatLng latLng=new LatLng(b.getDouble("latitude"),b.getDouble("longitude"));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,16));
map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(MapsActivity.this,"Lokasi Saat Ini " + latLng.latitude+ "," +latLng.longitude,Toast.LENGTH_LONG).show();
return false;
}
});
}else if (this.getIntent().getSerializableExtra("lokasi")!=null){
lokasi=(DBLokasi)this.getIntent().getSerializableExtra("lokasi");
if (lokasi!=null){
LatLng latLng=new LatLng(lokasi.getLatD(),lokasi.getLngD());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,16));
map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)).title(lokasi.getNama()));
}
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
final Dialog dialog=new Dialog(MapsActivity.this);
dialog.setTitle("Checkin Data : ");
dialog.setContentView(R.layout.fragment_dialog_datashow);
TextView tvNama=(TextView)dialog.findViewById(R.id.tv_nama);
TextView tvKoordinat=(TextView)dialog.findViewById(R.id.tv_koordinat);
Button btOK=(Button)dialog.findViewById(R.id.bt_checkin_ok);
tvNama.setText(String.format(getResources().getString(R.string.checkin_label_name),marker.getTitle()));
tvKoordinat.setText(marker.getPosition().latitude+ ","+ marker.getPosition().longitude);
btOK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.cancel();
}
});
dialog.show();
return false;
}
});
}
else {
LatLng init;
DBLokasi lokInit;
LatLng latLng;
values=((ArrayList<DBLokasi>)this.getIntent().getSerializableExtra("arraylokasi"));
lokInit=values.get(0);
init=new LatLng(lokInit.getLatD(),lokInit.getLngD());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(init,16));
for (DBLokasi lok:values){
latLng=new LatLng(lok.getLatD(),lok.getLngD());
map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
}
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
final Dialog dialog=new Dialog(MapsActivity.this);
dialog.setTitle("Checkin Data : ");
dialog.setContentView(R.layout.fragment_dialog_datashow);
TextView tvNama=(TextView)dialog.findViewById(R.id.tv_nama);
TextView tvKoordinat=(TextView)dialog.findViewById(R.id.tv_koordinat);
Button btOK=(Button)dialog.findViewById(R.id.bt_checkin_ok);
tvNama.setText(String.format(getResources().getString(R.string.checkin_label_name)));
tvKoordinat.setText(marker.getPosition().latitude+","+marker.getPosition().longitude);
btOK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.cancel();
}
});
dialog.show();
return false;
}
});
}
}
}
Thanks for any helps guys :)
Confirm the SHA-1 key you are getting in the message and the key you have on server are same. Also, make sure adding the API key in manifest as well as in a XML file (release -> res -> values -> google_maps_api.xml) which automatically gets generated.
**Manifest:**
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
and
**google_maps_api.xml**
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
YOUR_KEY_HERE
</string>
You can get SHA-1 key and package name from the error message you have posted. Both are separated by ';'
Make sure your API key is the correct one... and maybe check if you have the 'Google Play Services' SDK installed.
It says "In the Google Developer Console" so i would start there lol
Check:
-SHA 1 key
-API Key
Don't forget to hit 'Save' once you're done, i know a few people who have made that mistake before!
Related
I am trying to detect if any calls are presently being attended or the cell phone is ringing.If not, the cell radio should switch off.Since I am using telephony manager for the first time. I am not able to rectify the error.
The error is " cannot resolve 'setRadioPower(?)'.
My MainActivity.java is:
public class MainActivity extends AppCompatActivity {
private TelephonyManager tm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TelephonyManager telephonyManager =
(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener callStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber)
{
if(state==TelephonyManager.CALL_STATE_RINGING){
Toast.makeText(getApplicationContext(),"Phone Is Ringing",
Toast.LENGTH_LONG).show();
}
if(state==TelephonyManager.CALL_STATE_OFFHOOK){
Toast.makeText(getApplicationContext(),"Phone is Currently in A call",
Toast.LENGTH_LONG).show();
}
if(state==TelephonyManager.CALL_STATE_IDLE){
tm.setRadioPower(disabled);
}
}
};
telephonyManager.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
My AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vk9621.radiocall">
<application
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>
</application>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>
My imports are:
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
Can someone tell me how to rectify this error?
The reason you won't find it in the developer docs is that it is hidden.
However, you may always find hidden methods in the Android Source Code.
Code reference: public boolean setRadioPower(boolean turnOn){}
If your phone is not rooted, or if you do not have system permission android.Manifest.permission.MODIFY_PHONE_STATE, you won't be able to access this API.
However, if you do have those permissions, you can easily achieve this using the following code:
ITelephony iTelephony = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
try {
iTelephony.setRadioPower(true);
} catch (RemoteException e) {
e.printStackTrace();
}
I am new to android and I am trying to make this application where I need location co-ordinates of my current position and show my position on the map. all the other parts of the app run quite well until just when ever I try to get the latitude and longitude from the fusedLocationApi. I have followed this tutorial Get the Last Known Location and have tried to implement it on Google Map Activity.
here is my java file:
package com.example.deep.app_project;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.plus.Plus;
public class Map extends FragmentActivity implements GoogleMap.OnMyLocationChangeListener,
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
LocationManager lm;
TextView lt, ln;
String provider;
Location l;
double lon= 0, lat =0;
GoogleApiClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
setUpMapIfNeeded();
client = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
client.connect();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
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();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
mMap.setMyLocationEnabled(true);
}
public void button_Map_Back(View v){
Intent MainActivityIntent = new Intent(Map.this, MainActivity.class);
startActivity(MainActivityIntent);
finish();
}
#Override
public void onConnected(Bundle bundle) {
l = LocationServices.FusedLocationApi.getLastLocation(client);
if (l != null) {
lt.setText(String.valueOf(l.getLatitude()));
ln.setText(String.valueOf(l.getLongitude()));
}
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
#Override
public void onMyLocationChange(Location location) {
lt.setText(String.valueOf(location.getLatitude()));
ln.setText(String.valueOf(location.getLongitude()));
}
here is my .xml file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.deep.app_project" >
<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" />
<application
android:allowBackup="true"
android:icon="#mipmap/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>
<activity
android:name=".Distance_timer"
android:label="#string/title_activity_distance_timer" >
</activity>
<activity
android:name=".Journey_type"
android:label="#string/title_activity_journey_type" >
</activity>
<activity
android:name=".prev_stat_fragment"
android:label="#string/title_activity_prev_stat_fragment" >
</activity>
<activity
android:name=".Result"
android:label="#string/title_activity_result" >
</activity>
<activity
android:name=".settings_fragment"
android:label="#string/title_activity_settings_fragment" >
</activity>
<activity
android:name=".SimpleFragmentActivity"
android:label="#string/title_activity_simple_fragment" >
</activity>
<activity
android:name=".Time_timer"
android:label="#string/title_activity_time_timer" >
</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="AIzaSyD-LoJLRIyTF2mI5HdKULNk1QhBAQlhkRQ"/>
<activity
android:name=".Map"
android:label="#string/title_activity_map" >
</activity>
</application>
I have recently done this... and found it confusing to deal with varying different documentation.
I found it easier to use OnMyLocationChangeListener:
Activity implements GoogleMap.OnMyLocationChangeListener
then Override onLocationChanged:
#Override
public void onMyLocationChange(Location location) {
LatLng pos = new LatLng(location.getLatitude(),location.getLongitude());
CameraUpdate mLoc = CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().target(pos).zoom(ZOOM_LEVEL).build());
map.moveCamera(mLoc);
mLocMarker = map.addMarker(new MarkerOptions()
.title(TITLE)
.snippet(SNIPPET)
.position(pos)
.draggable(true));
mLocMarker.showInfoWindow();
map.setOnMyLocationChangeListener(null);
}
I'm working on a project which involves a "Points of Interest" locator. I have a generated Google Maps API v2 key and I've added all the proper permissions to the AndroidManifest (as you'll see below), and everything compiles...except for the map itself! There's a marker that shows your current location and as well as the GPS coordinates but not the map, which needless to say is essential. Also there are no runtime erros except that the LogCat says at points "There is too much output to process". Any help would be greatly appreciated.
Android Manifest
package="com.example.kavin_000.travelapplication" >
<!-- suppress AndroidDomInspection -->
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<permission
android:name="com.example.kavin_000.travelapplication.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.kavin_000.travelapplication.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/nyit_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".ow_main_page"
android:label="#string/app_name" >
</activity>
<activity
android:name=".manhattan_main_page"
android:label="#string/title_activity_manhattan_main_page" >
</activity>
<activity
android:name=".main_page"
android:label="Travel Application" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ow_campus_points_of_interest"
android:label="#string/title_activity_ow_campus_points_of_interest" >
</activity>
<activity
android:name=".manhattan_campus_points_of_interest"
android:label="#string/title_activity_manhattan_campus_points_of_interest" >
</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" />
</application>
</manifest>
Layout XML file
<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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".ow_main_page"
android:background="#ffffb502">
<fragment
android:id="#+id/googleMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_above="#+id/latlongLocation" />
<TextView
android:id="#+id/latlongLocation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:background="#ff058fff"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#ffffffff"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
</RelativeLayout>
Java class in question
package com.example.kavin_000.travelapplication;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class ow_campus_points_of_interest extends FragmentActivity implements LocationListener {
GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//show error dialog if GooglePlayServices not available
if (!isGooglePlayServicesAvailable()) {
finish();
}
setContentView(R.layout.activity_ow_campus_points_of_interest);
SupportMapFragment supportMapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);
googleMap = supportMapFragment.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(bestProvider);
if (location != null) {
onLocationChanged(location);
}
locationManager.requestLocationUpdates(bestProvider, 20000, 0, this);
}
#Override
public void onLocationChanged(Location location) {
TextView locationTv = (TextView) findViewById(R.id.latlongLocation);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
googleMap.addMarker(new MarkerOptions().position(latLng));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
locationTv.setText("Latitude:" + latitude + ", Longitude:" + longitude);
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
private boolean isGooglePlayServicesAvailable() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (ConnectionResult.SUCCESS == status) {
return true;
} else {
GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
return false;
}
}
}
It sounds like there may be an issue with your authorization on Google App Engine. Did you make sure to use the SHA1 fingerprint from your debug.keystore and not from your release keystore? Additionally, make sure that you are appending ;com.example.kavin_000.travelapplication to the end of the SHA1 fingerprint.
If you have not added your SHA1 fingerprint to the list of authorized applications, that is the issue. It can be done by finding your debug.keystore file (search on Google depending on your OS), and running the following command:
keytool -list -v -keystore debug.keystore
Here is Main Activity.java code :
package com.example.vd;
import android.app.Activity;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
public class MainActivity extends FragmentActivity implements LocationListener {
GoogleMap googleMap;
LatLng myPosition;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment fm=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map1);
googleMap=fm.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager=(LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria=new Criteria();
String provider =locationManager.getBestProvider(criteria, true);
Location location=locationManager.getLastKnownLocation(provider);
if(location!=null){
double latitude =location.getLatitude();
double longitude=location.getLongitude();
LatLng latlng=new LatLng(latitude, longitude);
myPosition=new LatLng(latitude, longitude);
googleMap.addMarker(new MarkerOptions().position(myPosition).title("Here"));
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
here is activity_main.xml code :
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity" >
<fragment
android:id="#+id/map1"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
And here is AndroidManifest.xml code :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vd"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="14" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<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-permission android:name="com.example.vd.permission.MAPS_RECEIVE"/>
<permission android:name="com.example.vd.permission.MAPS_RECEIVE"
/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.vd.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.maps.v2.API_KEY"
android:value="AIzaSyB5pN0xyJTRLVOAX3scagfb58b0bB0TBwg"/>
</application>
And I'm using Android 4.2.2 and using library google-play-services_lib
I've already search on the Internet and try to fix it for many many times but I still getting this error : Unfortunately application has stopped error.
See here,just change the api key with your key in manifest file and follow these steps:
and make sure that generate api key with package name which is mentioned in android manifest file and your google_play_services_lib project should be present in your project's work space only.
Manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<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" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.geeklabs.map.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.maps.v2.API_KEY"
android:value="replace with your API key"/>
</application>
</manifest>
MainActivity.java:
package com.geeklabs.map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
After got this let me know.
And make sure following steps done correct or not:
Steps:
* to ensure that device has Google Play services APK
* to install Google Play Service rev. more than 2
to create project at https://code.google.com/apis/console/
to enable "Google Maps Android API v2"
to register of SHA1 in project (NOW, YOU NEED WRITE SHA1;your.app.package.name) at APIs console and get API KEY
to copy directory ANDROID_SDK_DIR/extras/google/google_play_services/libproject/google-play-services_lib to root of your project
to add next line to the YOUR_PROJECT/project.properties
android.library.reference.1=google-play-services_lib
to add next lines to the YOUR_PROJECT/proguard-project.txt
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
Okay, now you ready to create your own Google Map app with using Google Map APIs V2 for Android.
If you create application with min SDK = 8, please use android support library v4 + SupportMapFragment instead of MapFragment.
Replace your Code
from
SupportMapFragment fm=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map1);
to
MapFragment fm=(MapFragment)getFragmentManager().findFragmentById(R.id.map1);
Also Add
<permission
android:name="com.xxxxxx.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
For More Details:
Visit: Android Maps V2
I'm having an Android GPS project for my CS class. Right now I'm working through tutorials (using Eclipse with ADT plugin) to have an idea of how to use the Android library, but along the way, I received the Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
I checked on LogCat and it seems the error starts on this line:
03-29 23:05:14.721: E/PackageManager(72): Package virginia.edu.cs2110 requires unavailable shared library android.location; failing!
I have looked up this problem and did all the things that I was able to find. I declared the uses-library field in the manifest file:
<uses-library android:name="android.location" />
<uses-library android:name="com.google.android.maps" />
If anyone is wondering, this is my whole manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="virginia.edu.cs2110"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TrivialGPS"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="android.location" />
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
I also created an Android emulator with Target Name "Google API (Google Inc.)":
http://i42.tinypic.com/2dj3vd5.jpg
Also, here's the code that I wanted to run:
package virginia.edu.cs2110;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class TrivialGPS extends MapActivity {
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// create a map view
mapView = new MapView(this, "C7:63:2F:C8:93:8B:E1:83:D6:4F:D3:5B:62:C1:75:90");
mapController = mapView.getController();
mapController.setZoom(22);
setContentView(mapView);
// get a hangle on the location manager
locationManager =
(LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
new LocationUpdateHandler());
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public class LocationUpdateHandler implements LocationListener {
#Override
public void onLocationChanged(Location loc) {
int lat = (int) (loc.getLatitude()*1E6);
int lng = (int) (loc.getLongitude()*1E6);
GeoPoint point = new GeoPoint(lat, lng);
mapController.setCenter(point);
setContentView(mapView);
}
#Override
public void onProviderDisabled(String provider) {}
#Override
public void onProviderEnabled(String provider) {}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
}
Delete <uses-library android:name="android.location" />, as there is no such library.