Posts

Native Methods and Libraries - Java

What are Native Methods and Libraries? Native methods  and  native libraries  are bits of platform-specific executable code (written in languages such as C or C++) contained in libraries or DLLs. Inside your Java applications you can gain access to the functions inside those libraries, allowing you to create a sort of hybrid Java and native code application. Although using native methods can give you some extra benefits Java does not provide (such as faster execution or access to a large body of existing code), there are significant disadvantages in using native methods as well. Why Use Native Methods? Gaining access to special capabilities of your computer or operating system Needing the extra speed that native methods provide Needing access to a large body of existing code Disadvantages of Native Methods With a hybrid Java and native method program, however, you've given up that cross-platform capability. First of all, Java programs that use native methods cannot...

Android Cloud to Device Messaging(C2DM):Project

Image
Android Push application is an Android Application which is registers to the C2DM Server.It allows user to send and store contact,message,images,maps from the Server to your Device. It uses a features Cloud to Device Messaging to deliver messages that actually pushes the messages to your device, therefore it saves much more battery and best of all,there is nothing you need to do to enable it. The entire project(Android Cloud to Device Messaging) is mainly divided into three parts i,e the primary processes involves in this project are      -Android Push Application      - Cloud to Device Messaging framework.      - Android Push server thats sends message via C2DM Server. Overview of LifeCycle: Check following URL too to know more about C2DM,Authorization Token And Third Party Application Server. Android cloud to Device Messaging:Tutorial Client Login AuthToken Third Party Application Server Some Screenshot: Se...

Android Code Style

Android follow standard Java coding conventions. We add a few rules: Exceptions: Never catch and ignore them without explanation. Exceptions: do not catch generic Exception, except in library code at the root of the stack. Finalizers: generally don't use them. Imports: Fully qualify imports. 1.Exceptions: do not ignore: Never do this.Never wr ite code that completely ignores an exception like this : void setServerPort(String value) { try { serverPort = Integer.parseInt(value); } catch (NumberFormatException e) { } } Always: Throw the exception up to the caller of your method. void setServerPort(String value) throws NumberFormatException {     serverPort = Integer.parseInt(value);  } Throw a new exception that's appropriate to your level of abstraction. void setServerPort(String value) throws ConfigurationException { try { serverPort = Integer.parseInt(value); } catch (NumberFormatException e) { throw new Configura...

Android Progress Dialog Example

Image
In situations when you need to wait some operation it is good practice to notify user that operation is in progress.For this cases in Android present several classes which can help with this. One of them I am going to demonstrate. In this tutorial, I will show you how to add a progress dialog to your Android application. A dialog is usually a small window or tab that appears before any activity in your application. It is intended to display alerts or information to the user. A progress dialog can be used to either show some processing activity to the user or to show the progress of some custom activity using the progress bar. To create a Progress Dialog, we can make use of the ProgressDialog class which is an extension of the AlertDialog class. It can be used to display a standard progress dialog with a spinning wheel and some custom text. You can display your Progress Dialog using a simple show () call on your dialog object. Here's the syntax to create a standard Progress dial...

Error: Unable to open class file R.java and How to fix it.

[2011-05-27 12:12:39 - listActivity] ERROR: Unable to open class file /root/workspace/Manifest.java: No such file or directory [2011-05-27 13:50:38 - listActivity] ERROR: Unable to open class file /root/workspace//R.java: No such file or directory R.java and Manifest.java is a automatically generated file. The ADT has a few such annoying bugs. But you can sort them out.. What usually helps is: 1. Close Project->Open Project > Build Automatically . 2.Another thing that sometimes helps is right click project > android tools > fix project properties and remove unnecessary content or jar files. 3.Or you can do Project->clean and Refresh . If still it not generating R.java files then check your class there must be a extra line.. Import R.java.*; Remove that and then do all the above one by one.. Hope it help .. If someone know other way please let me know. T...

Conversion to Dalvik format failed with error 1

Sometime You will encounter this problem when trying to Build Android Project on Eclipse..  You will get such output in console: [2011-05-24 09:25:03 - Android C2DM] Dx 1 error; aborting [2011-05-24 09:25:03 - Android C2DM] Conversion to Dalvik format failed with error 1 You can solve this problem: Go to Project » Properties » Java Build Path » Libraries and remove all except the "Android X.Y" (in my case Android 2.2). click OK.  and then Go to Project » Clean » Clean projects selected below » select your project and click OK.   That work for me. Hope it works for you too.!!!!

Third Party Applcation Server

Image
The Third Party Server is *your* server and can actually be any process written in any language (for example, it can be a batch process or a cron script). The role of the 3rd party "server" is to send the message to the device. The Server will store (or update) the registrationID received into its local database. So, eventually the server will have registrationIDs from the devices. Your server needs to get a ClientLogin Auth token in order to talk to the C2DM servers. When it wants to push a message to the device. For ClientLogin Auth_Token:  Click Here To send a message to a particular device, the Server needs to POST to the C2DM Service the following 4 things:  The accountName which will be arxxus.pushapp@gmail.com . An authentication Token. The registrationID of the device it wants to send the message.  The message itself (Message limit 1024 Bytes) Code: // Create a new HttpClient and Post Header  HttpClient httpclient = new DefaultHttpClient()...