Tuesday 10 July 2012

Sending Sms in JAVA


Hello friends have you searching of sending mobile alert or mobile
Notification from your Java web Application ?

If, Yes then this blog Helps you a lot.

While lot of searches I came across to Red Oxygen SMS gateway.
It provide a few free messages on the daily basis for your testing
Purpose.

For sending sms from your application first of all you have to sign
Up  your account in Red Oxygen .

Once you create your account in Red Oxygen you receive a mail
Which contains:

Account Name:
Mukesh Yadav
Account ID:
CI0007555890
Email Address:
Password:
************


Now  Place the following code in your web application and Enjoy the
Mobile alert facility.




/*
 *
 *  Java example code to send an SMS via the Red Oxygen SMS gateway over HTTP.
 *
 *  Mukesh Yadav   
 */

import java.io.*; 
import java.net.*; 
import java.lang.*; 



public class RedOxygenSMS
{ 

 public static int  SendSMS(String strAccountId,String strEmail,
        String strPassword,String strMSISDN,String strMessage,
        StringBuffer strResponse)
 {
  String  sRequestURL;
  String  sData;
  Integer nResult = -1;
 
  sRequestURL = "http://sms1.redoxygen.net/sms.dll?Action=SendSMS";

  try
  {  
  
   sData  = ("AccountId="  +       URLEncoder.encode(strAccountId,"UTF-8"));
   sData += ("&Email="     + URLEncoder.encode(strEmail,
                        "UTF-8"));
   sData += ("&Password="  + URLEncoder.encode(strPassword,
                        "UTF-8"));
   sData += ("&Recipient=" + URLEncoder.encode(strMSISDN,
                        "UTF-8"));
   sData += ("&Message="   + URLEncoder.encode(strMessage,
                        "UTF-8"));


  
   URL urlObject = new URL(sRequestURL); 
   
   HttpURLConnection con = (HttpURLConnection)  urlObject.openConnection();
   con.setRequestMethod("POST");
   con.setDoInput (true);
                        con.setDoOutput (true);


   DataOutputStream out;
              out = new DataOutputStream(con.getOutputStream());
              out.writeBytes (sData);
   out.flush();
   out.close();
      
   BufferedReader in = new BufferedReader
                          (new InputStreamReader(con.getInputStream())); 
     
   String inputLine; 
   StringBuffer responseBuffer = new StringBuffer(); 

   while ((inputLine = in.readLine()) != null)
   {
                              responseBuffer = responseBuffer.append(inputLine);
         responseBuffer = responseBuffer.append("\n\n\n");
   }
  
   strResponse.replace(0,0,responseBuffer.toString());

   String sResultCode = strResponse.substring(0,4);
   nResult = new Integer(sResultCode);
   
   in.close();
  }
  
  catch (Exception e)
  {
   System.out.println("Exception caught sending SMS\n"); 
   nResult = -2;
  }
  return nResult;
 }


 public static void main(String[] args) throws Exception 
 { 
  String strAccountId  = "CI00001234";  // Put your AccountId here
  String strEmail      = "youremal@company.com";  // Put your Email address here (Used for authentication and replies)
  String strPassword   = "yourpassword";  // Put your Password here
  String strMSISDN     = "61407000000";   // Put a recipient mobile number here
  String strMessage    = "Test SMS via Red Oxygen API";  // Put your SMS message text here
  Integer nResult;
  StringBuffer strResponse = new StringBuffer();

  nResult = SendSMS(strAccountId,strEmail,strPassword,strMSISDN,strMessage,strResponse);

                System.out.println("Result Code = " + nResult + "\n");
  System.out.println("Response Text = " + strResponse + "\n");

 } 
} 




Hope this will help you…
Enjoy Coding J

Tuesday 3 July 2012

Database in HTML5

Hello Guys,

Have you thinking of Creating | Inserting | Fetching of data in HTML5. If yes then this
Blog will helps you a lot.
Yesterday I worked on a phonegap Application where my need is to provide offline
Access to my mobile Apps. Its very Simple using HTML5 offline access to local
Database .

Here , I am sharing with a sample code:

1. Creating Database and Table in HTML5:
         This is, just a simple form. Of course, when you have a form, you want to capture the form submission somehow. In our case, we’ll use the new HTML5 local SQL database. We don’t need any servers or HTTP requests or anything except a compatible browser .
Here’s how we initialize the database:

Below can see that all we did here was add an openDatabase call and some SQL statements to create tables. These are just standard SQL statements (the reference SQL is from SQLite). 

