Java LinkedIn OAuth2 get access token

Pass the appropriate arguments and get authetication token.

private String getLinkedInAccessToken(String authorizationCode, String clientId, String clientSecret, String redirectUri, HttpServletResponse hsr) throws Exception {
        String accessToken = "";
        try {
         
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpGet getRequest = new HttpGet(
                    "https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&client_id="
                            + clientId + "&client_secret=" + clientSecret + "&code=" + authorizationCode + "&redirect_uri="
                            + redirectUri);
            getRequest.addHeader("oauth2_access_token", code);
            HttpResponse response = httpClient.execute(getRequest);

            if (response.getStatusLine().getStatusCode() != 200) {
                ExceptionWriter.showMsg(hsr, "Error in get access token\n" + "Request Status Code: "+
                        response.getStatusLine().getStatusCode());
                throw new Exception("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
            }
            BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            StringBuilder sb = new StringBuilder();
            String output;

            while ((output = br.readLine()) != null) {
                sb.append(output);
            }
            br.close();
            LOGGER.info("JSON Object" + sb);

            JSONObject jsonObject = new JSONObject(sb.toString());
            accessToken = jsonObject.getString("access_token");

            httpClient.getConnectionManager().shutdown();

        } catch (IOException | JSONException e) {
        }
        return accessToken;
    }

Include required jars in your project to run this method.

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.JSONValue;
-----
-----
etc

Java get MAC address of Computer

    /**
     * This method get the MAC address of a computer
     *
     * @return string of MAC address of computer
     */
    public static String getMacAddres() {
        String macAddress = "";
        try {
            for (Enumeration<NetworkInterface> enm = NetworkInterface.getNetworkInterfaces(); enm.hasMoreElements();) {
                NetworkInterface network1 = (NetworkInterface) enm.nextElement();
                if (null != network1.getHardwareAddress()) {
                    byte[] mac = new byte[50];

                    mac = network1.getHardwareAddress();

                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < mac.length; i++) {
                        sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
                    }

                    macAddress = sb.toString();
                }
            }
        } catch (SocketException e) {
            // e.printStackTrace();
        }

        return macAddress;
    }

Java get Taskbar height

    public static int getTaskbarHeight(Component comp) {
        int heightOfTaskbar = 0;
        try {
            Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(comp.getGraphicsConfiguration());
            heightOfTaskbar = scnMax.bottom;
        } catch (Exception e) {

        }
        return heightOfTaskbar;
    }

Java Resize Images

package com.bospp;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import org.imgscalr.Scalr;

public class ImageResize {

    public static void createResizedImage(String imageActualPath, String imagetargetPath, int imgWidth, int imgHeight) {
        try {
            BufferedImage originalImage = ImageIO.read(new File(imageActualPath));
            BufferedImage resizeImagePng = Scalr.resize(originalImage, imgWidth);

            File file = new File(imagetargetPath);
            file.getParentFile().mkdirs();
            String fileName = file.getName();
            String fileExtention = fileName.contains(".")
                    ? fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()) : "png";
            ImageIO.write(resizeImagePng, fileExtention, file);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void createDir(String fileDirStr) {
        File fileDir = new File(fileDirStr);
        if (!fileDir.exists() && !fileDir.mkdirs()) {
            System.out.println("Can't create directory. Check permissions");
        }
    }
   
    public static void main(String args[]){
        createResizedImage("/home/rahul/Documents/assets/photo.jpg", "/home/rahul/Documents/assets/yes.jpg", 100, 100);
    }
}

ionic change android class name

You have to follow following steps:

1. Change in AndroidMnifest.xml

<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="SoftwareCostEstimation" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">

2. Change in build.xml

<project name="SoftwareCostEstimation" default="help">

3. Change the name of file and class name

Change the CordovaApp.java to SoftwareCostEstimation.java

and don't forget to change the name of class like:

public class SoftwareCostEstimation extends CordovaActivity

Run ionic build android

Doing this your generated apk name will be changed according to project name.