get Proxy Ip Address - Android Network

Android examples for Network:IP Address

Description

get Proxy Ip Address

Demo Code


//package com.java2s;

import android.content.Context;
import android.database.Cursor;

import android.net.Uri;

public class Main {
    public static String getProxyIp(String apnId, Context context) {
        if (apnId == null)
            return null;
        Cursor c = null;/*from w w  w  . j  a  v  a 2  s. c o  m*/
        try {
            Uri uri = Uri.parse("content://telephony/carriers");
            c = context.getContentResolver().query(uri, null, null, null,
                    null);
            while (c != null && c.moveToNext()) {
                // APN id
                String id = c.getString(c.getColumnIndex("_id"));
                if (apnId.trim().equals(id)) {
                    return c.getString(c.getColumnIndex("proxy"));
                }
            }
        } finally {
            if (c != null)
                c.close();
        }
        return null;
    }
}

Related Tutorials