Wednesday 8 February 2012

How to form the json string in android or java?


import org.json.JSONObject;

public class Login {
private String Username = "username";
private String Password = "password";
private String jsonString;

public String requestForLogin()
{
JSONObject jsonData  =  new JSONObject();
JSONObject jsonobject= new JSONObject();

try{
jsonobject.put("method", "login");
jsonobject.put("username", Username);
jsonobject.put("password",Password);
jsonobject.put("session_id","");
jsonobject.put("dev_type", "android");
jsonData.put("data", jsonobject);
jsonString=jsonData.toString();
}catch(Exception e)
{
e.printStackTrace();
}
return jsonString;
}
}


The json String is like:
{"data":{
"method": login" , "username":"username" , "password":"password" , "session_id":"" , "dev_type":"android"
}
}

Wednesday 1 February 2012

How to send Json data to Server in android.



In this part we are sending data to the server(which is developed in node.js) as json String .

The response is responseString.


import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.MultipartPostMethod;

public class HttptRequest {

public String requestServerForData(String JSONString)
{

String responseString = null;
 HttpClient client = new HttpClient();
     MultipartPostMethod mPost = new MultipartPostMethod("ServerURL");
     client.setConnectionTimeout(10000);  
     mPost.addParameter("jsonstring", JSONString);
     try {
int statusCode1 = client.executeMethod(mPost);
responseString=mPost.getResponseBodyAsString();
System.out.println("status response=========" + mPost.getResponseBodyAsString());
mPost.releaseConnection();
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return responseString;
}

Java Class Decompiler

visit  http://java.decompiler.free.fr/?q=jdgui


follow the steps regarding this.



Monday 28 November 2011

How to send the email from Android application


The mail is use the default android mail from ur application.
Activity Action. Deliver some data to someone else.who the data is being delivered to is not specified.
Intent intent = new Intent(Intent.ACTION_SEND);

In this you will specify which type of data you are sending.
intent.setType("plain/text");

In this emailAddressList  you have to give the mail address of the receipent
intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);

In this emailSubject you will specify the subject of that perticular sending mail.
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);

emailText is like body of the email the content which you want to send.
intent.putExtra(Intent.EXTRA_TEXT, emailText);


Convenience function for creating a ACTION_CHOOSER  Intent. Parameters
target The Intent that the user will be selecting an activity
 to perform. title Optional title that will be displayed in the
 chooser.
startActivity(Intent.createChooser(intent, "SalesApp will send the mail"));

Tuesday 8 November 2011

Phonegap installation guide for blackberry.



to work with phonegap in blackberry , we need to install following things,,,

(1) install Ant
(2) install BB webwoks
(3) download sample phonegap app


##### Install Ant #####

--> download Ant from  http://apache.osuosl.org//ant/binaries/apache-ant-1.8.2-bin.zip
--> Extract and save to in drive C: ,Lets give folder name 'apache-ant' ( without single quotes)

now we neet to set environment path for that...

open Environment variable window

(1) make variable ANT_HOME  and give value    C:\apache-ant\
(2) make another variable JAVA_HOME  and give value   C:\Program Files\Java\jdk1.6.0_11
(3) also add this value in PATH variable  ;%ANT_HOME%\bin


Now open command prompt and type ant ...

if you will get something like this 'Buildfile: build.xml does not exist!  Build failed' ....it works !!


#### Install BB webwoks ####

-->Download Blackberry Webworks from http://us.blackberry.com/developers/browserdev/widgetsdk.jsp

-->install in C: drive lets give folder name BBWP



#### Download sample phonegap app ###

Download it from  https://github.com/phonegap/phonegap-blackberry-webworks

--> now Extract the folder and save in C: drive lets give folder name 'my-phonegap'
-->folder has following contents ,,,,
   -framework
   -javascript
   -template
   -.gitignore
   -bulid.xml
   -LICENSE
   -README.md
   -VERSION


-->go to C:\my-phonegap\phonegap-phonegap-blackberry-webworks-1.0.0-7-g182a043   
and type
   
    ant create -Dproject.path="C:\development\my_new_project"
   
 to create new project ..on succesfull . u will get output something like this

 -----------------------------------------------------------------------------
