Dilip
Dilip

Reputation: 2301

How to get Access Point Name programmatically

I'm trying to get Access Point Name programmatically.I need this to develop application for the specific APN name.I googled lot but didn't find any proper way can any tell me how to do this.Thanks

Upvotes: 2

Views: 4925

Answers (2)

Akshay Kumar A
Akshay Kumar A

Reputation: 19

For All APN Names:

Cursor c = getApplicationContext().getContentResolver().query(Uri.parse("content://telephony/carriers/current"),null, null, null, null);
        Log.e("MainActivity","getColumnNames: "+ 
                        Arrays.toString(c.getColumnNames())); //get the column names from here.
        if (c.moveToFirst()){
            do{
                String data = c.getString(c.getColumnIndex("name")); //one of the column name to get the APN names.
                Log.e("MainActivity","data: "+ data);

            }while(c.moveToNext());
        }
        c.close();         

For Selected APN:

Cursor c1 = getApplicationContext().getContentResolver().query(Uri.parse("content://telephony/carriers/preferapn"),null, null, null, null);
    if (c1.moveToFirst()){
        do{
            String data = c1.getString(c1.getColumnIndex("name"));
            Log.e("MainActivity","data: "+ data);
        }while(c1.moveToNext());
    }
    c1.close();    

Upvotes: 1

Sagar Maiyad
Sagar Maiyad

Reputation: 12733

For Selected APN:

Cursor c = context.getContentResolver().query(Uri.parse("content://telephony/carriers/preferapn"), null, null, null, null);

For All APN Names:

Cursor c = context.getContentResolver().query(Uri.parse("content://telephony/carriers/current"), null, null, null, null);

Upvotes: 1

Related Questions