--ADVERTISEMENT--

The android hardware and system information is different from device to device. You can find your android device info manually in About device section of settings. In this tutorial, you will learn to get android device system and hardware information programmatically. We will focus on some of the properties like serial number, model no, id, android SDK, brand, manufacture, version code, etc.

There are many other info you can get from a android device but here we will focus on some of the android properties. To get system info, we are going to add a button and a textview to display information of android device when button is clicked.

Related:
Embed and Play MP3 Songs/Music in Android Application Using WebView
Android Custom Horizontal Icons Menu
Material Ripple Effect/Animation in Android

There are different methods to retrieve the platform related information of the device programmatically. To obtain the hardware and software related information of an android device that runs your application, follow the following steps. Here we will only display information in TextView but you can also track to your server. You can get info like;


  • CPU Manufacturer
  • Model and serial number
  • SD Card Manufacturer
  • Camera Manufacturer and other related specs
  • Bluetooth related information
  • WiFi related information
  • Display vendor and model


How to Get Android Hardware and System Information Programmatically

Android Example: Getting Android Hardware and System Information Programmatically

Create a new android project with project name AndroidSystemInfo packagecom.viralandroid.androidsysteminfo.

XML Layout File

Open your activity_main.xml file and add a Button and TextView with different id. TextView is used to display device info when we click the button. Following is the complete code XML layout file.

res/layout/activity_main.xml


Java Activity File

Open your MainActivity.java activity file and define button and textview that we have created above in xml layout file. To get and display system info, see the following code.

src/MainActivity.java


And colors.xml, styles.xml file will look like below;

res/values/colors.xml


res/values/styles.xml


You have done all things. Now, run your application by clicking run button and click Get Android System Info button; you will see all information below the button like the screenshot presented above.

Steppers convey progress through numbered steps. Steppers display progress through a sequence of logical and numbered steps. They may also be used for navigation. Steppers may display a transient feedback message after a step is saved.

This library allows to use Material steppers inside Android applications. Steppers display progress through a sequence by breaking it up into multiple logical and numbered steps.

Types of Steps:
- Editable
- Non-editable
- Mobile
- Optional

Types of Steppers:
- Horizontal
- Vertical
- Linear
- Non-linear

Related:
Android AppIntro Slider Example
Android XML Animations Examples
Android Push Notification Tutorial Using Firebase

Supported features:

Color customisation of individual widgets inside of the stepper via View attributes or a style from a theme
Custom texts of individual widgets inside of the stepper via View attributes or a style from a theme
Embedding the stepper anywhere in the view hierarchy and changing the stepper type for various device configurations, e.g. phone/tablet, portrait/landscape
Step validation
Use with Fragments or Views

Android Material Stepper Library Tutorial and Source Code


Getting started

Android Dependencies:

compile 'com.stepstone.stepper:material-stepper:2.2.0'

Create layout in XML

<?xml version="1.0" encoding="utf-8"?>
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/stepperLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:ms_stepperType="progress_bar" />


Create step Fragment(s)

Step fragments must extend android.support.v4.app.Fragment and implement com.stepstone.stepper.Step

public class StepFragmentSample extends Fragment implements Step {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.step, container, false);

        //initialize your UI

        return v;
    }

    @Override
    public VerificationError verifyStep() {
        //return null if the user can go to the next step, create a new VerificationError instance otherwise
        return null;
    }

    @Override
    public void onSelected() {
        //update UI when selected
    }

    @Override
    public void onError(@NonNull VerificationError error) {
        //handle error inside of the fragment, e.g. show error on EditText
    }

}

Extend AbstractFragmentStepAdapter

AbstractFragmentStepAdapter extends FragmentPagerAdapter but instead of overriding the method getItem(int) you must override the createStep(int) method.

public static class MyStepperAdapter extends AbstractFragmentStepAdapter {

    public MyStepperAdapter(FragmentManager fm, Context context) {
        super(fm, context);
    }

    @Override
    public Fragment createStep(int position) {
        final StepFragmentSample step = new StepFragmentSample();
        Bundle b = new Bundle();
        b.putInt(CURRENT_STEP_POSITION_KEY, position);
        step.setArguments(b);
        return step;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @NonNull
    @Override
    public StepViewModel getViewModel(@IntRange(from = 0) int position) {
        //Override this method to set Step title for the Tabs, not necessary for other stepper types
        return new StepViewModel.Builder(context)
                .setTitle(R.string.tab_title) //can be a CharSequence instead
                .create();
    }
}

Set adapter in Activity

public class StepperActivity extends AppCompatActivity {

    private StepperLayout mStepperLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mStepperLayout = (StepperLayout) findViewById(R.id.stepperLayout);
        mStepperLayout.setAdapter(new MyStepperAdapter(getSupportFragmentManager(), this));
    }
}

Add a StepperListener in the Activity (optional)

public class StepperActivity extends AppCompatActivity implements StepperLayout.StepperListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //...
        mStepperLayout.setListener(this);
    }

    @Override
    public void onCompleted(View completeButton) {
        Toast.makeText(this, "onCompleted!", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onError(VerificationError verificationError) {
        Toast.makeText(this, "onError! -> " + verificationError.getErrorMessage(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStepSelected(int newStepPosition) {
        Toast.makeText(this, "onStepSelected! -> " + newStepPosition, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onReturn() {
        finish();
    }

}

Change Next/Complete button's text color when going to the next step should be disabled (optional)

It is possible to change the Next/Complete button's text color (together with right chevron's color) when all the criteria to go to the next step are not met. This color should indicate that the user cannot go to next step yet and look as if disabled. Clicking on the button will still perform the regular step verification. There is a custom state added since setting android:state_enabled to false in a color selector would disable the clicks and we want to have them so that we can show an info message for the user. In order to set that color:

Create a new color selector in res/color

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
    <item app:state_verification_failed="true" android:color="#30BDBDBD"/>
    <item android:color="@color/ms_white"/>
</selector>

Change button's (text) color in layout file

<?xml version="1.0" encoding="utf-8"?>
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/stepperLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:ms_stepperType="dots"
    app:ms_nextButtonColor="@color/ms_custom_button_text_color"
    app:ms_completeButtonColor="@color/ms_custom_button_text_color" />

Toggle the state in code

mStepperLayout.setNextButtonVerificationFailed(!enabled);
mStepperLayout.setCompleteButtonVerificationFailed(!enabled);
Make an IO operation before going to the next step (optional)

If the user wants to e.g. save something in the database or make a network call on a separate Thread after clicking on the Next button he can perform these operations and then invoke the goToNextStep() method of the StepperLayout.OnNextClickedCallback in the current Step. While operations are performed, and the user would like to go back you can cancel them and then invoke onBackClicked() method of the StepperLayout.OnBackClickedCallback.

The fragment must implement BlockingStep instead of Step. Also, make sure that goToNextStep() gets called on the main thread. Note: the onNextClicked(StepperLayout.OnNextClickedCallback) method gets invoked after step verification. E.g.:

public class DelayedTransitionStepFragmentSample extends Fragment implements BlockingStep {

    //...

    @Override
    @UiThread
    public void onNextClicked(final StepperLayout.OnNextClickedCallback callback) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                callback.goToNextStep();
            }
        }, 2000L);
    }

    @Override
    @UiThread
    public void onBackClicked(StepperLayout.OnBackClickedCallback callback) {
        Toast.makeText(this.getContext(), "Your custom back action. Here you should cancel currently running operations", Toast.LENGTH_SHORT).show();
        callback.goToPrevStep();
     }

}

Changing Back/Next button labels per step

Sometimes you might want to have different labels on the Next and/or Back navigation buttons on different steps e.g. use the default labels on the first few steps, but display 'Summary' just before the last page.


In such case you need to override the getViewModel(int) method from the StepAdapter e.g.

    @NonNull
    @Override
    public StepViewModel getViewModel(@IntRange(from = 0) int position) {
        StepViewModel.Builder builder = new StepViewModel.Builder(context)
                .setTitle(R.string.tab_title);
        switch (position) {
            case 0:
                builder
                        .setNextButtonLabel("This way")
                        .setBackButtonLabel("Go to first");
                break;
            case 1:
                builder
                        .setNextButtonLabel(R.string.go_to_summary)
                        .setBackButtonLabel("Go to first");
                break;
            case 2:
                builder.setBackButtonLabel("Go back");
                break;
            default:
                throw new IllegalArgumentException("Unsupported position: " + position);
        }
        return builder.create();
    }

Using the same stepper styling across the application

If you have many steppers in your application in different activities/fragments you might want to set a common style in a theme. To do so, you need to set the ms_stepperStyle attribute in the theme, e.g.

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        ...

        <item name="ms_stepperStyle">@style/DotStepperStyle</item>
    </style>

and declare that style in the XML you keep your styles at, e.g.

    <style name="DotStepperStyle">
        <item name="ms_stepperType">dots</item>
        <item name="ms_activeStepColor">#FFFFFF</item>
        <item name="ms_inactiveStepColor">#006867</item>
        <item name="ms_bottomNavigationBackground">?attr/colorAccent</item>
    </style>

Showing a Back button on first step

By default if the user is on the first step then the Back button in the bottom navigation is hidden. This behaviour can be changed by setting ms_showBackButtonOnFirstStep to true, e.g.

    <?xml version="1.0" encoding="utf-8"?>
    <com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/stepperLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:ms_showBackButtonOnFirstStep="true"
        app:ms_stepperType="dots" />

To get a callback when this button was pressed you need set a StepperListener and write your own custom return logic in the onReturn() method to e.g. close the Activity.

Using with Views instead of Fragments

It is possible to use this library without the need to rely on Fragments. To do so you need to use AbstractStepAdapter instead of AbstractFragmentStepAdapter. For an example of how to use it with views please see the sample app.

Custom styling

Basic styling can be done by choosing the active and inactive step colors. There are some additional properties which can be changed directly from StepperLayout's attributes e.g. the background of bottom navigation buttons (see StepperLayout attributes) For advanced styling you can use ms_stepperLayoutTheme StepperLayout's attribute and provide your custom style to be used. See 'Custom StepperLayout theme' in the sample app for an example.

Advanced usage

For other examples, e.g. persisting state on rotation, displaying errors, changing whether the user can go to the next step, etc. check out the sample app.

Download Complete Source Code

Github: https://github.com/stepstone-tech/android-material-stepper

If you want use this library, you only have to download MaterialDesign project, import it into your workspace and add the project as a library in your android project settings. This is a library with components of Android L to you use in android 2.2

If you prefer it, you can use the gradle dependency, you have to add these lines in your build.gradle file:

Library Details:

Library Name: Material Design Android Library
Owner: Ivan Navas (navasmdc)
Source Code: https://github.com/navasmdc/MaterialDesignLibrary
Min SDK: 8 (Android 2.2–2.2.3 Froyo)

Related:
Android Material Design GridView
Android Material Design Sliding Tabs Example
Android Swipe Down to Refresh Layout Example

Gradle Dependency

repositories {
    jcenter()
}

dependencies {
    compile 'com.github.navasmdc:MaterialDesign:1.5@aar'
}

Material Design Android Library Example Source Code


Some components have custom attributes, if you want use them, you must add this line in your xml file in the first component:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
</RelativeLayout>

If you are going to use a ScrollView, it is recommended that you use the CustomScrollView provided in this library to avoid problems with the custom components. To use this component:

<com.gc.materialdesign.views.ScrollView
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
   android:id="@+id/scroll"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
</com.gc.materialdesign.views.ScrollView>

Library Components

Buttons


Flat Button

<com.gc.materialdesign.views.ButtonFlat
                android:id="@+id/buttonflat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#1E88E5"
                android:text="Button" />

Rectangle Button


<com.gc.materialdesign.views.ButtonRectangle
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#1E88E5"
                android:text="Button" />

Float Button


It is recommended to put this component in the right-bottom of the screen. To use this component write this code in your xml file. If you don`t want to start this component with animation set the animate attribute to false. Put your icon in the icon attribute to set the drawable icon for this component.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <!-- ... XML CODE -->
    <com.gc.materialdesign.views.ButtonFloat
                android:id="@+id/buttonFloat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="24dp"
                android:background="#1E88E5"
                materialdesign:animate="true"
                materialdesign:iconDrawable="@drawable/ic_action_new" />
</RelativeLayout>


Float small button


<com.gc.materialdesign.views.ButtonFloatSmall
                android:id="@+id/buttonFloatSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#1E88E5"
                materialdesign:iconDrawable="@drawable/ic_action_new" />


Switches


CheckBox

<com.gc.materialdesign.views.CheckBox
                android:id="@+id/checkBox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#1E88E5"
                materialdesign:check="true" />

Switch

<com.gc.materialdesign.views.Switch
                android:id="@+id/switchView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#1E88E5"
                materialdesign:check="true" />

Progress Indicators


Progress bar circular indeterminate


<com.gc.materialdesign.views.ProgressBarCircularIndeterminate
                android:id="@+id/progressBarCircularIndeterminate"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:background="#1E88E5" />

Progress bar indeterminate


<com.gc.materialdesign.views.ProgressBarIndeterminate
                android:id="@+id/progressBarIndeterminate"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#1E88E5" />

Progress bar indeterminate determinate


<com.gc.materialdesign.views.ProgressBarIndeterminateDeterminate
                android:id="@+id/progressBarIndeterminateDeterminate"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#1E88E5" />

If you begin progrees, you only have to set progress it

progressBarIndeterminateDeterminate.setProgress(progress);

Progress bar determinate

<com.gc.materialdesign.views.ProgressBarDeterminate
                android:id="@+id/progressDeterminate"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#1E88E5" />

You can custom max and min progress values with materialdesign:max="50" and materialdesign:min="25" attributes.

Slider


Slider

<com.gc.materialdesign.views.Slider
                android:id="@+id/slider"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#1E88E5"
                materialdesign:max="50"
                materialdesign:min="0"
                 />

Slider with number indicator

<com.gc.materialdesign.views.Slider
                android:id="@+id/slider"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#1E88E5"
                materialdesign:max="50"
                materialdesign:min="0"
                materialdesign:showNumberIndicator="true"/>

Widgets


SnackBar

SnackBar snackbar = new SnackBar(Activity activity, String text, String buttonText, View.OnClickListener onClickListener);
snackbar.show();

If you don't want to show the button, put null in buttonText attribute

Dialog


Dialog

Dialog dialog = new Dialog(Context context,String title, String message);
dialog.show();

You can set the accept and cancel button on the event listener or change it's text

// Set accept click listenner
dialog.setOnAcceptButtonClickListener(View.OnClickListener onAcceptButtonClickListener);

// Set cancel click listenner
dialog.setOnCancelButtonClickListener(View.OnClickListener onCancelButtonClickListener);

// Acces to accept button
ButtonFlat acceptButton = dialog.getButtonAccept();

// Acces to cancel button
ButtonFlat cancelButton = dialog.getButtonCancel();

Color selector

ColorSelector colorSelector = new ColorSelector(Context context,int intialColor, OnColorSelectedListener onColorSelectedListener);
colorSelector.show();

TouchListener that can be attached to any RecyclerView and handles multi selection for you. It's a simple one class TouchListener that can be attached to any RecyclerView and handles multi selection in google photos style via long pressing on an item and moving the finger up/down to select more items (it even scrolls if you reach the edges of the RecyclerView)


Related:


Library Details:


Name: DragSelectRecyclerView 
Owner: MFlisar
Source: Download Full Library Source Code From GitHub

Gradle (via JitPack.io)


1. Add jitpack to your project's build.gradle:

repositories {
    maven { url "https://jitpack.io" }
}

2. Add the compile statement to your module's build.gradle:

dependencies {
    compile 'com.github.MFlisar:DragSelectRecyclerView:0.2'
}

Usage

Create the a touch listener like following

mDragSelectTouchListener = new DragSelectTouchListener()
    .withSelectListener(new DragSelectTouchListener.OnDragSelectListener() {
        @Override
        public void onSelectChange(int start, int end, boolean isSelected) {
            // update your selection
            // range is inclusive start/end positions
        }
    })

Following is all optional

    .withMaxScrollDistance(distance)    // default: 16;     defines the speed of the auto scrolling

    .withTopOffset(toolbarHeight)       // default: 0;      set an offset for the touch region on top of the RecyclerView

    .withBottomOffset(toolbarHeight)    // default: 0;      set an offset for the touch region on bottom of the RecyclerView

    .withScrollAboveTopRegion(enabled)  // default: true;   enable auto scrolling, even if the finger is moved above the top region

    .withScrollBelowTopRegion(enabled)  // default: true;   enable auto scrolling, even if the finger is moved below the top region

    .withDebug(enabled);                // default: false;
attach it to the RecyclerView

recyclerView.addOnItemTouchListener(mDragSelectTouchListener);

On item long press, inform the listener so that it can start doing it's magic

// if one item is long pressed, we start the drag selection like following:
// we just call this function and pass in the position of the first selected item
mDragSelectTouchListener.startDragSelection(position);

TODO

support horizontal RecyclerViews... should be quite simple, but is not yet implemented

In android, you can easily download any files or images from internet/URL. There are many ways to download images from internet and in this tutorial you will learn one of the easiest ways to download image from internet. Showing download progress derives a good user experience. So in this tutorial, you will also learn to display a progress bar that runs when the app downloads an image or files from the web.

Once the image is completely downloaded, the progress bar is disabled and the downloaded image is shown in an image view.

Related:
Load Image from URL (Internet) in Android
How to Pick an Image From SD Card Gallery and Display in Android App
Display Images in Android GridView

Creating New Android Project

Downloading File or Image and Displaying in Android

Let’s start by creating new android project with com.viralandroid.androiddownloadingfile package name and Android Downloading File as project name.

XML Layout File

Open your main XML layout file and add a button to download file or image when button is clicked. And also add an ImageView to show downloaded image. Don’t forget to give an id to both Button and ImageView. Your XML layout file will look like below.

res/layout/activity_main.xml


Java Activity File

In main activity class, you need to implement necessary classes and buttons. Progress dialog can be shown using ProgressDialog class which is a subclass of normal AlertDialog class.

Also you need to add Async background thread to download file from web/URL. Add asynctask class and name it as DownloadFromURL and extend AsyncTask in your main activity.

After downloading image from internet, read the downloaded image from the sdcard and display it in an image view.

Following is the complete code of java activity file.

src/MainActivity.java


Adding Internet and Writing to SdCard Permission

Before running your project, open your AndroidManifest.xml file and add android.permission.INTERNET and android.permission.WRITE_EXTERNAL_STORAGE. Your AndroidManifest.xml file will look like below.

Downloading File or Image and Displaying in AndroidDownloading File or Image and Displaying in Android



AndroidManifest.xml


Now, run your app by clicking Run button. Make sure you have internet connection to download image or file from web URL. Click the download button; you will see the progress bar with download progress in percentage. After download is completed, the downloaded image is shown in the ImageView, below the download button.

Android allows you to connect your android app to facebook. You can connect your app to facebook and share data or any other updates on facebook. By connecting app to facebook you can use facebook login, account kit, share and send dialog, app event, graph API, etc. In this tutorial you will learn to integrate facebook in android app using Android Studio and add login using facebook SDK.

The Facebook SDK is very easy to integrate in your Android app with Facebook. There are two different ways to integrate facebook and share something from your app – Facebook SDK and Intent Share.

Releted:
Integrating Google Firebase Analytics to your Android Project
How to Integrate Google AdMob in Android
Google Maps Android API Getting Started Tutorial : Part 1

Android Example: Integration Facebook Login in Android Using Android Studio


Let’s start by creating new android project using Android Studio or you can use any other development environment like eclipse to integrate facebook login in android app/game. Create new project with project name: Facebook Integration Android and minimum API 15: Android 4.0.3.

Facebook Integration in Android - Facebook Login


Create New Facebook App


Open facebook developer site developers.facebook.com . Open MyApp tab and click on the Add a New App. Here you need to fill up app information like name, contact email, app category etc. and click Create App Id button.


In Product Setup (Add Product) page click Facebook Login Get Started button. Enable Client OAuth Login, Web OAuth Login, Embedded Browser OAuth Login, Force Web OAuth Reauthentication and click Save Changes button.

From fb app dashboard click Choose Platform button and select Android.


Generate Android Hash Key


Now you need to get key hash value for your app. The key hash value is used by facebook as security check for login. To get hash key for your app, follow the following steps:

1. Open command prompt (Terminal)
2. Run the following command:
keytool -exportcert -alias androiddebugkey -keystore C:\Program Files\Java\jdk1.8.0_25\bin\debug.keystore | C:\OpenSSL\bin\openssl sha1 -binary | C:\OpenSSL\bin\openssl base64

Make sure you have installed jdk and OpenSSL in your PC and replace C:\Program Files\Java\jdk1.8.0_25\bin with your jdk bin directory and C:\OpenSSL\bin with your OpenSSL bin directory.


Now you will get hash key something like 2jmj7w0yVb/vlkK/YBwk= copy it.

Go to facebook developer page and select your app. From setting section click Add Platform and choose Android.

Here you need to provide more information about app like app package name, class name, hash key that we have generated above and so on. Add these information, enable Single Sign On and click Save Changes button.

Google Play Package Name: com.viralandroid.facebookandroidintegration
Class Name: com.viralandroid.facebookandroidintegration.MainActivity
Key Hashes: 2jmj7w0yVb/vlkK/YBwk=

From App Review section enable Make Android Integration public.

Add Repositories and Compile Dependency


Open module build.gradle file from android studio. Add repositories {mavenCentral()} and compile 'com.facebook.android:facebook-android-sdk:[4,5)' as dependency and build your project. Build.gradle file will look like below.
Module:build.gradle


Add Facebook App ID


Open your app strings.xml file, /app/src/main/res/values/strings.xml. Add a new string with the name facebook_app_id containing the value of your Facebook App ID. Strings.xml file will look like below.

res/values/strings.xml


Update your Android Manifest File


Open AnddroidManifest.xml file and add a user-permission and meta-data element. Android manifest file will look like this.

AndroidManifest.xml


Android XML Layout File


Open activity_main.xml file and add a TextView and facebook LoginButton widget. This XML layout file will look like this.

res/layout/activity_main.xml



Modify Java Activity File


In your java activity file, add callbackManager and onActivityResult. Following is the complete content of java activity file.

src/MainActivity.java


Now run your application by clicking Run icon from toolbar. Make sure you have connected your android device with computer and internet. Above are the screenshots of this example project.

JSON stand for JavaScript Object Notation. It is a minimal, readable, format for structuring data. JSON is an independent data transmit between a server and application and is the best alternative for XML. It represents data in a text format so that can be easily parsed. In this android JSON data parsing tutorial you will learn to parse the response in order to get the required information in android app.

Android provide different classes to manipulate JSON data, they are JSONArray, JSONStringer, JSONObject and JSONTokenizer. An JSON file have many components like Array([), Objects({), Key and Value.

Related:
Android Push Notification Tutorial Using Firebase
YouTube Android API Integration: Getting Started with YouTube Android API
Turn ON and OFF WiFi Connection Programmatically in Android


JSON Parsing Android Tutorial with Example


Let’s create new android project called Android JSON Data Parsing Example to parse JSON data from web server to android app.

Android JSON Data Parsing Tutorial with Example

Following is the simple JSON data that we parse in android app. This JSON gives list of contact information.


This JSON data can be found at: https://api.myjson.com/bins/31b8v

Adding Internet Permission


We are getting JSON data from server, so we need to add internet permission in our project AndroidManifest.xml file. Just open AndroidManifest.xml file and add android.permission.INTERNET permission. AndroidManifest.xml file will looks like below.

AndroidManifest.xml


XML Layout File


Open your activity_main.xml file and add ListView with an id to display JSON data in list view. Following is the content of activity_main.xml file.
res/activity_main.xml


Again create a new XML layout file list_item.xml and add three TextView vertically with id, textColor, textStyle, textSize, etc. Following is the complete content of list_item.xml file.
res/list_item.xml


Http Handler Class


Create a new java class HttpHandler.java and add the following java code.
src/HttpHandler.java


Modify MainActivity.java File


Open your MainActivity.java file and replace it with following code.
src/MainActivity.java


Now run your application, which looks like above screenshot. After running your app, you will see name, email address, and phone number in ListView. You can change these information according to your requirement. Remember to turn on the Internet connection on your device either WiFi or mobile data, because we have loading JSON data from internet.
Powered by Blogger.