[code]
 C:\my-phonegap\phonegap-phonegap-blackberry-webworks-1.0.0-7-g182a043>ant create
 -Dproject.path="C:\development\my_new_project"
Buildfile: C:\my-phonegap\phonegap-phonegap-blackberry-webworks-1.0.0-7-g182a043
\build.xml

clean:

build-javascript:
    [mkdir] Created dir: C:\my-phonegap\phonegap-phonegap-blackberry-webworks-1.
0.0-7-g182a043\build\javascript

build-extension:
    [mkdir] Created dir: C:\my-phonegap\phonegap-phonegap-blackberry-webworks-1.
0.0-7-g182a043\build\ext
      [zip] Building zip: C:\my-phonegap\phonegap-phonegap-blackberry-webworks-1
.0.0-7-g182a043\build\ext\phonegap.1.0.0.jar

create:
    [mkdir] Created dir: C:\development\my_new_project
     [copy] Copying 11 files to C:\development\my_new_project
     [copy] Copying 1 file to C:\development\my_new_project\www
     [copy] Copying 1 file to C:\development\my_new_project\www\ext
    [mkdir] Created dir: C:\development\my_new_project\lib\phonegap.1.0.0
     [copy] Copying 2 files to C:\development\my_new_project\lib\phonegap.1.0.0
     [echo]
     [echo] Project Creation Complete!
     [echo] ==========================
     [echo]
     [echo] Getting Started:
     [echo] ----------------
     [echo]
     [echo]   cd C:\development\my_new_project
     [echo]
     [echo]   ant help
     [echo]

BUILD SUCCESSFUL
Total time: 1 second


[/code]
--------------------------------------------------------------------------------------



Now go to C:\development\my_new_project

and edit  project.properties file and set path for BB web works

replace this line

bbwp.dir=C:\\Program Files\\Research In Motion\\BlackBerry WebWorks Packager

with

bbwp.dir=C:\\BBWP


Now it is time to add your html file to www folder ..otherwise it already has default index.html file

[code lang='java']
C:\development\my_new_project>ant build
Buildfile: C:\development\my_new_project\build.xml

generate-cod-name:
     [echo] Generated name: PhoneGapSample.cod

clean:

package-app:
    [mkdir] Created dir: C:\development\my_new_project\build\widget
     [copy] Copying 9 files to C:\development\my_new_project\build\widget
      [zip] Building zip: C:\development\my_new_project\build\PhoneGapSample.zip


build:
     [exec] [INFO]                      Parsing command line options
     [exec] [INFO]                      Parsing bbwp.properties
     [exec] [INFO]                      Validating application archive
     [exec] [INFO]                      Parsing config.xml
     [exec] [WARNING]                   Failed to find the <author> element
     [exec] [INFO]                      Populating application source
     [exec] [INFO]                      Compiling BlackBerry WebWorks applicatio
n
     [exec] [INFO]                      Generating output files
     [exec] [INFO]                      BlackBerry WebWorks application packagin
g complete

BUILD SUCCESSFUL
Total time: 14 seconds



  [/code]
-----------------------

Load into simulator.....


go to C:\development\my_new_project and type  ant load-simulator

final output would be......like this
[code lang='java']



[/code]

##### Load into Device #####

go to  C:\development\my_new_project\build\StandardInstall

using signature tool ...sign the .cod file and using javaloader  load into the device
haapy coding :)
-

JNI installation for android in linux environment

First step:
download the android ndk from http://developer.android.com/sdk/ndk/index.html and
Extract the ndk content.

Second step:
Set the android ndk path in .bashrc file.
Go to your root directory and type gedit .bashrc then it will open the .bashrc file in that replace the ndk with following code ANDROID_NDK_ROOT="Give Your NDK path".
once this is done check whether path is set properly by typing this command
echo $ANDROID_NDK_ROOT then it will show the path.

Third step:
Go to the android-ndk-r6b directory  by typing cd  android-ndk-r6b this command.
Go to samples inside the android-ndk-r6b by entering this command  cd samples.
Go to hello-jni inside the samples by entering this commnad cd hello-jni.
Then finally build the project by using ndk-build command.
the path will be like this.
/android-ndk-r6b/samples/hello-jni$ ndk-build


Final step:
Open your eclipse and import the project inside the samples hello-jni.