Category: Android

Android is a mobile operating system based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. Android is developed by a consortium of developers known as the Open Handset Alliance and commercially sponsored by Google. It was unveiled in November 2007, with the first commercial Android device, the HTC Dream, being launched in September 2008.

  • The application could not be installed: INSTALL_FAILED_MISSING_SHARED_LIBRARY

    The application could not be installed: INSTALL_FAILED_MISSING_SHARED_LIBRARY

    This could happen if you have two entries like in your AndroidManifest.xml. If you choose File -> New -> Activity -> Blank Activity this gets included in manifest file automatically. If you are not building for wearable you can delete this from manifest file or add missing library in build.gradle (app)

    <uses-library
        android:name="com.google.android.wearable"
        android:required="true" />
    <!--
           Set to true if your app is Standalone, that is, it does not require the handheld
           app to run.
    -->
    <meta-data
        android:name="com.google.android.wearable.standalone"
        android:value="true" />

    This could also happen when your app expecting a library which is not installed yet. Please update your build.gradle for any missing library.

    Spread the love
  • Volley json post request android

    Volley json post request android

    Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. Volley is available on GitHub.

    Find your build.gradle (app) add this under dependencies

    implementation 'com.android.volley:volley:1.2.0'

    Create a singleton class to manage all requests

    import android.content.Context;
    
    import com.android.volley.Request;
    import com.android.volley.RequestQueue;
    import com.android.volley.toolbox.Volley;
    
    public class AppHttp {
        private static AppHttp instance;
        private RequestQueue requestQueue;
        private static Context ctx;
    
        private AppHttp(Context context) {
            ctx = context;
            requestQueue = getRequestQueue();
        }
    
        public static synchronized AppHttp getInstance(Context context) {
            if (instance == null) {
                instance = new AppHttp(context);
            }
            return instance;
        }
    
        public RequestQueue getRequestQueue() {
            if (requestQueue == null) {
                // getApplicationContext() is key, it keeps you from leaking the
                // Activity or BroadcastReceiver if someone passes one in.
                requestQueue = Volley.newRequestQueue(ctx.getApplicationContext());
            }
            return requestQueue;
        }
    
        public <T> void addToRequestQueue(Request<T> req) {
            getRequestQueue().add(req);
        }
    }

    Create your POST request

    AppHttp requestQueue = AppHttp.getInstance(this);
    JSONObject postData = new JSONObject();
        try {
            postData.put("email", email);
            postData.put("password", password);
    
        } catch (JSONException e) {
            e.printStackTrace();
        }
    
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, "http://api.com/login", postData, new Response.Listener<JSONObject>() {
    
            @Override
            public void onResponse(JSONObject response) {
                Log.e("login response: ", response.toString());
                try {
                    // Retrieve user information and take user to next activity
                   // after successful login
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("login error: ", error.toString());
                    error.printStackTrace();
    
                    // show user login error with a Toast
                }
            }
        ) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("Accept", "application/json;charset=utf-8");
                params.put("Content-Type", "application/json;charset=utf-8");
    
                return params;
            }
        };
    
        requestQueue.addToRequestQueue(jsonObjectRequest);
    }
    Spread the love