Monday 16 July 2018

JSON PARSING

 

Android working with and Recycler View And JSON PARSING API IMPLEMENT Process.





package xyz;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;

public class Json_Obect extends AppCompatActivity {
    private Context mContext;
    RecyclerView my_list;
    List_Adapter gridViewAdapter;

    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.json_object);

        mContext = Json_Obect.this;

        initiView();
        Get_CardApi();

    }

    private void initiView() {
        my_list = findViewById(R.id.my_list);
    }

    private void Get_CardApi() {

        String Url = "xyz";
        // showProgressDialog("Please wait...");        if (NetworkUtil.isNetworkAvailable(mContext)) {
            // POST parameters            Map<String, String> params = new HashMap<String, String>();

           /* params.put("dsaCode", dsa_number);            JSONObject jsonObj = new JSONObject(params);            // Request a json response from the provided URL            JsonObjectRequest jsonObjRequest = new JsonObjectRequest(Request.Method.POST, Url, jsonObj, new Response.Listener<JSONObject>() {*/
            // Request a json response from the provided URL            JsonObjectRequest jsonObjRequest = new JsonObjectRequest(Request.Method.GET, Url, new Response.Listener<JSONObject>() {
                @Override                public void onResponse(JSONObject response) {
                    Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_SHORT).show();

                    String msg = response.toString();
                    //  Utils.showToast(mContext, msg);                    JSONObject json = response;
                    System.out.println(response);
                    if (json.has("contacts")) {
                        try {
                            JSONArray data = json.getJSONArray("contacts");
                            HashMap<String, String> list = new HashMap<String, String>();
                            //removeProgressDialog();
                            if (data.length() > 0) {
                                gridViewAdapter = new List_Adapter(mContext, data);
                                RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
                                // RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(), 2);                                my_list.setLayoutManager(mLayoutManager);
                                // my_list.setItemAnimator(new DefaultItemAnimator());                                my_list.setAdapter(gridViewAdapter);
                            } else {
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();

                        }
                    }
                }
            },
                    new Response.ErrorListener() {
                        @Override                        public void onErrorResponse(VolleyError error) {
                            //removeProgressDialog();                            {
                                Toast.makeText(mContext, "Api Error, Please try again " + error.getMessage(), Toast.LENGTH_SHORT).show();

                            }
                        }

                    }) {
                @Override                public Map<String, String> getHeaders() throws AuthFailureError {
                    Map<String, String> params = new HashMap<String, String>();
                   /* String Token = new GetProfileDetails(mContext).getToken();                    String auth = "Bearer " + Token;                    params.put("Authorization", auth);*/                    return params;
                }
            };
            // Add the request to the RequestQueue.            RequestQueue requestQueue = Volley.newRequestQueue(this);
            requestQueue.add(jsonObjRequest);

        }
    }
}








package XYZ;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;

public class List_Adapter extends RecyclerView.Adapter<List_Adapter.MyViewHolder> {
    private JSONArray kyc_List;
    private Context mContext;

    public List_Adapter(Context mcontext, JSONArray kycList) {
        this.mContext = mcontext;
        this.kyc_List = kycList;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        TextView name, email, mobile;


        public MyViewHolder(final View v) {
            super(v);

            name = v.findViewById(R.id.name);
            email = v.findViewById(R.id.email);
            mobile = v.findViewById(R.id.mobile);

        }
    }

    @Override    public List_Adapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.listview, parent, false);

        return new List_Adapter.MyViewHolder(itemView);
    }

    @Override    public void onBindViewHolder(final List_Adapter.MyViewHolder holder, final int position) {
        try {
            final RecyclerView.ViewHolder holder1 = holder;
            kyc_List.getJSONObject(position);
            //String text_Name = kyc_List.getJSONObject(position).optString("name").toString();            String text_Email = kyc_List.getJSONObject(position).optString("email").toString();
            String text_Mobile = kyc_List.getJSONObject(position).optString("address").toString();

            holder.name.setText("Andrew PJ");
            holder.email.setText(text_Email);
            holder.mobile.setText(text_Mobile);

            //  holder.text_des.setText(kyc_List.getJSONObject(position).optString("descriptions").toString());
           /* if (!Imgurl.equals("") && Imgurl != null) {
                Utils.loadImage(holder.productIcon, Imgurl, mContext, R.drawable.ic_profile_img);            }*/

        } catch (JSONException e) {
            e.printStackTrace();

        }

    }


    @Override    public int getItemCount() {
        return kyc_List.length();
    }

}



package XYZ;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;


public class NetworkUtil {

    public static boolean isNetworkAvailable(Context context) {
        boolean value = false;


        ConnectivityManager manager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = manager.getActiveNetworkInfo();
        //       /* NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        boolean isWifiConn = networkInfo.isConnected();        networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);        boolean isMobileConn = networkInfo.isConnected();*/        //        if (info != null && info.isAvailable()) {
            value = true;
            Log.d("Is network available", String.valueOf(value));

        } else {
          

        }

        return value;
    }

}

Monday 11 July 2016

Android Intriew Question

(1) What is Android ? 

 Ans:- Android is an open-source, Linux-based operating system that is used in mobiles, tablets, televisions etc. 


(2) Who is the founder of Android ?

Andy Rubin. 


3) What are the code names of android? 


1. Aestro 2. Blender 3. Cupcake 4. Donut 5. Ã‰clair 6. Fro yo 7. Gingerbread 8. Honeycomb 9. Ice Cream Sandwich 10. Jelly Bean 11. Kitkat 



(4) What are the advantages of android? 


Ans:-Open-source: It means no licence, distribution and development fee. Platform-independent: It supports windows, mac and Linux platforms. Supports various technologies: It supports camera, bluetooth, wifi, speech, EDGE etc. technologies. Highly optimized Virtual Machine: Android uses highly optimized virtual machine for mobile devices, called DVM (Dalvik Virtual Machine).



(5) Does android support other language than java?


Ans:-Yes, android app can be developed in C/C++ also using android ND K (Native Development Kit). It makes the performance faster. It should be used with android SDK. 



(6) What are the core building blocks of android? 


Ans:-The core building blocks of android are: • Activity • View • Intent • Service • Content Provider • Fragment etc


.(7)What is Activity ?


Ans:-Activity is a single screen in supporting java code that is called a activity


  (9) What is view in android ? 


Ans:- A view is it the UI element such as button label tablet etc Anything that you see is a view. 



(10)What is Intent ?


Ans:- Notification message to the user from android embed device can be display using intent that is called a intent. ?



(11)What is  Service


 Ans:-A service is a background process process that can run for a long time that is call a service .There are two types of services local and remote. Local service is accessed from within the application whereas remote service is accessed remotely from other applications running on the same device.


(10)What is Fragment ?


Ans: Ans-Fragment is a part of Activity by the help of fragment, we can display multiple screen on one activity that is call a fragment .



(12) What is Content Provider?


Ans:-Content Provider or used to share data between the applications, that is called a content Provider.

(13) What are the code names of android?

    Aestro
    Blender
    Cupcake
    Donut
    Eclair
    Froyo
    Gingerbread
    Honycomb
    Ice Cream Sandwitch
    Jelly Bean
    Kitkat
    Lollipop
    Marshmallow

 (14) What is the name of database used in android?

 Ans :-SQLite: An opensource and lightweight relational database for mobile devices.

 

15) What is AAPT?


AAPT is an acronym for android asset packaging tool. It handles the packaging process.
16) What is content provider?

Content providers are used to share information between android applications.
 

(17) What is fragment?

Fragment is a part of Activity. By the help of fragments, we can display multiple screens on one activity.
 

(18) What is ADB?

ADB stands for Android Debug Bridge. It is a command line tool that is used to communicate with the emulator instance.


(19) What is NDK?

NDK stands for Native Development Kit. By using NDK, you can develop a part of app using native language such as C/C++ to boost the performance.
 

20) What is ANR?
ANR stands for Application Not Responding. It is a dialog box that appears if the application is no longer responding.
 

(21) What is DDMS?

DDMS stands for Dalvik Debug Monitor Server. It gives the wide array of debugging features:

    Port forwarding services
    Screen capture
    Thread and heap information
    Network traffic tracking
    Location data spoofing

(22) Define Android Architecture?

Android architecture consists of 4 components:

    Linux Kernal
    Libraries
    Android Framework
    Android Applications


(23) What is a portable wi-fi hotspot?

The portable wi-fi hotspot is used to share internet connection to other wireless devices. 

(24) Name the dialog box which are supported by android?

    Alert Dialog
    Progress Dialog
    Date Picker Dialog
    Time picker Dialog

(25) Name some exceptions in android?

    Inflate Exception
    Surface.OutOfResourceException
    SurfaceHolder.BadSurfaceTypeException
    WindowManager.BadTokenException

