我正在尝试以编程方式获取接入点名称。我需要这个来开发特定APN名称的应用程序。我google了很多但没有找到任何正确的方法可以告诉我如何这样做。谢谢
答案 0 :(得分: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);
答案 1 :(得分:-1)
对于所有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();