2011-12-20 6 views
4

안드로이드가 어떻게하고 있는지 궁금합니다.안드로이드 - APN 연결 변경 처리

:

  1. WAP 푸시는 수신 MMS를 나타냅니다.
  2. APN을 MMS로 변경하십시오.
  3. MMS를 다운로드하십시오.
  4. 기본 APN에 대한 연결을 복원하십시오.

어떻게 APN의 변경이 완료 되었습니까?

: 다른 APN을 사용하여 기본 또는 MMS APN 대신 인터넷에 연결하고 싶습니다.

+0

https://groups.google.com/group/android-developers/browse_thread/thread/4a4d8fbc87d20c/a7abeb949cd8b3ba?lnk=gst&q=3g+WiFi+simultaneously#a7abeb949cd8b3ba – Jens

+0

@Jens을 링크가 응답하지 않습니다 그 질문은 분명히. 심지어이 문제에 대한 해결책을 찾고 있어요. – webgenius

답변

6

다음 활동은 기본 APN을 변경하고 원본으로 되돌리는 문제를 해결합니다.

package com.slk.apnapp; 

import android.app.Activity; 
import android.content.ContentResolver; 
import android.content.ContentValues; 
import android.database.Cursor; 
import android.database.SQLException; 
import android.net.Uri; 
import android.os.Bundle; 
import android.telephony.TelephonyManager; 
import android.util.Log; 

public class NewAPNActivity extends Activity { 
/* 
* Information of all APNs Details can be found in 
* com.android.providers.telephony.TelephonyProvider 
*/ 
public static final Uri APN_TABLE_URI = Uri 
     .parse("content://telephony/carriers"); 
/* 
* Information of the preferred APN 
*/ 
public static final Uri PREFERRED_APN_URI = Uri 
     .parse("content://telephony/carriers/preferapn"); 
private static final String TAG = "CHANGE_APN"; 
public static final String NEW_APN = "NewAPN"; 

private int getDafaultAPN() { 
    Cursor c = this.getContentResolver().query(PREFERRED_APN_URI, 
      new String[] { "_id", "name" }, null, null, null); 
    int id = -1; 
    if (c != null) { 
     try { 
      if (c.moveToFirst()) 
       id = c.getInt(c.getColumnIndex("_id")); 
     } catch (SQLException e) { 
      Log.d(TAG, e.getMessage()); 
     } 
     c.close(); 
    } 
    return id; 

} 

/* 
* Set an apn to be the default apn for web traffic Require an input of the 
* apn id to be set 
*/ 
public boolean setDefaultAPN(int id) { 
    boolean res = false; 
    ContentResolver resolver = this.getContentResolver(); 
    ContentValues values = new ContentValues(); 

    // See /etc/apns-conf.xml. The TelephonyProvider uses this file to 
    // provide 
    // content://telephony/carriers/preferapn URI mapping 
    values.put("apn_id", id); 
    try { 
     resolver.update(PREFERRED_APN_URI, values, null, null); 
     Cursor c = resolver.query(PREFERRED_APN_URI, new String[] { "name", 
       "apn" }, "_id=" + id, null, null); 
     if (c != null) { 
      res = true; 
      c.close(); 
     } 
    } catch (SQLException e) { 
     Log.d(TAG, e.getMessage()); 
    } 
    return res; 
} 

private int checkNewAPN() { 
    int id = -1; 
    Cursor c = this.getContentResolver().query(APN_TABLE_URI, 
      new String[] { "_id", "name" }, "name=?", 
      new String[] { NEW_APN }, null); 
    if (c == null) { 
     id = -1; 
    } else { 
     int record_cnt = c.getCount(); 
     if (record_cnt == 0) { 
      id = -1; 
     } else if (c.moveToFirst()) { 
      if (c.getString(c.getColumnIndex("name")).equalsIgnoreCase(
        NEW_APN)) { 
       id = c.getInt(c.getColumnIndex("_id")); 
      } 
     } 
     c.close(); 
    } 
    return id; 
} 

public int addNewAPN() { 
    int id = -1; 
    ContentResolver resolver = this.getContentResolver(); 
    ContentValues values = new ContentValues(); 
    values.put("name", NEW_APN); 
    values.put("apn", NEW_APN); 

    /* 
    * The following three field values are for testing in Android emulator 
    * only The APN setting page UI will ONLY display APNs whose 'numeric' 
    * filed is TelephonyProperties.PROPERTY_SIM_OPERATOR_NUMERIC. On 
    * Android emulator, this value is 310260, where 310 is mcc, and 260 
    * mnc. With these field values, the newly added apn will appear in 
    * system UI. 
    */ 
    values.put("mcc", "310"); 
    values.put("mnc", "260"); 
    values.put("numeric", "310260"); 

    Cursor c = null; 
    try { 
     Uri newRow = resolver.insert(APN_TABLE_URI, values); 
     if (newRow != null) { 
      c = resolver.query(newRow, null, null, null, null); 

      // Obtain the apn id 
      int idindex = c.getColumnIndex("_id"); 
      c.moveToFirst(); 
      id = c.getShort(idindex); 
      Log.d(TAG, "New ID: " + id + ": Inserting new APN succeeded!"); 
     } 
    } catch (SQLException e) { 
     Log.d(TAG, e.getMessage()); 
    } 

    if (c != null) 
     c.close(); 
    return id; 
} 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    int id = checkNewAPN(); 
    int default_id = getDafaultAPN(); 

    if (id == -1) { 
     id = addNewAPN(); 
    } 

    if (setDefaultAPN(id)) { 
     Log.i(TAG, NEW_APN 
       + " set new default APN successfully and Default id is " 
       + id); 
    } 
    if (setDefaultAPN(default_id)) { 
     Log.i(TAG, 
       NEW_APN 
         + " set previous default APN successfully and Default id is " 
         + default_id); 
    } 

} 
} 
+2

감사합니다 Raj, 내 문제를 해결하는 코드 및 현상금이 수여됩니다. –

+3

@HiteshPatel : 다음을 확인할 수도 있습니다. [이 링크] (http://blogs.msdn.com/b/zhengpei/archive/2009/10/13/managing-apn-data-in-google-android.aspx) 더 좋은 예를 들어. :) –

+0

확인. APN의 새로운 지점을 만들고 기본값으로 설정합니다. 이미 구성되어 있고 사용 가능한 회사 APN으로 변경하면되지만 기본값이 아니기 때문에 (여전히 남아있을 것으로 예상됩니다). 변경 사항은 회사 응용 프로그램의 시작 부분에서 발생하며 응용 프로그램을 종료하면 기본 APN으로 돌아갑니다. –