Skip to main content

Posts

Showing posts with the label java

Screen capture and save to SDCard in Blackberry Java (OS4.3 and above)

Blackberry OS (4.3 and above) provides a very easy way to capture screen of device. We can use screenshot(Bitmap bmp) method of Display class. In this post you will see how to capture screen contents and save to a file on SDCard. First we will get width and height of screen. This is very important because Bitmap we pass to screenshot method must have same width and height as of screen. int screenWidth=Display.getWidth(); int screenHeight=Display.getHeight(); Next, create a Bitmap object of dimensions equivalent to width and height of screen. Bitmap bmpScreen=new Bitmap(screenWidth,screenHeight); Take screenshot using screenshot method of Display class Dispaly.screenshot(bmpScreen); Now bmpScreen contains our screen image data. Our next task is to save this data in a file on SDCard. Let's create PNGEncodedImage from this Bitmap. PNGEncodedImage imgToSave=PNGEncodedImage.encode(bmpScreen); Open a file to write this image FileConnection fc=(FileConnection)Connector...

How to change JVM for Eclipse

I have following JDKs installed 1) JDK7 64 bit 2) JDK6 64 bit 3) JDK6 32 bit Also I have multiple Eclipse installed. They run on different JVM. For example Eclipse for Blackberry runs on 32 bit JDK and Eclipse for Android runs on 64 bit JDK. You can put only one JDK to PATH in Environment variable or JAVA_HOME environment variable. To configure Eclipse to use specific JVM you have to modify configuration file for your eclipse (usually eclipse.ini). Add following lines just before the line which says “-vmargs”. -vm D:\TOOLS\Java\JDK6-32bit\bin\javaw.exe {this should be the path to your desired JDK bin\javaw.exe }

Cannot find RIMIDEWin32Util.dll in Eclipse for Blackberry development

I switched to Windows 7 64 bit few months back and I upgraded all my tools/SDKs to 64 bit versions including JDK. Suddenly after I updated JDK to 64bit my Eclipse plugin that I use to develop Blackberry applications started giving this error on every start Cannot find RIMIDEWin32Util.dll. This is a required component of the IDE.  Solution to this problem is that install both JDK and Eclipse 32bit versions. And set the following environment variables in Windows JAVAHOME=path to the folder where JDK(32bit) is installed PATH=add path to bin folder of your JDK(32bit)

HTTP POST request in Java

In one blog post I wrote about how we can make HTTP requests and receive response in Java. That post was only about sending GET request. This time we will learn how to make POST (submitting form etc) request in Java.  This post assumes that you are familiar with  HttpURLConnection  found in  java.net  package. If you are not please read this blog post http://random-stuff-mine.blogspot.com/2013/06/http-request-and-response-java.html HTTP POST request Lets say you entered username/password in a website and pressed "Login" button. Most probably the web browser makes a HTTP POST request containing your username/password. A simple POST request would look like this POST /path/to/script HTTP/1.1 User-Agent: RemzyHttpBot Content-Type: application/x-www-form-urlencoded Content-Length: 32   username=rameez&password=test In the above request you see that username and password are sent inside the request body and content-type of request is set to appl...

Java SDK not found under Android's SDK Locations settings in Xamarin

To work with Android under Xamarin you have to set up Android SDK and JDK path under Tools->Options->Projects->SDK Locations->Android I faced a problem after setting all SDK locations it says "SDK not found" for JDK despite giving the correct path for JDK installed on my system. After few hit and trials I figured out that the problem is 64-bit version of JDK installed . Xamarin works with 32 bit JDK. So I downloaded the 32-bit version of JDK from http://download.xamarin.com/Installer/MonoForAndroid/jdk-6u39-windows-i586.exe After installing this JDK I set up the options for SDK locations and now Xamarin works fine.

HTTP requests and response in Java

Java has excellent support of HTTP client side. In this blog post we will have a look at how to make HTTP request in Java and download the response , saving it in a buffer. Java implements a simple HTTP client in a class java.net.HttpURLConnection . So our first step is to make an instance of java.net.HttpURLConnection. To do this we need java.net.URL class. We will use its constructor which takes url in a form of string as a parameter and then call its openConnection method casting the returned object to HttpURLConnection. Here is how it is done String strUrl="http://google.com"; URL url=new URL(strUrl); HttpURLConnection httpConn=(HttpURLConnection)url.openConnection(); We now have HttpURLConnection object to use. Please note right now no request has been sent to the server (in our case google.com). To complete the process of sending actual request and start getting response we have to use getInputStream  method of HttpURLConnection class. Actually getInputStr...

Blackberry round corner TextField with place holder text

While working on a blackberry project I was required to display a round corner text field with a place holder text. The logic was to display place holder text when TextField is not in focus and no text is entered by user (or text is cleared by user). As soon as TextField receives focus, placeholder text should be removed. Displaying place holder text when TextField is empty is very easy . You can just override TextField's  paint method and check if text is empty you can set text to place holder text. Here is a simple example protected void paint(Graphics g){     if (getText().compareTo("")==0){         setText( "Place holder text.." );     }     super.paint(g); } But displaying and removing of placeholder text on focus and unfocus was a bit of task so I came up with my own class and want to share with other fellow coders. import net.rim.device.api.ui.Color; import net.rim.device.api.ui.Graphics; import net.rim.device...