Monday, June 6, 2016

android barcode example

THis post regarding best barcode scanner for android for beginners actually i worked and found most useful fro developing barcode for my project 
Android library projects that provides easy to use and extensible Barcode Scanner views based on ZXing and ZBar.

I am giving github link with this example am just adding details but any confusion please comment below i would happy to reply it back 

ZXing

Installation

Add the following dependency to your build.gradle file.
compile 'me.dm7.barcodescanner:zxing:1.8.4'

Simple Usage

1.) Add camera permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.CAMERA" />
2.) A very basic activity would look like this:
public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler {
    private ZXingScannerView mScannerView;

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        mScannerView = new ZXingScannerView(this);   // Programmatically initialize the scanner view
        setContentView(mScannerView);                // Set the scanner view as the content view
    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
        mScannerView.startCamera();          // Start camera on resume
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();           // Stop camera on pause
    }

    @Override
    public void handleResult(Result rawResult) {
        // Do something with the result here
        Log.v(TAG, rawResult.getText()); // Prints scan results
        Log.v(TAG, rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)

        // If you would like to resume scanning, call this method below:
        mScannerView.resumeCameraPreview(this);
    }
}
Please take a look at the zxing/sample project for a full working example.

Advanced Usage

Take a look at the ScannerActivity.java or ScannerFragment.java classes to get an idea on advanced usage.
Interesting methods on the ZXingScannerView include:
// Toggle flash:
void setFlash(boolean);

// Toogle autofocus:
void setAutoFocus(boolean);

// Specify interested barcode formats:
void setFormats(List<BarcodeFormat> formats);

// Specify the cameraId to start with:
void startCamera(int cameraId);
Specify front-facing or rear-facing cameras by using the void startCamera(int cameraId); method.
Supported Formats:
BarcodeFormat.UPC_A
BarcodeFormat.UPC_E
BarcodeFormat.EAN_13
BarcodeFormat.EAN_8
BarcodeFormat.RSS_14
BarcodeFormat.CODE_39
BarcodeFormat.CODE_93
BarcodeFormat.CODE_128
BarcodeFormat.ITF
BarcodeFormat.CODABAR
BarcodeFormat.QR_CODE
BarcodeFormat.DATA_MATRIX
BarcodeFormat.PDF_417

ZBar

Installation

Add the following dependency to your build.gradle file.
compile 'me.dm7.barcodescanner:zbar:1.8.4'

Simple Usage

1.) Add camera permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.CAMERA" />
2.) A very basic activity would look like this:
public class SimpleScannerActivity extends Activity implements ZBarScannerView.ResultHandler {
    private ZBarScannerView mScannerView;

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        mScannerView = new ZBarScannerView(this);    // Programmatically initialize the scanner view
        setContentView(mScannerView);                // Set the scanner view as the content view
    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
        mScannerView.startCamera();          // Start camera on resume
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();           // Stop camera on pause
    }

    @Override
    public void handleResult(Result rawResult) {
        // Do something with the result here
        Log.v(TAG, rawResult.getContents()); // Prints scan results
        Log.v(TAG, rawResult.getBarcodeFormat().getName()); // Prints the scan format (qrcode, pdf417 etc.)

        // If you would like to resume scanning, call this method below:
        mScannerView.resumeCameraPreview(this);
    }
}
Please take a look at the zbar/sample project for a full working example.

Advanced Usage

Take a look at the ScannerActivity.java or ScannerFragment.java classes to get an idea on advanced usage.
Interesting methods on the ZBarScannerView include:
// Toggle flash:
void setFlash(boolean);

// Toogle autofocus:
void setAutoFocus(boolean);

// Specify interested barcode formats:
void setFormats(List<BarcodeFormat> formats);
Specify front-facing or rear-facing cameras by using the void startCamera(int cameraId); method.
Supported Formats:
BarcodeFormat.PARTIAL
BarcodeFormat.EAN8
BarcodeFormat.UPCE
BarcodeFormat.ISBN10
BarcodeFormat.UPCA
BarcodeFormat.EAN13
BarcodeFormat.ISBN13
BarcodeFormat.I25
BarcodeFormat.DATABAR
BarcodeFormat.DATABAR_EXP
BarcodeFormat.CODABAR
BarcodeFormat.CODE39
BarcodeFormat.PDF417
BarcodeFormat.QRCODE
BarcodeFormat.CODE93
BarcodeFormat.CODE128

Rebuilding ZBar Libraries

