Skip to main content

Posts

Showing posts from 2013

Introduction and Example of Eventbus in Android.

EventBus is a library of Greenbot . This is very simple for all users how to implement and its basic use. Here I will also share examples for better understanding. What is EventBus? EventBus is subscribed/publish event bus to communication between components with limited lines of code, in short, its bus for events transfers the data between one activity(class) to another to reflect the changes based on our needs. That makes the data exchange between components like Activity, Fragment, Services, and any kind of backgrounds threads pretty easy. EventBus can handle the threading for us: events can be posted in threads different from the posting thread. Common use can be dealing with UI changes. In Android, UI changes must be done in the Main(UI) thread. In other words, networking or more time-consuming task cannot be handled in the Main thread, for that we must use AsyncTask or Handler to make it more smooth. Now we have one more options use EventBus to change the UI po

RoboGuice Example in Android

This library having good implementation for Android developer who don't won't spoil time written for initialize the Components, Resources, and so on. As I know those who want only like to written minimum code and output will be more. So use this library. Guide means make development and debugging the code very easy and faster. With the help of RoboGuice library you should be able to understand your code very speedily with minimum time. What is RoboGuice? RoboGuice is a dependency injection framework for Android applications. RoboGuice is a framework that brings the simplicity and ease of Dependency Injection to Android. RoboGuice 2 takes the guesswork out of development.Using RoboGuice, you can inject your View, Resource, System Service, or any other object.To express a dependency, you use annotations like Inject. Usage of RoboGuice library: Views Injection: To initialize views - use @InjectViews, for example: @InjectView(R.id.txtName) TextView txtName; Resou

Android Volley Network Library

Volley - HTTP Library for Android In every project we most of use Network related task and pull JSON data or sent JSON data to the server. Same way we fetch images or thumbnails over the HTTP protocol API. So here, same thing happen with Volley Library. So let's see what is volley library and what's advantages to use in our project. What is Volley Library? Volley is a library that makes networking for Android application easier and most importantly, very faster and work smoothly. It can manage the processing and caching of network requests and it saves our valuable time compare to other network library that included in by default. But using this library you can achieve fast and rapid application development when you want to use network related task. Features: Volley automatically schedule all network requests. It means that Volley will be taking care of all the network requests your app executes for fetching response or image from web. It provides memory caching.

Display Toast in different style : Crouton

I know most of people uses Toast when displaying message i.e. Warning, Error, Confirmation, and so on. But today we show the toast in different way. And this toast already have been seen by you in Facebook Android application. Its display when network is not reachable. So now we move to our main point. How to generate that kind of toast with custom style. Here I attached screen shots so you can check it and help from it. [Crouton - Alert Message] [Crouton - Confirm Message] [Crouton - Custom View Message] [Crouton - Custom View Message at specific place] You can download full source code from here. CroutonAndroidApplication If you are satisfied then please give your comments. Thanks for your Interest!!!

Google Maps API v2 using Android

We know how to add Maps in Android Project. But here I would like to share Map Integration (Google Map API V2). Google has deprecated the Google Map API v1. From now we use Map API v2. For more details you can check developers document. https://developers.google.com/maps/documentation/android/ Why Google Map API v2? The new Google Maps Android API v2 allows you to offer interactive, feature-rich maps to users of your Android application. Some features are: * Caching part is improved * Maps are now turn into 3D * Faster, smoother and use less bandwidth Google Play Service : Library As per new Google Map API v2 we need to add google_play_service_lib for reference to our project. You can found that library from this location. android-sdk\extras\google\google_play_services\libproject\google-play-services_lib Here I display screen shots in step by step to how to follow it. [Configure Android Key for Google Map v2] [Android API Key for Google Map v2]

DatabaseLocked Exception in SQLite : Android

Many time we face this error due to multiple times we access the tables (Same table or may be different table). Although I understand the which problem occur during this single database accessing multiple tables same time. I face this kind of problem many times. Means when I was inserting some value to local database at that same time I was fetching some value to send data on server in background. This problem arise occasionally when we use AsyncTasks or else with thread, because of database - access the tables and its data in a fraction of second. Database trying to access the tables and same time user hit second request so database again access to other table. So this issue was arise. But, here I try to overcome this problem using synchronized the accessing database. Let me give you one be one steps with description. SQLDataSQLHelper.java     This getInstance method will call only when mInstance is null. So its called only once when we start our application. After

Passing ArrayList from one activity to other

We all know how to pass String, boolean, objects from one activity to another but if we want to pass ArrayList then? So here I am giving you small example which help you to pass ArrayList from one activity to another. 1. Books.java First, we write one class(Model), lets take example for Book for library project. 2. BookList.java Create another class with inherits from ArrayList of Books model and implements the interface Parcelable. There are basically two methods. One that writes the content into ArrayList and another that retrieves the content in form of ArrayList. 3. CallerActivity.java MainActivity(CallerActivity) that pass content as a ArrayList to another activity(CalledActivity). 4. CalledActivity.java This activity receives the content as a ArrayList which was pass from CallerActivity. Hope this will help you. If you are satisfied then please give your comments. Thanks for your Interest!!!

Part - 2: Webservice running in Android with Database

