Example usage for android.util Log i

List of usage examples for android.util Log i

Introduction

In this page you can find the example usage for android.util Log i.

Prototype

public static int i(String tag, String msg) 

Source Link

Document

Send an #INFO log message.

Usage

From source file:Main.java

/**
 * Create a URL from an API call (or "action string")
 *//*from   w  w w. j a va  2s.c o m*/
public static String getPageURL(String call) {
    Log.i("Jarvis", String.format("Call: %s", call));

    // Call's parts
    String function = "";
    String action = "";
    String data = "";

    // Final URL
    String url = "";
    Boolean isInternal = true;

    // This is weird left-over support for external URLs
    // Check if this is not a Jarvis URL
    if (call.length() >= 4 && call.substring(0, 4).equals("http")) {
        Integer length = API_ROOT.length();
        if (call.substring(0, length).equals(API_ROOT)) {
            call = call.substring(length + 1);
            call = call.replace("/", " ");
        } else {
            url = call;
            isInternal = false;
        }
    }

    if (isInternal) {
        // Encode URI data
        Pattern pattern = Pattern.compile(" ");
        String[] parts = pattern.split(call, 3);
        function = Uri.encode(parts[0]);
        if (parts.length > 1) {
            action = Uri.encode(parts[1]);
        }
        if (parts.length > 2) {
            data = Uri.encode(parts[2]);
        }

        // Final format
        url = String.format("%s/api/%s/%s/%s", API_ROOT, function, action, data);
    }

    Log.d("Jarvis", String.format("URL: %s", url));

    return url;
}

From source file:Main.java

private static Object getValue4Field(Object orginalValue, String typeName) {
    Log.i("YunMing", typeName);
    Object value = orginalValue.toString();
    if (typeName.equals(BYTE) || typeName.equals(VALUE_BYTE)) {
        value = Byte.class.cast(orginalValue);
    }//from w ww  .j  ava 2 s . co m
    if (typeName.equals(INTEGER) || typeName.equals(VALUE_INTEGER)) {
        value = Integer.class.cast(orginalValue);
    }
    if (typeName.equals(SHORT) || typeName.equals(VALUE_SHORT)) {
        value = Short.class.cast(orginalValue);
    }
    if (typeName.equals(LONG) || typeName.equals(VALUE_LONG)) {
        value = Long.class.cast(orginalValue);
    }
    if (typeName.equals(BOOLEAN) || typeName.equals(VALUE_BOOLEAN)) {
        value = Boolean.class.cast(orginalValue);
    }
    if (typeName.equals(CHAR) || typeName.equals(VALUE_CHAR)) {
        value = Character.class.cast(orginalValue);
    }
    if (typeName.equals(FLOAT) || typeName.equals(VALUE_FLOAT)) {
        value = Float.class.cast(orginalValue);
    }
    if (typeName.equals(DOUBLE) || typeName.equals(VALUE_DOUBLE)) {
        value = Double.class.cast(orginalValue);
    }
    return value;
}

From source file:Main.java

public static void LOGI(final String text) {
    Log.i(LOG_TAG, text);
}

From source file:Main.java

public static String getHostIP() {
    String hostIp = null;/*from  w  ww . j  ava 2s  .c  o  m*/
    try {
        Enumeration nis = NetworkInterface.getNetworkInterfaces();
        InetAddress ia = null;
        while (nis.hasMoreElements()) {
            NetworkInterface ni = (NetworkInterface) nis.nextElement();
            Enumeration<InetAddress> ias = ni.getInetAddresses();
            while (ias.hasMoreElements()) {
                ia = ias.nextElement();
                if (ia instanceof Inet6Address) {
                    continue;// skip ipv6
                }
                String ip = ia.getHostAddress();
                if (!"127.0.0.1".equals(ip)) {
                    hostIp = ia.getHostAddress();
                    break;
                }
            }
        }
    } catch (SocketException e) {
        Log.i("yao", "SocketException");
        e.printStackTrace();
    }
    return hostIp;

}

From source file:Main.java

