7

コードで APN を作成したいのですが、Android SDK で何らかのサポートはありますか。いろいろ試しましたが成功しませんでした。このhttp://blogs.msdn.com/b/zhengpei/archive/2009/ 10/13/managing-apn-data-in-google-android.aspxこの参照を使用してクラスを作成しましたが、何もできません。これに対する解決策を教えてください???? ありがとう

4

2 に答える 2

13

いくつかの例を挙げます:

デフォルトの APN 情報の取得:

//path to APN table
final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");

//path to preffered APNs
final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");

//receiving cursor to preffered APN table
Cursor c = getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);

//moving the cursor to beggining of the table
c.moveToFirst();

//now the cursor points to the first preffered APN and we can get some
//information about it
//for example first preffered APN id    
int index = c.getColumnIndex("_id");    //getting index of required column
Short id = c.getShort(index);           //getting APN's id from

//we can get APN name by the same way
index = c.getColumnIndex("name");
String name = c.getString(index); 

//and any other APN properties: numeric, mcc, mnc, apn, user, server,
//password, proxy, port, mmsproxy, mmsport, mmsc, type, current

新しい APN を定義するには:

//first we have to create a new row in APN table
int id = -1;
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();

//create value, you can define any other APN properties in the same way
values.put("name", "Your APN Name");    //choose APN name, like 3G Orange
values.put("apn", "Your APN address");  //choose APN address, like cellcom.wapu.co.il

//now we have to define APN setting page UI. You have to get operator numeric property
//you can obtain it from TelephonyManager.getNetworkOperator() method
values.put("mcc", "your operator numeric high part");  //for example 242
values.put("mnc", "your operator numeric low part");   //for example 501
values.put("numeric", "your operator numeric");        //for example 242501

Cursor c = null;
try
{
    //insert new row to APN table
    Uri newRow = resolver.insert(APN_TABLE_URI, values);
    if(newRow != null)
    {
        c = resolver.query(newRow, null, null, null, null);

        //obtain the APN id
        int index = c.getColumnIndex("_id");
        c.moveToFirst();
        id = c.getShort(index);
    }
}
catch(Exception e)
{
}

//now after we created a new APN in APN table
//and APN's ID stored in id variable (or -1 if any troubles was happaned)
//we can define a new APN as default
values = new ContentValues();
values.put("apn_id", id); 

try
{
    resolver.update(PREFERRED_APN_URI, values, null, null);
}
catch (Exception e)
{
}

うまくいかない場合は教えてください。問題を調べてみます。

于 2011-10-28T11:42:54.557 に答える
2

@ Borg8 ありがとう、あなたは私をたくさん助けてくれました。ここのリンクの上の@DeepSanで答えを見つけました。

** emaltor ** UI で作成したばかりの新しい APN を確認するには、数値 310260 を使用します。

// TelephonyProperties;
    values.put("mcc", "310");
    values.put("mnc", "260");
    values.put("numeric", "310260");

デバイス (Galaxy) で表示するには、TelephonyManager を使用しました。

  TelephonyManager tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String networkOperator = tel.getNetworkOperator();
    int mcc = 0;
    int mnc = 0;
    if (networkOperator != null) {
          mcc = Integer.parseInt(networkOperator.substring(0, 3));
          mnc = Integer.parseInt(networkOperator.substring(3));
    }

   // TelephonyProperties;
    values.put("mcc", mcc );
    values.put("mnc", mnc );
    values.put("numeric",networkOperator);

これで、UI に新しい APN が表示されます。

于 2011-11-28T08:27:30.287 に答える