【问题标题】:How to get Access Point Name programmatically如何以编程方式获取接入点名称
【发布时间】:2013-06-11 12:20:24
【问题描述】:

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

【问题讨论】:

  • @Triode 我相信 APN 在这里声明 Access Point Name,而不是应用程序名称...
  • @Triode 询问 APN 名称而不是应用程序名称。

标签: android apn


【解决方案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);

【讨论】:

    【解决方案2】:

    对于所有 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();    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-07
      • 2023-04-04
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      相关资源
      最近更新 更多