Android Studio setmylocationenabled(true) throws SecurityException - java

I've encountered a problem. My program throes SecurityException, even if I declraed all the Permissions.
Here is MapsActivity class:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// 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);}
public void onMapReady(GoogleMap googleMap) {
try{
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
// set map type
}
Here is the Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mazebug.danuleoshaleosha">
<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="#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>
<activity android:name=".Interface" />
<activity android:name=".Main2Activity" />
<activity android:name=".Main22Activity" />
<activity android:name=".SFR_Table" />
<activity android:name=".sfrtable2" />
<activity android:name=".sfrtable3" />
<activity android:name=".sfrtable4" />
<activity android:name=".sfrtable5" />
<activity android:name=".sfrtable6" />
<activity android:name=".sfrtable7" />
<activity android:name=".mySfrs" />
<activity android:name=".Search_bySiteName" />
<activity android:name=".Search_byDate" />
<activity android:name=".Search_byLocation" />
<activity android:name=".Found_1" />
<activity android:name=".Found_2" />
<activity android:name=".Found_3" />
<activity android:name=".Edit_first" />
<activity android:name=".Edit_1_2" />
<activity android:name=".Edit_1_3" />
<activity android:name=".Edit_1_4" />
<activity android:name=".Edit_1_5" />
<activity android:name=".Edit_1_6" />
<activity android:name=".Edit_1_7" />
<activity android:name=".testing" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name=".Main23Activity" />
<!--
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="AIzaSyA-z6nM3WoXwP7dBzIdz1_dssl8X81xttg" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps"></activity>
</application>
Here is the thrown Exception
FATAL EXCEPTION: main Process: mazebug.danuleoshaleosha, PID: 13162
java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
at com.google.maps.api.android.lib6.e.ev.c(Unknown Source)
at com.google.android.gms.maps.internal.j.onTransact(SourceFile:274)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.setMyLocationEnabled(Unknown Source)
at com.google.android.gms.maps.GoogleMap.setMyLocationEnabled(Unknown Source)
at mazebug.danuleoshaleosha.MapsActivity.onMapReady(MapsActivity.java:51)
at com.google.android.gms.maps.SupportMapFragment$zza$1.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzo$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.be.a(SourceFile:82)
at com.google.maps.api.android.lib6.e.fb.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I'm pretty confused, 'cause it seems like I granted the required permissions.
Please give me a piece of advice. Thanks!

Try change the code.
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) return;
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);

Related

Unable to obtain GPS location coordinates using a service with SecurityException "gps" location provider requires ACCESS_FINE_LOCATION permission

This is my GPS service that I'm using to obtain GPS coordinates in the background. I have logged at various areas of the code to see which bits are being called and which aren't. This service is called from a button being clicked. Nothing seems to be logged for the location and the main issue is regarding the location updates which is not returning anything.
public class SetGPS extends Service {
private LocationListener listener;
private LocationManager locationManager;
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
//this is logged successfully
Log.i("LocationListener","is called");
listener = new LocationListener() {
#Override
public void onLocationChanged(Location location) {
Intent i = new Intent("location_update");
i.putExtra("coordinates", location.getLongitude() + " " + location.getLatitude());
sendBroadcast(i);
String latitude = String.valueOf(location.getLatitude());
//this is NOT logged successfully
Log.i("coordinates SetGPS",latitude);
}
#Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
#Override
public void onProviderEnabled(String s) {
}
#Override
public void onProviderDisabled(String s) {
Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
//this is NOT logged successfully
Log.i("onProviderDisabled","is logged");
}
};
locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
try {
//does NOT successfully log
Log.i("testing","testing");
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 0, listener);
}
catch (SecurityException e){
e.printStackTrace();
}
}
#Override
public void onDestroy() {
super.onDestroy();
if(locationManager != null){
locationManager.removeUpdates(listener);
}
}
}
And here is my manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a_phi.nowswap">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_CONTACTS"
android:required="true" />
<uses-permission
android:name="android.permission.READ_CONTACTS"
android:required="true" />
<meta-data
android:name="firebase_crash_collection_enabled"
android:value="false" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<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">
<service
android:name=".HceService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="#xml/apduservice" />
</service>
<service android:name=".SetGPS"
android:permission="android.permission.ACCESS_FINE_LOCATION"/>
<activity
android:name=".LoginActivity"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:scheme="file" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.CATEGORY_DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Pilot"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:scheme="file" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.CATEGORY_DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".personalHome"
android:label="#string/title_activity_personal_home"
android:theme="#style/AppTheme.NoActionBar"></activity>
<activity
android:name=".ProfessionalHome"
android:label="professionalHome"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.CATEGORY_DEFAULT" />
<data android:mimeType="text/plain`" />
<data android:scheme="file" />
</intent-filter>
</activity>
<activity
android:name=".EditDetailsPersonal"
android:label="editDetails"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".EditDetailsProfessional"
android:label="editDetailsProfessional"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".receivedContact"
android:label="#string/title_activity_received_contact"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".RegisterActivity"
android:label="RegisterActivity"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".AddContact"
android:label="#string/add_contact_button"
android:theme="#style/Theme.AppCompat.Light" />
<activity
android:name=".DrawerActivity"
android:label="#string/title_activity_drawer"
android:theme="#style/Theme.AppCompat.DayNight.DarkActionBar"></activity>
</application>
</manifest>
It returns the following stacktrace.
08-31 11:44:47.710 1399-1411/? W/System.err: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
at com.android.server.LocationManagerService.checkResolutionLevelIsSufficientForProviderUse(LocationManagerService.java:1321)
at com.android.server.LocationManagerService.getProviderProperties(LocationManagerService.java:2334)
at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:378)
at com.android.server.HwLocationManagerService.onTransact(HwLocationManagerService.java:379)
08-31 11:44:47.711 1399-1411/? W/System.err: at android.os.Binder.execTransact(Binder.java:565)
08-31 11:44:47.712 1399-2192/? W/System.err: java.lang.SecurityException: "network" location provider requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
at com.android.server.LocationManagerService.checkResolutionLevelIsSufficientForProviderUse(LocationManagerService.java:1324)
at com.android.server.LocationManagerService.getProviderProperties(LocationManagerService.java:2334)
at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:378)
at com.android.server.HwLocationManagerService.onTransact(HwLocationManagerService.java:379)
at android.os.Binder.execTransact(Binder.java:565)
08-31 11:45:06.132 17192-17192/com.example.a_phi.nowswap W/System.err: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
at android.os.Parcel.readException(Parcel.java:1665)
at android.os.Parcel.readException(Parcel.java:1618)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:614)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:952)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:536)
at com.example.a_phi.nowswap.SetGPS.onCreate(SetGPS.java:72)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3350)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1670)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6623)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
which indicates there is an issue with
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 0, listener);

BroadcastReceiver can't detect/read sms

I'm building an app that would read incoming SMS. But, my BroadcastReceiver class can't detect/read incoming SMS. I think my code is correct but still it's not working.
Here's my code:
[XML]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.crashlocator.carlax.crashlocator">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.VIBRATE" />
<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:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
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=".MapsActivity"
android:label="#string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.default" />
</intent-filter>
</activity>
<activity android:name=".MainActivity2" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.default" />
</intent-filter>
</activity>
<receiver
android:name=".SmsReceiver"
android:exported="true" >
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
[JAVA CLASS]
public class SmsReceiver extends BroadcastReceiver {
private static final String SMS_BUNDLE = "pdus";
private String smsBody, address;
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"Test",Toast.LENGTH_LONG);
}
public void showNotification(Context context) {
Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MapsActivity.class), 0);
v.vibrate(500);
Intent in = new Intent("SmsMessage.intent.MAIN").
putExtra("get_msg", address + ":" + smsBody);
context.sendBroadcast(in);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
//.setSmallIcon(R.drawable.notif1)
.setContentTitle("Attention!")
.setContentText("Car crash occure.");
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
I think you forgot to put .show() at the end of Toast.
Toast.makeText(context, "Test" ,Toast.LENGTH_LONG).show();

Google maps v2 API integration problems

