【发布时间】:2013-06-11 12:20:24
【问题描述】:
我正在尝试以编程方式获取 接入点名称。我需要这个来为特定的 APN 名称开发应用程序。我用谷歌搜索了很多,但没有找到任何合适的方法可以告诉我如何这样做。谢谢
【问题讨论】:
-
@Triode 我相信 APN 在这里声明
Access Point Name,而不是应用程序名称... -
@Triode 询问 APN 名称而不是应用程序名称。
我正在尝试以编程方式获取 接入点名称。我需要这个来为特定的 APN 名称开发应用程序。我用谷歌搜索了很多,但没有找到任何合适的方法可以告诉我如何这样做。谢谢
【问题讨论】:
Access Point Name,而不是应用程序名称...
对于选定的 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);
【讨论】:
对于所有 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();
【讨论】: