Skip to main content

Posts

Barcode or QR scanner - Android Tutorial

This tutorial explains how to scan Bar-code or QR-code . We have many third party libraries and here we can see one among them zxing-android-embedded library How to use this Step 1: Add the dependency   implementation 'com.journeyapps:zxing-android-embedded:3.5.0' Step 2 : Initialize it in your activity IntentIntegrator qbScan = new IntentIntegrator(this);  Step 3: Call on button call or on any trigger qbScan.initiateScan(); For Portrait mode, in Manifest file   <activity     android:name="com.journeyapps.barcodescanner.CaptureActivity"     android:screenOrientation="portrait"     tools:replace="screenOrientation" /> _____________________________________________________________________________ Happy Coding...

Encryption on Android

Encryption is a simple way to encrypt and decrypt strings on Android This can be achieved by some third-party libraries, here we look about one among them How to use   1.  Add JitPack to your build file allprojects {   repositories {     ...     maven { url 'https://jitpack.io' }   } } 2.Add the gradle dependency compile 'com.github.simbiose:Encryption:2.0.1' 3.  Get an Encryption instance String key = "YourKey"; String salt = "YourSalt"; byte[] iv = new byte[16]; Encryption encryption = Encryption.getDefault(key, salt, iv); 4. Encrypt your text String encrypted = encryption.encryptOrNull("Text to be encrypt"); 5. Decrypt your text String decrypted = encryption.decryptOrNull(encrypted); for more ... ---------------------------------------------------------------------------------------------------------------- Happy Coding...

How to clear the orientation issue on Camera Image

We will be taking a picture with this library and create a Bitmap and set it in an ImageView as follow public void onPictureTaken(CameraView cameraView, byte[] data) {      Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);      imageView.setImageBitmap(bitmap); } This will work fine on most of the devices however there are some exceptional devices too, where the picture orientation appears to be incorrectly rotated 90 degrees to the left when the device orientations is portrait. Solution to overcome this issue in your application  Trick :  Check if the  width > height  of the image then rotate by 90  Follow the steps: private static int fixOrientation(Bitmap bitmap) {         if (bitmap.getWidth() > bitmap.getHeight()) {             return 90;         }         return 0;     } Call this method to apply the rotation if needed public static Bitmap flipIMage(Bitmap bitmap) {         //Moustafa: fix

Underline TextView Text - Android

If your app need an underline for the text in TextView  Achieve it in simple way  - (By both xml and code part) xml It can be achieved if you are using a string resource xml file, which supports HTML tags like <b></b>, <i></i> and <u></u> <resources> <string name = "your_string_here" > This is an <u> underline </u> . </string> </resources> Code Way - 1 TextView textView = ( TextView ) view . findViewById ( R . id . textview ); SpannableString content = new SpannableString ( "Hello, Android !!!" ); content . setSpan ( new UnderlineSpan (), 0 , content . length (), 0 ); textView . setText ( content ); Way - 2 textview . setPaintFlags ( textview . getPaintFlags ()| Paint . UNDERLINE_TEXT_FLAG ); Way - 3 textview . setText ( Html . fromHtml ( "<u>Text to underline</u>" ));

Run / Install / Debug Android applications over Wi-Fi? - Android Tutorial

What is the need through Wi-Fi? i. This will save your phone from irregular charges. ii. A remedy for short length USB cables  There are several methods to achieve this, here we can see how to do with the plugin. A better method through Android-Studio plugin Follow the steps to achieve this: 1 ) A plugin for Android studio exits , called    ADB WiFi Connect.      (There are some other plugin such as  WiFi ADB ULTIMATE,  Android wifi ADB ) 2) Go to file -> settings -> Plugins -> Browse Repositories 3) Look for  ADB WiFi Connect  , click on INSTALL , and then restart on prompt 4) You will see a new icon , which is your new plugin. Like in an image Now to make this work : 5) Go to your phone's developer option and enable DEBUGGING (must) 6) Also enable , ALLOW DEBUG OVER TCP/NETWORK 7) Attach your phone via USB , and make sure, both phone and your PC/laptop are connected to the same network (either Hotspot or WiFi) 8) CLICK ON THE NEW I

Add custom font in Android using Calligraphy library

Are you fed up of Custom Views to set fonts? Or traversing the ViewTree to find TextViews? Sometime we want some other font for our Android application then you can add custom font in Android using Calligraphy library . Dependency Include the dependency Download (.aar) dependencies { compile ‘uk.co.chrisjenx:calligraphy:2.2.0’ } Add Fonts Add your custom fonts to assets/ . All font definitions are relative to this path. On Assets you should right-click New Directory, call it "fonts". In the finder put the .ttf  or .otf  font files in there. Create Class Create a class that extends Application and write this code public class App extends Application { @Override public void onCreate() { super.onCreate(); CalligraphyConfig.initDefault(new CalligraphyConfig.Builder() .setDefaultFontPath("your font path") .setFontAttrId(

Android Collapsing ToolbarLayout Example

Android CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout. CollapsingToolbarLayout is the newly introduced in Lollipop , using which you can create awesome scrolling effect. The following sample will explain you how to achieve this CollapsingToolbarLayout Build Gradle file : build.gradle dependencies {     compile 'com.android.support:design:23.0.1'    compile 'de.hdodenhof:circleimageview:2.2.0' }   XML Layout activity_main.xml <? xml version= "1.0" encoding= "utf-8" ?> < android.support.design.widget.CoordinatorLayout xmlns: android = "http://schemas.android.com/apk/res/android"     xmlns: app = "http://schemas.android.com/apk/res-auto"     android :layout_width= "match_parent"     android :layout_height= "match_parent"     android :background= "@color/color_g