Thursday, 5 April 2018

>Please fix the version conflict either by updating the version of the google-services plugins (information about the latest version is available at http://bintray.com/android/android-tools//com.google.gms.google-services/) or updating the version of com.google.android.gms to 12.0.1



This problem occurs when google play services  and its dependencies have different versions, however google play services require its all dependencies of same version.

So, to fix this -

Open build.gradle (Module: app) and go into dependencies section and check all dependencies that starts like com.google.xxx:zyx-zbc:12.0.x;. Now change its version to the version of google play service (generally it is last one).



Now sync the gradle.

Monday, 2 April 2018

How to generate Google Map API key for any Android Project ?

Google map API key is necessary to add Google map to your any application. So, why we require this key ?

This API key is required because you have to access the Google map server. You can restrict this key only for Android app. This is free and any numbers of user can use it.

Let see how you can generate Google map API key for your Android project.

Start a new project in Android Studio and select Google Map Activity. When project open in Android Studio it open on google_maps_api.xml file by default.


You can see the instruction to generate the API key as well as the link (Third line of comment) to generate that API key. Just copy this link and paste it on any browser.


It will ask your gmail username and password, just put your email and password to login into your gmail account.


Now register your project for Google Map API in Google API Console by clicking Continue.


 It will take some time to enable API, just wait for it.


After API is enabled, click on Create API Key .


It will also take some time to create API key, just wait for it.


Now your API key is ready to use just copy it and use it in your app.



You should paste this API key in your file google_maps_api.xml  of your Android app.



Error :- Google Map fragment/activity is blanked with Google logo and update google play services in Android Studio.

When we develop Google Map fragment in Android Studio, it shows only blank map with Google logo. We stuck here, why it is so ? However we have done everything fine.


 Before this we also find that we don't have updated Google Play Services as message shown by emulator like -


So, how this can be resolved ?

Let see, how these Google Map related problems can be resolved ?

First See how to update Google Play Services.

Go to -

Tools ----> Android ------> SDK Manager 

A dialogue window will appear. Click on SDK Tools  tab. Find the Google Play Services. You will see that it is unchecked and status is Not installed.


Check Google Pay Services then click Apply. A confirmation box will appear Click on Ok.
Download will be started if you are connected to the Internet. After download done click on Finish.









Now your Google Play Services is updated. And you can run your map fragment now.

After updating Google Play Services, if you again can not see the map or you only see the blank map with Google logo like screen shot given above then-

We know that for developing map activity in Android Studio, we require Google Map API key generated form google API console. If you using key that is not generated from developer machine, it show blank map. So make sure that you should generate API key from the machine from where you are developing the map activity.

How to generate Google Map API key ?

Monday, 19 March 2018

Androis Studio errors and solutions


Here are some list of Android Studio errors, I faced when trying to use Android Studio. This is not limited only to the listed below, it will be growing, when I get new one.
  1. Emulator: [1116]:ERROR:android/android-emu/android/qt/qt_setup.cpp:28:Qt library not found at C:\Users\user1\AppData\Local\Android\Sdk\emulator\lib64\qt\lib
  2. > Manifest merger failed: uses-sdkminSdkVersion 9 cannot be smaller than version 14 declared in library [com.android.support.apcompat-v7:26.0.0-alpha1]  Android Studio
  3. Error Loading Project: Cannot load 3 facets Details... Android Studio.
  4. Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
  5. Google Map fragment is blanked with Google logo and update google play services. 
  6. >Please fix the version conflict either by updating the version of the google-services plugins (information about the latest version is available at http://bintray.com/android/android-tools//com.google.gms.google-services/) or updating the version of com.google.android.gms to 12.0.1
  7. Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. 
  8. Emulator: emulator: ERROR: x86 emulation currently require hardware acceleration!
  9. Error: Cannot fit requested classes in a single dex file (# methods: 87573 > 65536)
  10. KVM is required to run this AVD. /dev/kvm/ device:permission denied. Grant current user  access to /dvm/kvm

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.

This kind of error is Gradle related error. If there is a problem in Gradle or it is working in offline mode, you get error like -


To resolve this kind of error either update your Gradle or put your Gradle in online mode.

To do so, go to -

File ----> Settings ------> Build,Execution, Deployment ------> Gradle ------> and uncheck the Offline mode

Note :- make sure you are connected to internet, because it is updated from there.


Then click Apply and Ok and wait till Gradle is being updated.



Monday, 5 March 2018

Emulator: [1116]:ERROR:android/android-emu/android/qt/qt_setup.cpp:28:Qt library not found at C:\Users\user1\AppData\Local\Android\Sdk\emulator\lib64\qt\lib

As a beginner of using Android Studio, it is very hard to rectify the Android Studio error. As I also a beginner of Android Studio and what I face during my experience, I just share it through my blog. Here I am sharing my experience regarding emulator error. See the error in screen shot -



So, why this problem occurs ? Answer is that, your SDK does not have emulator or partially installed.
To install emulator go to -

Tools -----> SDK Manager -------> Android SDK

 and tick the Android Emulator then Apply and Ok

Note :- make sure that you are connected to Internet.


Confirm it by clicking OK.


Then it will download the emulator from Google Android.



Click Finish.

Restart Android Studio.





Tuesday, 20 February 2018

Android Database Connectivity with Firebase

Firebase is a mobile platform that helps you quickly develop high-quality apps. Firebase is made up of complementary features that you can mix-and-match to fit your needs including database, with Google Analytics for Firebase at the core. 

In this post, I will demonstrate that how to connect you android app to Firebase Database. I also assume that you have enough working knowledge of Android and Android Studio.

Prerequisites-

  • Latest Android Studio
  • Android Services plugins should be installed in IDE
  • Gmail account
Start a project in Android Studio. (I have used 3.0.1) .

Now Go to Firebase Console and log in using your gmail id and password and click on Add Project.


Then give a name of your package and your country here and then Continue.

After clicking on Continue, You will be on Firebase Console. Then select here "Add Firesbase to your Android app" in the centre of page.


A window (Add Firebase to your project) will appear. Here is 3 step process.

1. Register App -

Input package name (e.g com.example.arvindsbi.sbischooldevices;) whatever you have created in Android Studio and then click on Register App.



2. Download config file -

Here you will have to download google-services.jason file on your system and click Continue. After downloading, paste this file into your app root directory. (Hero you will find instructions to use it)


3. Add Firebase SDK -

After downloading and configuring jason file, you will have make some changes in your gradle file. You will have to add some dependencies in your app level and project level build.gradle file (as instructed by Firebase).



 

Now in app level build.gradle file, add the following line in dependencies -
compile com.google.firebase:firebase-core:11.8.0'
Sometimes this line also required
compile 'com.firebase:firebase-client-android:2.5.0' 


Now in project level build.gradle file, add the foolowing dependencies -
classpath 'com.google.gms:google-services:3.2.0'
After updating your both gradle file click on sync now.
After doing all these things your app is now prepared for connectivity with Firebase database.
Now you require Java code and xml code to make connectivity.
Important- It should be assured that Android Support should be installed in Android Studio.
To check or install Android Support Go to 

Tools ===>> Android ===>> SDK Manager   then select Plugins in left pane and then tick Android 
Support in center pane if not cheked


Here is the full code of both files -
Xml code -
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.arvindsbi.sbischooldevices.FirebaseDemo"> <EditText android:id="@+id/myname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginEnd="72dp" android:layout_marginRight="72dp" android:layout_marginTop="64dp" android:ems="10" android:inputType="textPersonName" android:hint="Name" tools:layout_editor_absoluteX="84dp" tools:layout_editor_absoluteY="44dp" /> <EditText android:id="@+id/myage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/myname" android:layout_alignStart="@+id/myname" android:layout_below="@+id/myname" android:layout_marginTop="43dp" android:ems="10" android:hint="Age" android:inputType="textPersonName" /> <Button android:id="@+id/button13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/myage" android:layout_alignStart="@+id/myage" android:layout_below="@+id/myage" android:layout_marginLeft="36dp" android:layout_marginStart="36dp" android:layout_marginTop="58dp" android:text="Add to Firebase" /> </RelativeLayout>
In Java file you required -
1. import com.firebase.client.Firebase;
2. Then declare Firbase class
public Firebase fb;
3. In onCreate method initialise the Firebase and connect using URL
Firebase.setAndroidContext(this);
fb=new Firebase("https://sbxxxxx-fxxxx.firebaseio.com/");
4. In onClick method
Firebase nameChild=fb.child("Name");
nameChild.setValue(myname.getText()+"");
Firebase ageChild=fb.child("Age");
ageChild.setValue(myage.getText()+"");
Here is full Java code -
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.firebase.client.Firebase;

public class FirebaseDemo extends AppCompatActivity {
public EditText myname,myage;
private Button mybutton;
public Firebase fb;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_firebase_demo);

        Firebase.setAndroidContext(this);

        fb=new Firebase("https://sbixxxxxl-fxxxx.firebaseio.com/");

        mybutton=(Button)findViewById(R.id.button13);
        myname=(EditText) findViewById(R.id.myname);
        myage=(EditText) findViewById(R.id.myage);
        mybutton.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                Firebase nameChild=fb.child("Name");
                nameChild.setValue(myname.getText()+"");
                Firebase ageChild=fb.child("Age");
                ageChild.setValue(myage.getText()+"");
                Toast.makeText(getBaseContext(),"Details Added",
                Toast.LENGTH_SHORT).show();
            }
        });
    }
}
After doing all these things don't forget to give internet permission to AndroidManifest.xml file
<uses-permission android:name="android.permission.INTERNET"/>



Now run your app enter data -



Go to  Firebase database and see your entered data -

(Note:- Sometime you can not see your data in Google Chrome, means it will show blank, if so then change your browser to Mozilla Firefox or Internet Explorer and loging to see your data. I don't why it is so? But I have faced this and resolved like this. )


Quick Look up -

  1. Firebase account login
  2. Add project
  3. Add your project package
  4. Download config file
  5. Paste this file in your app root directory
  6. Change in both app level and project level build.gradle file
  7. Check android support plugins
  8. Write code in your project
  9. Give internet permission to your project
  10. Run project
  11. See the data in Firebase


Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...