I've tried and tried and tried to figure this problem out. I've searched everywhere and I haven't found a solution yet. I understand that there are many forums on this topic, but none have helped me come up with a solution.
The problem I'm having is that when I run my android application, in the emulator, the area for the map comes up only with grey tiles. I've read online that the problem is most likely the Google API key, but I've tried multiples way to generate it (Used the Android Studio Terminal to obtain SHA1, I had Android studio generate a link to google so it can automatically create the key).
I'm hoping someone can help me out, I'm pretty desperate here!
Here's my Activity class
package com.bignerdranch.android.taskmanager;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class AddLocationMapActivity extends MapActivity {
public static final String ADDRESS_RESULT = "address";
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.add_location);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
#Override
protected boolean isLocationDisplayed() {
return true;
}
}
This is the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/location_title"
.../>
<EditText
android:id="#+id/task_address"
.../>
<Button
android:id="#+id/map_location_button"
.../>
<com.google.android.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/map_location_button"
android:layout_above="#+id/use_this_location_button"
android:clickable="true"
android:apiKey="AIza.................................." />
<Button
android:id="#id/use_this_location_button"
.../>
</RelativeLayout>
Then, this is the manifest file:
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bignerdranch.android.taskmanager">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_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" />
<application
android:name=".TaskManagerApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIza..........................." />
<activity android:name=".ViewTasksActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".AddTaskActivity"
android:text="#string/add_task"/>
<activity android:name=".AddLocationMapActivity"
android:text="#string/add_location_to_task"/>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
Then the build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:24'
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.bignerdranch.android.taskmanager"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
}
And lastly, this is what is generated by the Monitor:
12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: IOException processing: 26
12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: java.io.IOException: Server returned: 3
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at java.lang.Thread.run(Thread.java:818)
I WOULD BE FOREVER GRATEFUL TO THE PERSON WHO CAN HELP ME FIGURE THIS PROBLEM OUT!
Grey tiles instead of map
The map that you're using com.google.android.maps.MapView is a v1 of Google Map API. Unfortunately, it is officially deprecated.
You should use the new version of Google Maps API which is Version 2
Here's a tutorial for Google Map V2
Related
I've asked a question before where my app was working only on the emulator but not a real device, here's a link of it:
Firebase database is not updating with no errors, slow response
unfortunately, I wasn't able to figure out the issue or solve it. So, I started from scratch and build a simple app that writes "TEST" to a real-time database, and the same issue was there, the app is working ONLY on the emulator but not my real device.
So, I figured out that the app is not able to connect to firebase when I ran it in my device. But I couldn't figure out why?
Here's my main activity:
package com.example.alice.testingfirebase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends AppCompatActivity {
private DatabaseReference mDatabase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDatabase = FirebaseDatabase.getInstance().getReference();
for (int i = 0; i<10;i++) {
String id = i+"";
mDatabase.child("users").child(id).setValue("TEST");
}
}
}
Here's my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alice.testingfirebase">
<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>
</manifest>
and here's my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.alice.testingfirebase"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
The rules of the database are set to be public.
After adding the INTERNET permission, the app keeps stopping, and here's part of the log cat:
09-09 14:39:55.374 21502-21537/com.example.alice.testingfirebase V/FA: Connection attempt already in progress
09-09 14:39:55.455 21502-21502/com.example.alice.testingfirebase D/AndroidRuntime: Shutting down VM
09-09 14:39:55.456 21502-21502/com.example.alice.testingfirebase E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.alice.testingfirebase, PID: 21502
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alice.testingfirebase/com.example.alice.testingfirebase.MainActivity}: com.google.firebase.database.DatabaseException: Calls to setLogLevel() must be made before any other usage of FirebaseDatabase instance.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2955)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: com.google.firebase.database.DatabaseException: Calls to setLogLevel() must be made before any other usage of FirebaseDatabase instance.
at com.google.firebase.database.FirebaseDatabase.zzb(Unknown Source:38)
at com.google.firebase.database.FirebaseDatabase.setLogLevel(Unknown Source:3)
at com.example.alice.testingfirebase.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:7183)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
09-09 14:39:55.472 21502-21551/com.example.alice.testingfirebase W/zygote64: Skipping duplicate class check due to unrecognized classloader
09-09 14:39:55.474 21502-21551/com.example.alice.testingfirebase I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
09-09 14:39:55.475 21502-21551/com.example.alice.testingfirebase I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 6
09-09 14:39:55.506 21502-21551/com.example.alice.testingfirebase W/zygote64: Skipping duplicate class check due to unrecognized classloader
09-09 14:39:55.567 21502-21559/com.example.alice.testingfirebase D/NetworkSecurityConfig: No Network Security Config specified, using platform default
09-09 14:39:55.573 21502-21559/com.example.alice.testingfirebase D/TcpOptimizer: TcpOptimizer-ON
09-09 14:40:00.281 21502-21521/com.example.alice.testingfirebase I/zygote64: WaitForGcToComplete blocked for 22.520ms for cause HeapTrim
09-09 14:40:00.286 21502-21521/com.example.alice.testingfirebase W/zygote64: Suspending all threads took: 5.439ms
For developers using VIVO and OPPO phones, these brands have a strange problem connecting to Firebase. I have 7 devices of different makes and configurations for testing purposes and all of them connect except these two. There are no errors and no exceptions. They just refuse to connect. Just wanted to float this point out so developers using these phones know about the problem.
Please add this to your manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alice.testingfirebase">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"..
....
</application>
</manifest>
Also edit your MainActivity like
FirebaseDatabase obj= FirebaseDatabase.getInstance();
DatabaseReference mDatabase= obj.getReference();
for (int i = 0; i<10;i++)
{
String id = i+"";
mDatabase.child("users").child(id).setValue("TEST");
}
First, you don't have internet permission in your AndroidManifext.xml and I'm still wondering how it does works on the emulator.
Second, initialize FirebaseDatabase then DatabaseReference to be able to read-write data in Firebase Realtime database:
// Write a message to the database
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference().child("users").child("id"); //location to put, can be anything you want ...
myRef.setValue("TEST");
Also, are you sure this is what you want? Putting String in an id field? Consider checking your FireBase Database in console!
Read: https://firebase.google.com/docs/database/android/start
API Version Incompatibilities
I have made an app using android studio, until now I have been testing it on a 'Nexus 5X (API 23) emulator'. However, today i started debugging the app on a 'Samsung Galaxy Tab 2 7.0 (API 18)' and the app will not even start. I know this is because of incompatibilities between the API's specifically something to do with the Theme i'm using. What i want to know is how i can fix this problem without changing the look of the app drastically.
Log Cat Crash Log
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.***.********/com.***.********.MenuActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:124)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.***.*******.MenuActivity.onCreate(MenuActivity.java:47)
at android.app.Activity.performCreate(Activity.java:5283)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MenuActivity"
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=".About" />
<activity android:name=".SettingsActivity" />
<activity android:name=".********Activity" />
<activity android:name=".********Activity" />
<activity
android:name=".VideoPlayerActivity"
android:screenOrientation="landscape" />
<activity android:name=".*******Activity"></activity>
</application>
Gradle Build App File
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.***.*******"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "2.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
}
Note: The last two lines (the ones with compile...) are underlined in red and say 'This support library should not use a different version(22) than the compile SDK version(21).'
Edit: If I change the Theme for the main activity to '#style/Theme.AppCompat.NoActionBar' the application will start however, the look of the application changes. Also, other activities that do not use the new theme work fine.
Any Help is Appreciated.
I am developing a chat application for Android. But while trying to register with GCM, I am receiving the following error:
04-02 16:59:29.793 29773-30031/purepush.group101.talktoday W/InstanceID/Rpc: Found 10010
04-02 16:59:29.920 29773-30031/purepush.group101.talktoday W/System.err: java.io.IOException: SERVICE_NOT_AVAILABLE
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.zzc.zzb(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.zzc.zza(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.InstanceID.zzc(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.InstanceID.getToken(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at purepush.group101.talktoday.LoginActivity$GetGCMTokenTask.doInBackground(LoginActivity.java:240)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at purepush.group101.talktoday.LoginActivity$GetGCMTokenTask.doInBackground(LoginActivity.java:211)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.lang.Thread.run(Thread.java:818)
04-02 16:59:29.958 29773-29773/purepush.group101.talktoday E/GcmReceiver: Failed to resolve target intent service, skipping classname enforcement
04-02 16:59:29.958 29773-29773/purepush.group101.talktoday E/GcmReceiver: Error while delivering the message: ServiceIntent not found.
I am obtaining GCM token using the following code:
InstanceID instanceID = InstanceID.getInstance(context);`
regToken = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="purepush.group101.talktoday">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="purepush.group101.talktoday.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="purepush.group101.talktoday.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity android:name=".ChatActivity" />
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
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="purepush.group101.talktoday" />
</intent-filter>
</receiver>
<service
android:name=".utils.GCMMessageListener"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>
</manifest>
Build.Gradle (App Module)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "21.1.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId 'purepush.group101.talktoday'
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'org.apache.httpcomponents:httpmime:4.5.2'
compile 'org.apache.httpcomponents:httpclient:4.5.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.android.gms:play-services:8.4.0'
}
Now the funny thing is, this error occurs only on my Nexus 5 running 6.0.1 (Build: MMB29Q). I tested this application on my colleague's Samsung Note 4 running 5.1.1 and I was able to successfully register his device with GCM. I am getting this error with multiple of our applications using GCM only my Nexus 5.
Any help on this would be appreciated
Thanks!
Please check your "Nexus 5" clock, it should be exact, and try to change
buildToolsVersion "21.1.2"
to something like: buildToolsVersion "23.0.2" => i'm using this version and GCM working well with Android 6
Update:
I'm using this Method to register my GCM
public void getRegId() {
new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
}
regid = gcm.register(R.string.gcm_defaultSenderId);
msg = "Device registered, registration ID=" + regid;
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
System.out.println("Error---" + ex.getMessage());
}
return msg;
}
#Override
protected void onPostExecute(String msg) {
System.out.println("Registerid---" + regid);
}
}.execute(null, null, null);
}
please try it and let me know.
Well, it turns out that my Google Play store wasn't working properly. I could view apps and install new ones but when I entered "My apps & games", it gave me the Check your connection and try again error. So, I am posting this solution for anyone who might be having a similar problem since I spend 4-5 days looking for errors and trying different fixes.
Note: This is only for rooted users.
Steps:
Open your FIle Manager. I used ES File Explorer.
Goto "/" or the root of your phone
There will be folder called etc
Inside etc, you'll see a file name hosts
Inside the hosts file, you'll see 2 IP addresses. The second one will vary depending upon your location
Add a # at the start of the 2nd IP Address. # will change that line to a comment
I recommend making a backup of the hosts file before editing.
Credits to "Ronny927": http://forum.xda-developers.com/showthread.php?t=2273994
I have faced the same situation some days ago, it is not the problem of GCM it is the problem of our internet connection. see below points for more understanding
you phone is connected to wifi but there is no internet from wifi, try to google in browser, if it is working perfectly then you should try some more things, like checking play services in your device and many more.
your phone's data pack could have been over , it means that you are connected to internet , but you won't get any kind of data from it. this error can not be identified without checking connection to your server.
You can get additional details from this link
How to fix Google Cloud Messaging Registration error: SERVICE_NOT_AVAILABLE?
Please keep in mind that I have read through the hundreds of similar questions such as this but I've seemed to cross off the check list of everything that has been stated in the instructions on how to get the Google maps to start working.
First things first, I'll show my code, then I'll narrate what has been happening.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="elephant.tuskapp"
android:versionCode="49"
android:versionName="4.6">
<uses-sdk android:minSdkVersion="15"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission android:name="elephant.tuskapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="elephant.tuskapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<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_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<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="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<permission android:name="elephant.tuskapp.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="elephant.tuskapp.permission.C2D_MESSAGE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:name=".NVtuskapplication"
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" />
<activity
android:name=".activity.MainActivity"
android:label="#string/activity_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="elephant.tuskapp.service.AlarmReceiver"></receiver>
<receiver android:name="elephant.tuskapp.service.TimeSynchronizer">
<intent-filter>
<action android:name="android.intent.action.ACTION_TIME_CHANGED"/>
<action android:name="android.intent.action.TIMEZONE_CHANGED"/>
</intent-filter>
</receiver>
<service android:name=".service.GPSService"></service>
<service android:name=".service.RouteUpdateService"></service>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<receiver
android:name=".service.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="elephant.tuskapp"/>
</intent-filter>
</receiver>
<service android:name=".service.GcmIntentService"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="key" />
<!-- google maps api v2-->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="key"/>
</application>
Layout 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"/>
Main Activity
package elephant.tuskapp.activity;
import android.app.Activity;
import android.os.Bundle;
import elephant.tuskapp.R;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.route_details);
}
}
When I run my app, I see a blank canvas with the Google logo on the bottom left corner. The Logcat prints out the following error:
-22 20:47:24.822 22720-22720/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: free.elephant.tuskapp, PID: 22720
java.lang.RuntimeException: Unable to start activity ComponentInfo{free.elephant.tuskapp/elephant.tuskapp.activity.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2301)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
at android.app.ActivityThread.access$800(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5232)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:767)
at android.view.LayoutInflater.inflate(LayoutInflater.java:486)
at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2161)
at elephant.tuskapp.activity.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2254)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
at android.app.ActivityThread.access$800(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5232)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
at com.google.maps.api.android.lib6.d.fk.a(Unknown Source)
at com.google.maps.api.android.lib6.a.g.a(Unknown Source)
at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
at com.google.android.gms.maps.internal.i.onTransact(SourceFile:62)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.zzc$zza$zza.zzr(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zzvu(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2117)
at android.app.Activity.onCreateView(Activity.java:5333)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:737)
at android.view.LayoutInflater.inflate(LayoutInflater.java:486)
at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2161)
at elephant.tuskapp.activity.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2254)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
at android.app.ActivityThread.access$800(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5232)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Familiar right? You see it in a lot of other questions. I think what differentiates my question from the others is I may have a problem with different flavors of my app.
To cross out the mistakes others have encountered, I have done the following:
- Made sure my api keys are inside the tag of the manifest file.
- Ensured that the Google Maps API v2 for Android is enabled on Google Consoles
- I'm using the Google Play Services via Gradle (Scroll down for my gradle snippet)
- I made sure all of the essential permissions are set
- I made sure to enable the glEsVersion.
What I think the problem is?
I think I'm having a problem with my "free.elephant.tuskapp" flavor to authenticate with googles servers. In my gradle build, I maintain two different flavors of my application and I seem to be getting an error with authentication:
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: myAPIKEY
Android Application (<cert_fingerprint>;<package_name>): SHA-1;free.elephant.tuskapp
I obtained my API by using the 'elephant.tuskapp' package name rather than the 'free.elephant.tuskapp'
Here's my gradle build if it's of any help:
Gradle
buildscript {
repositories {
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven {
url 'https://maven.fabric.io/public'
}
}
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
defaultConfig {
applicationId "elephant.tuskapp"
minSdkVersion 15
targetSdkVersion 15
}
productFlavors {
demo {
applicationId "demo.elephant.tuskapp"
}
free {
applicationId "free.elephant.tuskapp"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.google.zxing:core:3.2.0'
compile('com.crashlytics.sdk.android:crashlytics:2.3.2#aar') {
transitive = true;
}
}
Am I missing out on something? Or does it really have something to do with my flavor builds? If it's the flavors causing trouble, how am I supposed to handle this? I generated new api keys for all my flavors but I don't see how I'm supposed to make that work within the manifest file as well as having it look elegant.
According to your logcat, it says something wrong with your Map fragment layout. Also, I find that there is nothing in your MainActivity, I think you should initial map there. For more details, you can refer code here.
Sample code:
public class MainActivity extends FragmentActivity {
GoogleMap mGoogleMap;
private static LatLng MountainView = new LatLng(37.42, -122.08);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initial Map
try {
if (mGoogleMap == null) {
mGoogleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
} catch (Exception e) {
e.printStackTrace();
}
mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true);
mGoogleMap.getUiSettings().setZoomControlsEnabled(true);
mGoogleMap.getUiSettings().setZoomGesturesEnabled(true);
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MountainView, 15));
Marker marker = mGoogleMap.addMarker(new MarkerOptions()
.position(MountainView)
.title("Have a nice day!"));
}
}
Since my app has multiple flavors, I was getting thrown an error that my api-keys were not being validated. The way to resolve this is to ensure that you add all packages of your project into the Google Developer Console.
SHA1;packagename
Then press enter
SHA1;packagename2(flavor)
In my case it was:
SHA1;elephant.tuskapp
SHA1;free.elephant.tuskapp
SHA1;demo.elephant.tuskapp
I'm creating sample application to use Google Maps Android API v2.
I tried on Samsung Galaxy Ace GT-S5830i, but instead of Map, I'm seeing
And logcat is
Signature not valid. Found:
MIIDDTCCAfWgAwIBAgIEEhX+gTANBgkqhkiG9w0BAQsFADA3MQswCQYDVQQGEwJVUzEQMA4GA1UE
ChMHQW5kcm9pZDEWMBQGA1UEAxMNQW5kcm9pZCBEZWJ1ZzAeFw0xMzAyMjUxMTEwNDRaFw00MzAy
MTgxMTEwNDRaMDcxCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdBbmRyb2lkMRYwFAYDVQQDEw1BbmRy
b2lkIERlYnVnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApqChoDnHsDfsxa7n2Kv9
2av0G0tm+kS1uP4T6fA8cO6jB3qB5EHFR6+5UO+k4laHW2WzOJbyhhtFE5eOTS4Zt5qo4FX/hsc/
Zi7dDX/Y13b+4qajhLoGYqVjM00eQc2qF58TTnbQ3lTERxaofYL2qI3j2KcVODFMksinL9lt3RTD
V3MXy7KDLcuSvoVZxXn1L0O9rkTbZicmleK4wLDzI+lTpuXngAuQ4MBH1wEWwqMhJg6/J06t5axU
ea2UVv7ZtYg8KPMEiQEApCbdAHtQsmqcsEQZtJAqFtj7KEQ7wTSgnpDRix4N5C9QlwUtKSlOCIlk
ueUPVBypKf/SWIgF6QIDAQABoyEwHzAdBgNVHQ4EFgQURyMuspjlLaDj8LhEb5UyYqQgWQYwDQYJ
KoZIhvcNAQELBQADggEBAA9IXLEAQTD+VEt9l8JQDEOFv8WqIdQisvmJCfJjN98faarvf6RRA+v3
HF2VFlZPaUu/HBeOH8MI7u+gNuRtZGYWn1eC/qfP0W31MQoNaN4ocsF+tL9INzpd89/u6Ya5Kove
r0E0tpJFBgdtDPYcPBjQ6tYAqmhnmPIJftGHLNQbil4ocK/PkqgxGlwQN7WrCNjDewb0twz7hZBx
Ig4OsnfdgPTYGlR+LyTzUd9/KyqaLHivRAI+y/xGDz6lOfGH7bDOPi/hDm0bkhC1y1J7L9+FiGWb
dmi+Co9Jlf1f3vyTtD7kr3h0K0C3MsNWtybVqmVvgImoLt/lPbjNJahVrds=
Google Play services signature invalid.
Can't open keycharmap file
Error loading keycharmap file
Using default keymap
My manifest code
<?xml version="1.0" encoding="utf-8"?>
<permission
android:name="com.example.testmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.testmap.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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" />
<permission
android:name="com.example.testmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<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="AIzaSyDTsWrO0j24sbp4E5qhoHhd6nyOQM5lErc" />
<activity
android:name="com.example.testmap.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>
my xml file code
<?xml version="1.0" encoding="utf-8"?>
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
My activity code
package com.example.testmap;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.final_main);
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//map.getMinZoomLevel();
}
}
And clicking on ok button gives force close with Logcat
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
at android.app.Activity.startActivityForResult(Activity.java:2827)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
at android.app.Activity.startActivity(Activity.java:2933)
at com.google.android.gms.internal.e$2.onClick(Unknown Source)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Also when I UN-comment last line map.getMinZoomLevel(); , I get null pointer exception on the line.
Check if you have enabled offline work for gradle: Goto File > Settings > Gradle
Deselect Offline Work if its checked.
Then confirm if you have latest version of google services mentioned as dependencies in project level build.gradle:
classpath 'com.google.gms:google-services:2.1.0'
You can find latest version here: https://jcenter.bintray.com/com/android/tools/build/gradle/
Clean and build the project after gradle sync completes.
ouThese steps solved a similar issue I'd with Google Maps and also solved the first error you mentioned Signature Not Valid
If your device runs on Android M, you may want to verify your code for location access following this answer.
I was also getting same exception and I fixed it.
Note: I am working on google analytics and was getting this exception. But my app was not crashing I was getting this in Logs. you can also try this solution.
add this in project level gradle file.
classpath 'com.google.gms:google-services:2.1.0'
and this one for module level gradle file.
compile 'com.google.android.gms:play-services:8.4.0'
and move `below plugin at the end of file (at last line) of module level gradle file.
apply plugin: 'com.google.gms.google-services'