mkdir some_work_dir
cd work_dir
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
Patch the localcharset.c file: vim libiconv-1.14/libcharset/lib/localcharset.c
On line 48, add the following line of code:
#undef HAVE_LANGINFO_CODESET
Save the file and continue with steps below:
cd libiconv-1.14
./configure
cd ..
hg clone http://hg.code.sf.net/p/zbar/code zbar-code
cd zbar-code/android
android update project -p . -t 'android-19'
Open jni/Android.mk file and add fPIC flag to LOCAL_C_FLAGS. Open jni/Application.mk file and specify APP_ABI targets as needed.
ant -Dndk.dir=$NDK_HOME  -Diconv.src=some_work_dir/libiconv-1.14 zbar-clean zbar-all
Upon completion you can grab the .so and .jar files from the libs folder

github link 
https://github.com/dm77/barcodescanner

Thursday, February 4, 2016

Android Camera Basic


Over View

This project demonstrates how to implement a camera preview step-by-step.

Git Tags

  • minimum -- Minimum code implementing camera preview.
  • orientation -- Display in correct orientation.
  • aspectratio -- Display in correct aspect ratio.
  • aspectratio_refine -- Fixed a non-critical issue that onSurfaceChanged() is called twice.
  • resizable -- Includes UI to arbitrarily set camera preview size.
  • previewsize_fix -- Fixed a problem that preview couldn't start even with supported preview size.
  • multicamera -- Supports multiple cameras.
  • practical -- Allows the user program to set the layout size, position, and callbacks.

minimum

This release is a minimum implementation of camera preview, which may display the preview in wrong orientation and broken aspect ratio.

Files

  • CameraPreview.java -- Primary file implementing camera preview feature.
  • MainActivity.java -- Driver Activity to demonstrate the usage of CameraPreview.java.

orientation

This release handles the orientation change to display in the correct orientation.

Files

The same as the ones in "minimum."

aspectratio

This release displays camera preview in correct aspect ratio. Whatever the actual size of the preview is, it keeps the width & height ratio while it scale the preview to fit to the display. This although has a non-critical issue that might configure the camera parameters twice for one configuration change of the display. It is caused by the multiple invocation of onSurfaceChanged for one orientation change because layout parameter might be updated at the first call of onSurfaceChanged. This will be fixed in the next release.

Files

The same as the ones in "orientation."

aspectratio_refine

This release fixed the known issue explained in the previous section. It was also changed the algorithm to select the preview size, and now picks the size of which the ratio is closest to the one of the display. There is a known issue that the camera preview might fail to start even with the supported preview size on some devices. It is observed on Japanese device, IS03, so far.

Files

The same as the ones in "aspectratio."

resizable

This release allows user to arbitrarily set the size of camera preview from the supported sizes. It still keeps the aspect ratio and scales it to fit to the display.

Files

  • CameraPreview.java -- Primary file implementing camera preview feature.
  • MainActivity.java -- Driver Activity to demonstrate the usage of CameraPreview.java. This file includes both code that utilizes CameraPreview and ResizeableCameraPreview, one of them commented out.
  • ResizableCameraPreview.java -- Extended class of CameraPreview allowing user to specify the preview size.

picturesize_fix

This release includes a fix that solves the issue that the preview can't be started even with supported preview size. The solution was to set picture size with supported picture size, as well as preview size. This release also supported more display rotation, Surface.ROTATION_270 in addition to Surface.ROTATION_90. This affects only Android 2.2 and later.

Files

The same as "resizable."

Known Issue

  • If the display rotation is changed from Surface.ROTATION_90 to Surface.ROTATION_270 or vice versa, the rotation of the camera preview is not updated.
  • Orientation is not correct on an optimus pad (or all Honeycomb).

multicamera

This release supports multiple camera. If the device has more than one camera on it, the user can choose a camera to display the camera preview. CameraPreview (and ResizableCameraPreview) takes a camera ID, which is usually 0 for back-facing camera and 1 for front-facing camera if exists. To switch between cameras, call stop() and instantiate another camera preview object with different camera ID. This release also shows how to stop the camera preview when it is not on the foreground. Stopping camera preview prevents from wasting the battery power and blocking other applications to use camera device.

Files

The same as "picturesize_fix."

practical

This version allows user class to specify the size and position of the camera preview. Also, implemented setter for a callback called on preview-ready, and wrapper for Camera.set*Callback. Refined sample driver activities.

Files

  • CameraPreview.java -- Primary file implementing camera preview feature.
  • MainActivity.java -- UI that allows users to select a sample activity or a test activity to open.
  • CameraPreviewSampleActivity.java -- Driver Activity to demonstrate the usage of CameraPreview.java.
  • CameraPreviewTestActivity.java -- Driver Activity for testing CameraPreview.java.
  • ResizableCameraPreview.java -- Extended class of CameraPreview allowing user to specify the preview size, for the purpose of testing.

Android Facebook integration Code and

In this tutorial i am giving facebook integration with android app please look into the github link and develop the app based on your requirement from facebook

Download Link
https://github.com/facebook/facebook-android-sdk.git
if you not finding hyperlink copy paste url and do the coding 

This open-source library allows you to integrate Facebook into your Android app.
Learn more about about the provided samples, documentation, integrating the SDK into your app, accessing source code, and more at https://developers.facebook.com/docs/android

  1. Check-out the tutorials available online at https://developers.facebook.com/docs/android/getting-started
  2. Start coding! Visit https://developers.facebook.com/docs/android/ for tutorials and reference documentation.

FEATURES

Happy Coding

Monday, December 28, 2015

Hybrid Applications

Hybrid Mobile application frame works are HTML5 mobile UI frameworks  which lets you to create cross platform hybrid mobile applications by using the technology that you already known i.e. HTML5, CSS and JavaScript(JS).

Whether you are a web developer planning to pitch or start into mobile apps development, or an experienced native apps developer, hybrid mobile apps development is the easiest way to start building cross platform mobile apps. 

The biggest reason for hybrid apps growth is that you write the hybrid mobile app once and run it on every platform like iOS, Android, Windows 8/10, Blackberry etc. without putting much extra efforts.

You design the app as a regular web application, a responsive web application that fits different screen sizes by using the components provided by mobile HTML5 UI frameworks. The access to native hardware components like Camera, Contacts or accelerometer is achieved by JavaScript APIs like the ones that Cordova (PhoneGap) offers or Appcelerator (Titanium). Your app is then compiled into platform specific native packages, ready to be deployed on your mobile device or published to app stores.

On a high level, we can say that hybrid applications are basically websites that are 'wrapped' in native code. This allows you to create a native app that at its core is just a website. However, the wrapping allows you to access low level hardware like a native app and allows you to publish the app to app stores. Another major benefit of hybrid apps is that you only need to know HTML/JavaScript to create a multi-platform app that will run on all of the mobile operating systems. This is what Cordova / PhoneGap does.
While starting to create Hybrid mobile application development you must be aware about Tools/SDK Kit and Frameworks.

Tools/SDK Kit
Tools like Cordova / PhoneGap or Appcelerator Titanium will work as SDK which will be creating the application bundle will be having native code as well as native configuration application development. The developer only need to bother about web development part otherwise HTML or CSS part of the application. Rest of the things are done by these tools. 

There are several Tools/SDKs available in the market. It will be discussed in my next blog article.

We Will Discuss in another blog.


Frameworks 
If you are worried about Responsive UI as well as mobile application icons and tools then no need to worry just choose any framework it is having pre written CSS and JS files to do all the UI Stuff and lots of attributes. You just need to add attributes in your HTML code.
We will Discuss detail on Another Blog

Best Recommendation for Hybrid app Development

Adobe Dreamweaver + jQuery mobile Framework + Cordova (tools) 
Adobe Dreamweaver is having an option to create mobile responsive UI by automatically integrating with jQuery mobile resulting in creating a web folder. That web folder can be directly used by Cordova project for creating the application. It is the simplest way for programmer's to begin with creating hybrid apps.

But the recommended framework would be Ionic. Reason being, from the beginning of application development, you will be following MVC or AngularJS pattern for the application. That leads to highly maintainable code you can write and execute.


Still confused? Make your hands dirty first ☺ Just create one simple application using Cordova and Adobe Dreamweaver using jQuery mobile Framework as explained above.
Note:

Because of huge content i am dividing this article into  parts so that may be  you can understand easily as i believe 

Sunday, August 25, 2013

Android Integrating google map with application

In this tutorial i will explain step by step about integrating google map with android app


  1. Create a new android project with default settings.
  2. Import “google-play-services_lib”.
    1. Select File-->Import
    2. Select Android-->Existing Android Code into Workspace
    3. Browse and select <bundle root>\sdk\extras\google\google_play_services\libproject
    4. Select “google-play-services_lib” and finish.
      3) Install google play services.
      1. Open sdk manager
      2. Select google play services and install.
4.Add the google play services library to your project.
A.Right-click on your project and select properties.
B.Select the library, and press OK.

5.Find your SHA1.
  1. Open command prompt and go to your jdk/bin folder. Such as: C:\Program Files\Java\jdk1.7.0_02\bin
    • Start-->run, cmd
    • cd C:\Program Files\Java\jdk1.7.0_02\bin
  2. find your debug.keystore path by checking windows-->preferences-->android-->build

C.Run the following command to get your sha1: keytool -v -list -keystore "<debug.keystore path>" and press “enter” when a password asked.

6.Get the key for android apps.
  1. You need to have a gmail account.
  2. Create Google APIs project from https://code.google.com/apis/console adress.


C . From services, Turn “Google Maps Android API v2” to ON.

D.  From API Access, create new Android Key.


E . Paste SHA1 and your package name <SHA1>;<package name> for example at my case it is (3C:64:03:7B:0E:F7:E5:71:0D:10:9D:62:4C:03:8C:F2:4E:AD:B8:94;info.tekguc.umut.googlemapsmapsandroidv2)



7.Modify AndroidManifest.xml
  1. Double-click on androidmanifest.xml

B.Add necessary permissions and glEs feature to androidmanifest.xml
  1.  <permission
            android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
            android:protectionLevel="signature"></permission>
        <uses-permission
            android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/>
        <uses-permission
            android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
        <uses-permission
            android:name="android.permission.INTERNET"/>
        <uses-permission
            android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission
            android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        <uses-permission
            android:name="android.permission.ACCESS_FINE_LOCATION"/>
        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true"/>
    C .Create metadata for map api in application
  2. <meta-data  android:name="com.google.android.maps.v2.API_KEY"
    android:value="AIzaSyDciL7-T3BphxGv2q-A77vNrcyJQ_sTrgI"/>
    D.       Your final androidmanifest.xml file will lool like as follows:
  3.  <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="info.tekguc.umut.googlemapsmapsandroidv2"
        android:versionCode="1"
        android:versionName="1.0" >
        <uses-sdk
            android:minSdkVersion="14"
            android:targetSdkVersion="17" />
            <permission
            android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
            android:protectionLevel="signature"></permission>
        <uses-permission
            android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/>
        <uses-permission
            android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
        <uses-permission
            android:name="android.permission.INTERNET"/>
        <uses-permission
            android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission
            android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        <uses-permission
            android:name="android.permission.ACCESS_FINE_LOCATION"/>
        
        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true"/>
        
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
              <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="AIzaSyDciL7-T3BphxGv2q-A77vNrcyJQ_sTrgI"/>
            <activity
                android:name="info.tekguc.umut.googlemapsmapsandroidv2.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>
    
    
    
    
    8 Modify activity_main.xml
    1. Double click on activity_main.xml

  1. Add to map fragment
     <fragment
      android:id="@+id/map"        
      android:layout_width="match_parent"        
      android:layout_height="match_parent"        
      class="com.google.android.gms.maps.MapFragment"/>
  2. Your final activity_main.xml file will lool like as follows:
     <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"    
    xmlns:tools="http://schemas.android.com/tools"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent"    
    android:paddingBottom="@dimen/activity_vertical_margin"    
    android:paddingLeft="@dimen/activity_horizontal_margin"    
    android:paddingRight="@dimen/activity_horizontal_margin"    
    android:paddingTop="@dimen/activity_vertical_margin"    
    tools:context=".MainActivity" >
    <TextView        
    android:layout_width="wrap_content"        
    android:layout_height="wrap_content"        
    android:text="@string/hello_world" />
    <fragment
            android:id="@+id/map"     
            android:layout_width="match_parent"        
            android:layout_height="match_parent"        
    class="com.google.android.gms.maps.MapFragment"/>
    </RelativeLayout>
    9 Modify MainActivity.Java
    package com.nisdroid; 
    import android.os.Bundle; 
    import android.app.Activity; 
    import android.view.Menu; 
    import com.google.android.gms.maps.GoogleMap; 
    import com.google.android.gms.maps.MapFragment; 
    import com.google.android.gms.maps.model.LatLng; 
    import com.google.android.gms.maps.model.Marker; 
    import com.google.android.gms.maps.model.MarkerOptions; 
    public class MainActivity extends Activity {     
    private GoogleMap mMap;         
    @Override     
    protected void onCreate(Bundle savedInstanceState) {         
    super.onCreate(savedInstanceState);         
    setContentView(R.layout.activity_main);             
    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();         
    mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);         
    final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);         
    Marker ciu = mMap.addMarker(new MarkerOptions()                                   
    .position(CIU).title("My Office"));     
    }     
    @Override     
    public boolean onCreateOptionsMenu(Menu menu) {         
    // Inflate the menu; this adds items to the action bar if it is present.         
    getMenuInflater().inflate(R.menu.main, menu);         
    return true;     } }