public static void killProcesses(Context context, int pid, String processName) {

    String cmd = "kill -9 " + pid;
    String Command = "am force-stop " + processName + "\n";
    Process sh = null;//from   w ww  . j  a v  a  2 s . co  m
    DataOutputStream os = null;
    try {
        sh = Runtime.getRuntime().exec("su");
        os = new DataOutputStream(sh.getOutputStream());
        os.writeBytes(Command + "\n");
        os.writeBytes(cmd + "\n");
        os.writeBytes("exit\n");
        os.flush();

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

    try {
        sh.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    // AbLogUtil.d(AbAppUtil.class, "#kill -9 "+pid);
    Log.i("AppUtil", processName);
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    String packageName = null;
    try {
        if (processName.indexOf(":") == -1) {
            packageName = processName;
        } else {
            packageName = processName.split(":")[0];
        }

        activityManager.killBackgroundProcesses(packageName);

        //
        Method forceStopPackage = activityManager.getClass().getDeclaredMethod("forceStopPackage",
                String.class);
        forceStopPackage.setAccessible(true);
        forceStopPackage.invoke(activityManager, packageName);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static boolean isExternalStorageWriteable() {
    boolean writealbe = false;
    long start = System.currentTimeMillis();
    if (TextUtils.equals(Environment.MEDIA_MOUNTED, Environment.getExternalStorageState())) {
        File esd = Environment.getExternalStorageDirectory();
        if (esd.exists() && esd.canWrite()) {
            File file = new File(esd, ".696E5309-E4A7-27C0-A787-0B2CEBF1F1AB");
            if (file.exists()) {
                writealbe = true;/*  ww w . jav a  2  s . c o  m*/
            } else {
                try {
                    writealbe = file.createNewFile();
                } catch (IOException e) {
                    Log.w(TAG, "isExternalStorageWriteable() can't create test file.");
                }
            }
        }
    }
    long end = System.currentTimeMillis();
    Log.i(TAG, "Utility.isExternalStorageWriteable(" + writealbe + ") cost " + (end - start) + "ms.");
    return writealbe;
}

From source file:Main.java

/**
 * Get resource ID from extra or from metadata.
 * // www .  j  a  v a  2  s  .co m
 * @param context
 * @param packagename
 * @param intent
 * @param extra
 * @param metadata
 * @return
 */
public static int getResourceIdExtraOrMetadata(final Context context, final String packagename,
        final Intent intent, final String extra, final String metadata) {
    if (intent.hasExtra(extra) && intent.getStringExtra(extra) != null) {

        int id = 0;
        try {
            String resourcename = intent.getStringExtra(extra);
            Resources resources = context.getPackageManager().getResourcesForApplication(packagename);
            Log.i(TAG, "Looking up resource Id for " + resourcename);
            id = resources.getIdentifier(resourcename, "", packagename);
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Package name not found", e);
        }
        return id;
    } else {
        //Try meta data of package
        Bundle md = null;
        try {
            md = context.getPackageManager().getApplicationInfo(packagename,
                    PackageManager.GET_META_DATA).metaData;
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Package name not found", e);
        }

        if (md != null) {
            // Obtain resource ID and convert to resource name:
            int id = md.getInt(metadata);

            return id;
        } else {
            return 0;
        }

    }
}

From source file:com.cssweb.android.service.ZixunService.java

/**
 * ??/*from   w  ww.j  a v  a2  s  .  c  o m*/
 * @param userType
 * @param custid
 * @return 
 * @throws JSONException 
 */
public static int getUserLevel(String userType, String custid) throws JSONException {
    StringBuffer sb = new StringBuffer();
    sb.append(Config.roadZixun);
    sb.append("iphone/login/Login/getTradUserCustLevel.do?");
    sb.append("&userType=");
    sb.append(userType);
    sb.append("&clientNo=");
    sb.append(custid);
    Log.i("KKK", sb.toString() + ">>>>>");
    String s = Conn.getUserLevel(sb.toString());
    Log.i("##########", s + ">>>>>>>>");
    if (null != s) {
        JSONObject j = new JSONObject(s);
        if (j != null && "success".equals(j.getString("cssweb_code")))
            return j.getInt("custLevel");
    }
    return 0;
}

From source file:Main.java

public static String getJsonWithPath(String path) {
    StringBuffer sb = new StringBuffer();
    URL url = null;//w ww.  j  a  v  a 2s.c  om
    HttpURLConnection conn = null;
    BufferedReader br = null;

    try {
        url = new URL(path);
        conn = (HttpURLConnection) url.openConnection();
        if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
            br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String temp = "";
            while ((temp = br.readLine()) != null) {
                sb.append(temp);
            }
        } else {
            Log.e(TAG, " NET IS ERROR");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        close(br);
        conn.disconnect();
    }
    Log.i("TAG", "---" + sb.toString());
    return sb.toString();
}

From source file:Main.java

public static void setFocusArea(Camera.Parameters parameters) {
    if (parameters.getMaxNumFocusAreas() > 0) {
        Log.i(TAG, "Old focus areas: " + toString(parameters.getFocusAreas()));
        List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
        Log.i(TAG, "Setting focus area to : " + toString(middleArea));
        parameters.setFocusAreas(middleArea);
    } else {//from   w  ww.j  a v  a2  s.  c  o m
        Log.i(TAG, "Device does not support focus areas");
    }
}