If you do not completed simple example for how to call soap service from android then please look at my Part - 1 : Calling Web Service from Android After successfully understand the basic info from Part - 1, we moved to another advance example with database connectivity. Our android application connected with database, return value and display in our Android device. Here, I am using Microsoft SQL Server Database connectivity, you can use your preferred database. Before start the our implementation we first download the required library files for our use. 1. SQL Connectivity jar file for Webservice : http://www.4shared.com/file/IxoPooiE/sqljdbc.html 2. Ksoap Library file for Android : http://www.4shared.com/file/uOhx5aoj/ksoap2-android-assembly-24-jar.html Dynamic Web Project First we create webservice project. In that project we are connecting SQL database and write connection between them to retrieve the books data. Once its completed then move to Andro

Part - 1 : Calling Web Service from Android

I was running Web Service successfully in Year-2010 and already post into many forums. But some of forum/sites had removed that post So I thought to post once again for those who still facing problem. First I am giving simple code that will help you. First create Dynamic Web project using Eclipse IDE. and create one class : Converter.java This class place under this package:  org.web.prashant.adesara now select Converter.java file and do right click and New--> Other--> Web Services--> and select Web Service There are two option 1. Web Service Type 2. Client Type in first point you have to select slider as a Start Service: and in second point you have to select slider as a Test Client and click on Finish button. You web Service will run automatically. Just check your webservice will work properly or not. Main Steps: Now most important thing is you have to download ksoap2 jar file Now Create Android Project and copy paste this code

Auto Turn Off/On GPS in Android

I was doing search from the net. There are multiple scenario to make application feature to enable/disable the GPS through Programming. If we want to track our children status where he/she going from School/college to any other place. So at that we can start GPS without notify them. Second scenario may be happen when our device is stolen or lost at any place and someone open our application or restart the device so automatic start our application and send data to our server. That also be happen. But this is not fully reliable that we get back our device. At lease we know the location where our device is Below code is used for enable/disable the GPS using Android by Programming. 1. Forcefully Enable the GPS if its disable 2. Forcefully Disable the GPS if its Enable [Auto Enable/Disable GPS Programmatically] If you are satisfied then please give your comments. Thanks for your Interest!!!

Get the Current Latitude Longitude using GPS

As per new Google Map API. They have changed in MAP integration as well as Update the Google Play Service to fetch Current latitude and longitude using GPS/Wi-fi. The location APIs make it easy for you to build location-aware applications. For that first you need to setup the Google Play Service through your SDK Setup Google Play Services SDK A compatible Android device that runs Android 2.2 or higher and includes Google Play Store. The Android emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or higher. Install the Google Play Services SDK Launch the SDK Manager.  Install the Google Play services SDK. ( <android-sdk>/extras/google/google_play_services/ .) Install a compatible version of the Google APIs platform. Make a copy of the Google Play services library project. (Copy the library project at <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/)   [Get Latitu

Disable Force Stop in Android

I have worked since 1 week on how to disable the FORCE STOP button in Manage Application in Android. And I was able to disable the Force Stop and Uninstall button in Manage Application. For that you need to make your application as Device Administrator. Android has add this kind of feature from Android 2.2 version. This feature is for Security reason with different option. Set Minimum Password Strength, Data Wipe, Force Lock,  Reset Password and so on. We set our application as Device Administrator to change above features. For more info and advance example you can check your android-sdk path (>= android-8). \samples\android-[>=8]\ApiDemos\src\com\example\android\apis\app\DeviceAdminSample.java See the below screen shots which shows how to activate the application and disable force stop button. [Active device adminstrator] [Disable the Force Stop and Uninstall button] Follow the below steps to disable the FORCE STOP button. 1. Create one cl

Find Unused Resource From Android

Find Unused resource from Android Application: Today I am going to share one tool which help you to remove Unused Resources from the Android Application. I hope you guys like this. We all know that once we start our development, at starting stage we enthusiasm about our logic and codes and we always try to make proper code with good arrangement. But when day passed away we adding so many new things which may be unused or else we never used that because its for our demo purpose only. That tools is created by other person but I am just share that things with you guys. And I am giving full credit to that person who developed this tool. Really it help a lot while we developed the application. Resource means images (drawable), text (string.xml, style.xml), id (used by layouts) etc... Android Unused Resources is a Java application that will scan your project for unused resources. Unused resources needlessly take up space, increase the build time, and clutter the IDE's

Android Client Connected with Socket Server

I hope this will help you for how to start communication between Socket Server (Desktop Chat Server Application) and Mobile Application (Android Socket Client). This application simply look like as chat application. You can add your idea and innovation to make very useful application. Follow below steps to run application: Use custom port and define same port in both application (i.e. Port No: 5657 ) Define computer IP Address in Android Client Application. (i.e. 192.168.1.x) . If you want to run this application in real device, then you can't connect with Desktop Socket Server. For that you need to upload runnable jar file in specific server and then you can use that server IP Address. First start Socket Server Application using Start button. Now you can start Android application. Just Enjoy it !!! Here I give you screen shot for communication between both application. [Socket Server (Desktop Application)] [Socket Client (Android Application)]

Custom Listview with itemadapter in Android

Today we learn how can we create custom Listview in Android Application. I'll give you full example with source. Please let me know if you have any concern in this example. First of all define how many files required for it. lstview_itemrow_load.xml (For custom rows of listview) activity_main.xml ItemAdapter.java MainActivity.java ItemsDTO.java [Custom Listview] You can download code from here. Custom List View in Android MainActivity.java ItemsDTO.java ItemAdapter.java activity_main.xml lstview_itemrow_load.xml If you are satisfied then please give your comments. Thanks for your Interest!!!