I am trying to integrate google maps in my android app, but after creatng apk and starting it on the phone (Android 4.4.4) it crashes. If i start on emulator i get message "Failure [INSTALL_FAILED_MISSING_SHARED_LIBRARY]". What can i done incorrect?
Here is my files
MainActivity.java
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tieride);
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
if (savedInstanceState == null) {
// First incarnation of this activity.
mapFragment.setRetainInstance(true);
} else {
mMap = mapFragment.getMap();
}
setUpMapIfNeeded();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
if (mMap == null) {
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
// Enabling MyLocation Layer of Google Map
mMap.setMyLocationEnabled(true);
}
}
}
and here is my layout
<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/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="there is my package" >
<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.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="there is my key, which i got from API console"/>
<uses-library android:name="com.google.android.maps" />
<permission
android:name="(there is my app path).permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="(there is my app path).permission.MAPS_RECEIVE"/>
<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"/>
<activity
android:screenOrientation="portrait"
android:name=".login.LoginActivity"
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:screenOrientation="portrait"
android:name=".main.MainActivity"
android:label="#string/thereismytitle" >
</activity>
</application>
</manifest>
Is your emulator target set with Google APIs (Google Inc.)? Last time I used the google map api, I had the same experience and it worked after I set the target to Google APIs (Google Inc.)-API Level (version).

GCM no receive messages in 2.3.6 but it's ok in 4.1.2

The problem is only with android 2.3.6 .
With 4.x, there isn't any problem, the receiver it's ok.
I have received the registration ID with 2.3.6 but the messages are never received.
My Manifest is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.arte.bilunaā€¯
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="net.arte.biluna.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="net.arte.biluna.permission.C2D_MESSAGE" />
<application
android:name="net.arte.biluna.businesslogic.CosmoApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light" >
<!-- android:theme="#style/Theme.Sherlock" > -->
<activity
android:name="net.arte.biluna.SplashScreen"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="net.arte.biluna.GreatestActivity"
android:screenOrientation="portrait" />
<activity
android:name="net.arte.biluna.LogInActivity"
android:screenOrientation="portrait" />
<activity
android:name="net.arte.biluna.HomePage"
android:screenOrientation="portrait" />
<activity
android:name="net.arte.biluna.LiveTourActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="net.arte.biluna.ChatActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="net.arte.biluna.ForYouActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="net.arte.biluna.StoreActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<service android:name="net.arte.biluna.GcmIntentService" />
<receiver
android:name="net.arte.biluna.GcmBroadcastReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="net.arte.biluna" />
</intent-filter>
</receiver>
</application>
My receiver:
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
my activity:
...
if (checkPlayServices()) {
gcm = GoogleCloudMessaging.getInstance(this);
regid = getRegistrationId(context);
if (regid.equals("")) {
registerInBackground();
}
}
...
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
finish();
}
return false;
}
return true;
}
Check the Google play services version number and there is a pretty defined method to check Google play services a availability
Latest release of gcm using google play is very easy to implement and can be used for longer time.
See this tutorial. Hope it might help.
http://techlovejump.in/2013/11/android-push-notification-using-google-cloud-messaging-gcm-php-google-play-service-library/

Google Map is getting loaded but marker is not getting shown on the map in android native app

I just wrote a simple program to an add maker on the Google map. When I run the app on the mobile, the marker is not visible but the Google map is getting loaded. Please help me out. I wrote the program based on Google documentation. (https://developers.google.com/maps/documentation/android/marker#add_a_marker). Here is the code.
MainActivity
public class MainActivity extends Activity {
GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(mMap== null){
mMap= ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
}
mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world"));
}
#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;
}
}
Activity_main.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"
xmlns:map="http://schemas.android.com/apk/res-auto"
map:cameraBearing="112.5"
map:cameraTargetLat="-33.796923"
map:cameraTargetLng="150.922433"
map:cameraTilt="30"
map:cameraZoom="6"
map:mapType="normal"
map:uiCompass="false"
map:uiRotateGestures="true"
map:uiScrollGestures="false"
map:uiTiltGestures="true"
map:uiZoomControls="false"
map:uiZoomGestures="true"/>
Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dummymaptest"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.dummymaptest.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.dummymaptest.permission.MAPS_RECEIVE"/>
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<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/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="key" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.dummymaptest.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>
You have not created marker object. Do it like this:
Marker marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world"));
Marker will be shown somewhere around africa.
You are adding marker with lat-long 0,0, so the marker would somewhere in the sea near africa. Give some real lat-long, then the marker will surely get displayed.

Categories