(26) What are the basic tools used to develop an android app?

    JDK
    Eclipse+ADT plugin
    SDK Tools

(27) What are the advantages of android?

Open-source: It means no licence, distribution and development fee.

Platform-independent: It supports windows, mac and linux platforms.

Supports various technologies: It supports camera, bluetooth, wifi, speech, EDGE etc. technologies.

Highly optimized Virtual Machine: Android uses highly optimized virtual machine for mobile devices, called DVM (Dalvik Virtual Machine).
 

(28) Does android support other language than java?

Yes, android app can be developed in C/C++ also using android NDK (Native Development Kit). It makes the performance faster. It should be used with android SDK.
 

(29) What are the core building blocks of android?

The core building blocks of android are:

    Activity
    View
    Intent
    Service
    Content Provider
    Fragment etc.


(30) What is activity?

Activity is like a frame or window in java that represents GUI. It represents one screen of android.
 

(31) What are the life cycle methods of android activity?

There are 7 life-cycle methods of activity. They are as follows:

    onCreate()
    onStart()
    onResume()
    onPause()
    onStop()
    onRestart()
    onDestroy()

(32) What is intent?

It is a kind of message or information that is passed to the components. It is used to launch an activity, display a web page, send sms, send email etc. There are two types of intents in android:

    Implicit Intent
    Explicit Intent


(33) What is implicit intent in android?

Implicit intent is used to invoke the system components.

(34) What is explicit intent in android?

Explicit intent is used to invoke the activity class.

(35) How to call another activity in android?

    Intent i = new Intent(getApplicationContext(), ActivityTwo.class); 
    startActivity(i); 

(36) What is the APK format?

The Android packaging key is compressed with classes,UI's, supportive assets and manifest.All files are compressed to a single file is called APK.
 

(37) What is An android manifest file?
Ans :- Android manifest .xml Application recource file and other file a project complie into a single activity file.

Saturday 17 October 2015

Activity LifeCycle in Android


Android Architecture :-



Linux Kernel:
Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.

Android  Runtime:
Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.
Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool.
The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.
Libraries:
Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. Some of the core libraries are listed below:
·       Free Type: This library supports bitmap and vector font rendering.
·       Libc: This library is a BSD-derived implementation of standard c system library, tuned for embedded linux-based devices.
·       LibWebCare: This library offers a modern and fast web browser engine that powers the Android browser and an embedded web view . Its based on WebKit and is also used by the Google Chrome and Apple Safari browsers.
·       Media Framework: These libraries ,which are based on packet video’s OpenCORE , support the playback and recording of many  popular audio and video formats, as well as working with static image files.
·       OpenGL/ES: These 3D Graphics libraries provide an OpenGL implementation based on OpenGL/ES 1.0 APIs.
·       SGL: This library provides the underlying 2D Graphics engine.
·       SQLite: This library provides a powerful and lightweight relational database engine that’s available for all app’s and also used by Mozilla Firefox and Apple’s iPhone for persistent storage.
·       SSL: This library provides secure sockets layer-based (SSL-based) security for network communication.
·       Surface Manager: This library manages access to the display subsystem , and seamlessly composites 2D and 3D graphic layers from multiple apps.
Application Framework:
By providing an open development platform, Android offers developers the ability to build extremely rich and innovative applications. Developers are free to take advantage of the device hardware, access location information, run background services, set alarms, add notifications to the status bar, and much, much more.Developers have full access to the same framework APIs used by the core applications. The application architecture is designed to simplify the reuse of components; any application can publish its capabilities and any other application may then make use of those capabilities (subject to security constraints enforced by the framework). This same mechanism allows components to be replaced by the user.
Underlying all applications is a set of services and systems, including:
·       A rich and extensible set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser
·       Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data
·       A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files
·       A Notification Manager that enables all applications to display custom alerts in the status bar
·       An Activity Manager that manages the lifecycle of applications and provides a common navigation backstack

 Application
Android will ship with a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, and others. All applications are written using the Java programming language.

 Building Blocks of Android

Application Components

 Main  Building blocks are components that you use as an application developer to build Android apps.
  Application Components are the essential building blocks of an Android application. Each component is a different point through which the system can enter your application. Not all components are actually entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role-each one is a unique building block that helps define your application’s overall behaviour.
There are four different types of application components.
·      Activities:-
·      Services:-
·      Content Providers:-
·      Broadcast Receivers:-