<!DOCTYPE html> 
<html>  
  <head>
    <title>Offline Storage</title>
    <script src="http://www.google.com/jsapi"></script>
    <script>
      google.load("jquery", "1.4.1");
    </script>
    <script>
      var db = window.openDatabase("Student", "", "Previous Course", 1024*1000);
      $(document).ready(function() {
        db.transaction(function(tx) {
          tx.executeSql('CREATE TABLE IF NOT EXISTS Course(id INTEGER PRIMARY KEY, course_id
              INTEGER, subject_one TEXT, subject_two TEXT, email TEXT)', []);
        });
      });
    </script>
  </head>
  <body>
    <form method="get" id="course_form">
      <div>
        <label for="1">Subject 1</label>
        <input type="text" value="" id="subject1" name="subject1" placeholder="subject"/>
      </div>
      <div>
        <label for="2">Subject 2</label>
        <input type="text"  value="" id="subject2" name="subject2" placeholder="subject" />
      </div>
      <div>
        <input type="email" id="email" placeholder="Enter your email address" size="40"/>
      </div>
      <div>
        <input type="submit" value="Upload Data" />
      </div>
    </form>
  </body>
</html> 


2. Inserting Data into the Table:
               Now we’ll write a couple functions to help us insert subject into this table:

<!DOCTYPE html>
<html>
<head>
<title>OffLine Storage</title>
<script src="http://www.google.com/jsapi"></script>
<script>
      google.load("jquery", "1.4.1");
