get the Network connection proxy and port - Android Phone

Android examples for Phone:Network

Description

get the Network connection proxy and port

Demo Code


//package com.java2s;

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

import android.net.Uri;

public class Main {
    /**//from w w w  .ja va2s.c o  m
     * get the connection proxy and port
     * @param context
     * @return
     */
    public static String[] getHostAndProxy(Context context) {
        Uri uri = Uri.parse("content://telephony/carriers/preferapn");
        Cursor mCursor = context.getContentResolver().query(uri, null,
                null, null, null);
        if (mCursor != null) {
            mCursor.moveToNext();
            String proxyStr = mCursor.getString(mCursor
                    .getColumnIndex("proxy"));
            String port = mCursor.getString(mCursor.getColumnIndex("port"));
            return new String[] { proxyStr, port };
        }
        return null;
    }
}

Related Tutorials