2

我正在尝试以编程方式获取接入点名称。我需要这个来开发特定 APN 名称的应用程序。我用谷歌搜索了很多,但没有找到任何合适的方法可以告诉我如何做到这一点。谢谢

4

2 回答 2

1

对于选定的 APN:

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

对于所有 APN 名称:

Cursor c = context.getContentResolver().query(Uri.parse("content://telephony/carriers/current"), null, null, null, null);
于 2013-06-11T12:26:46.283 回答
0

对于所有 APN 名称:

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();         

对于选定的 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();    
于 2019-06-19T05:16:41.777 回答