</script>
<script>
      var db = window.openDatabase("Student", "", "Previous Course", 1024*1000);

      function insertSubject(subject_one, subject_two, course_id, email) {
       db.transaction(function(tx) {
          tx.executeSql('INSERT INTO Course (course_id, subject_one, subject_two, email)
            VALUES (?, ?, ?, ?)', [course_id, subject_one, subject_two, email]);
       });
      }

      $(document).ready(function() {
        db.transaction(function(tx) {
          tx.executeSql('CREATE TABLE IF NOT EXISTS Course(id INTEGER PRIMARY KEY, course_id
           INTEGER, subject_one TEXT, subject_two TEXT, email TEXT)', []);
        });

        $('#course_form').submit(function() {
         course = { 1: $('#subject1').val(), 2: $('#subject2').val() };
          
          insertSubject($('#subject1').val(), $('#subject2').val(), 1, $('#email').val());

          return false;
        });
      });
    </script>
</head>
<body>
<form method="get" id="course_form">
<div>
<label for="1">Subject 1</label> <input type="text" value=""
id="subject1" name="subject1" placeholder="subject" />
</div>
<div>
<label for="2">Subject 2</label> <input type="text" value=""
id="subject2" name="subject2" placeholder="subject" />
</div>
<div>
<input type="email" id="email" placeholder="Enter your email address"
size="40" />
</div>
<div>
<input type="submit" value="Upload Data" />
</div>
</form>
</body>
</html>

3. Displaying | Fetching of data from the table :
       Getting data inserted into our database was trivial, but now we want to show previously submitted data, right? This is easy, too. We’ll start with two changes: (1) show ALL previously submitted data upon loading the page, and (2) update this list whenever new data are submitted.




<!DOCTYPE html>
<html>
<head>
<title>OffLine Storage</title>
<script src="http://www.google.com/jsapi"></script>
<script>
      google.load("jquery", "1.4.1");
</script>
<script>
      var db = window.openDatabase("Student", "", "Previous Course", 1024*1000);

      function insertSubject(subject_one, subject_two, course_id, email) {

       db.transaction(function(tx) {
          tx.executeSql('INSERT INTO Course (course_id, subject_one, subject_two, email)
VALUES (?, ?, ?, ?)', [course_id, subject_one, subject_two, email]);
       });
      }

      function renderResults(tx, rs) {
          e = $('#previous_course');
          e.html("");
          for(var i=0; i < rs.rows.length; i++) {
            r = rs.rows.item(i);
            e.html(e.html() + 'id: ' + r['id'] + ', subject_one: ' + r['subject_one'] + ',
  subject_two: ' + r['subject_two'] + ', email: ' + r['email'] + '<br />');
          }
        }
        function displayData(email) {
          db.transaction(function(tx) {
            if (!(email === undefined)) {
              tx.executeSql('SELECT * FROM Course WHERE email = ?', [email], renderResults);
            } else {
              tx.executeSql('SELECT * FROM Course', [], renderResults);
            }
          });
        }
        $(document).ready(function() {

         db.transaction(function(tx) {
                 tx.executeSql('CREATE TABLE IF NOT EXISTS Course(id INTEGER PRIMARY KEY,
course_id INTEGER, subject_one TEXT, subject_two TEXT, email TEXT)', []);
               });
               $('#course_form').submit(function() {
                course = { 1: $('#subject1').val(), 2: $('#subject2').val() };
                insertSubject($('#subject1').val(), $('#subject2').val(), 1, $('#email').val());
                displayData();
            return false;
          });
               displayData();
        });
    </script>
</head>
<body>
<form method="get" id="course_form">
<div>
<label for="1">Subject 1</label> <input type="text" value=""
id="subject1" name="subject1" placeholder="subject" />
</div>
<div>
<label for="2">Subject 2</label> <input type="text" value=""
id="subject2" name="subject2" placeholder="subject" />
</div>
<div>
<input type="email" id="email" placeholder="Enter your email address"
size="40" />
</div>
<div>
<input type="submit" value="Upload Data" />
</div>
</form>
<div>
<h2>Previous Course</h2>
</div>
<div id="previous_course"></div>
</body>
</html>

Hope this will helps some one.....
Enjoy Coding  :)

Wednesday 20 June 2012

Integrating Zxing QR Code scanner Into your android Application | ZXing QR Reader | Android - Integrate ZXing QR code scanner


Hello Android Guys,

 Have you facing issue in Integrating QR Code scanner ?  

 Please follow this steps:

android qr code Step1 :Obtain the zxing source code
  Run this command from your terminal(for mac/linux os)
  svn checkout http://zxing.googlecode.com/svn/trunk/ 
  zxing-read-    only
  Also you can find the full source code at this url
  http://code.google.com/p/zxing/source/browse/trunk.               

 Step 2 : Build zxing core using Apache Ant
  You will need to build the core project into a jar file using apache ant
  (download from here http://ant.apache.org/ivy/download.cgi). 
  Using a shell or cmd prompt navigate to the root directory of 
  the downloaded zxing src and execute “ant -f core/build.xml”. 
  This will produce a file core/core.jar which
  we will use in the next step.   
  Download Core.jar from here

 Step 3: Build ZXing Android using Eclipse
  Create a New Android Project (File –> New –> Android Project).
  Set the project name to ZXing (or similar).
  Select the “Create project from existing source” radio button
  Click “Browse” and navigate to the android project that you downloaded from
  zxing  and click “OK” Select “Finish”

  The project will not currently build. We need to add the core.jar file (that we
  produced    in the previous step) into our project. Right-click on ZXing
  project –> properties –> Java Build Path –> Add External Jars –> Navigate to
  and select core.jar –> Open –> OK.

  Actually, while we’re here we should do one more very important thing!
  Right-click on ZXing project –> properties –> Android –> Scroll down and
  check/tick the “Is Library” checkbox –> OK

 Step 4: Include ZXing Android into your project.
   Within Eclipse,  Right-click on YOURPROJECTNAMEHERE project –>
   properties –>Android –> Scroll down to Libraries section –> Click Add –>
   Select ZXing (which should appear as an option as a result of completing
   previous step).


   Here ,I am sharing you a full running Sample code . Just download it, import
   it into your Eclipse and Run.

   1. AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.testqrcode"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.CAMERA" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TestQRCodeActivity"
            android:label="@string/app_name" >
            <intent-filter>
              <action android:name="android.intent.action.MAIN" />

              <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.google.zxing.client.android.CaptureActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden" >
            <intent-filter>
              <action android:name="android.intent.action.MAIN" />

              <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
              <action android:name="com.google.zxing.client.android.SCAN" />

              <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

  </manifest>
   2. TestQRCodeActivity.java
package com.testqrcode;

import com.google.zxing.client.android.CaptureActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class TestQRCodeActivity extends Activity {

 /** Called when the activity is first created. */
 Button b1;
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);
  b1 = (Button) findViewById(R.id.submit);

  b1.setOnClickListener(new OnClickListener() {
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    Intent intent = new Intent(TestQRCodeActivity.this,
            CaptureActivity.class);
    // Intent intent = new
    // Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
    startActivityForResult(intent, 0);
   }
  });
 }

 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  if (requestCode == 0) {
   if (resultCode == 1) {
    // Handle successful scan
    String capturedQrValue = intent.getStringExtra("RESULT");
    // String format =
    intent.getStringExtra("SCAN_RESULT_FORMAT");
          Toast.makeText(TestQRCodeActivity.this,
    "Scan Result:" + capturedQrValue, Toast.LENGTH_SHORT)
    .show();
   } else if (resultCode == RESULT_CANCELED) {
    // Handle cancel

   }
  } else {

  }
 }
}

 I am also sharing the screen shot which helps you in
        configuring the build path and zxing as a library  
         

 project.



        


android qr code reader integration
android qr code reader
qr code scanner
zxing qr code scanner
            
   
   May this will Helps you.
   Enjoy Coding…. J
   Cheers…. J

 

Copyright @ 2013 Android Developers Blog.