首页
社区
课程
招聘
[求助]请大神看看这个APN是怎么设置的,谢谢!
发表于: 2014-12-13 21:34 7640

[求助]请大神看看这个APN是怎么设置的,谢谢!

2014-12-13 21:34
7640
我研究好久没看懂这个APN是怎么设置的.!

我想知道手机上到底怎么手工填写这个APN

1.名称:

2.APN:

3.代理:

4.端口:

5.用户名:

6.密码:

7.服务器:

8.MMSC:

9.彩信代理:

10.彩信端口:

11.彩信协议:

12.MCC:

13.MNC:

14.APN类型:



package com.XxX.apn;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;

public abstract class AbstractAPNSetting
{
public static final String APN_ID = "apn_id";
public static String APN_TABLE_URI = "content://telephony/carriers";
protected static final Uri APN_URI = Uri.parse(APN_TABLE_URI);
protected static final Uri PREFERAPN_URI = Uri.parse("content://telephony/carriers/preferapn");
public static final String PREFERRED_APN_URI = "content://telephony/carriers/preferapn";

public int delAPN(Context paramContext, String paramString)
{
paramContext.getContentResolver().delete(APN_URI, "_id<>?", new String[] { paramString });
return 1;
}

protected ContentValues getApn(Context paramContext, String paramString1, String paramString2, String paramString3)
{
Cursor localCursor = paramContext.getContentResolver().query(APN_URI, null, "(apn=? or name=?) and mcc=? and mnc=?", new String[] { paramString1, paramString1, paramString2, paramString3 }, null);
localCursor.moveToFirst();
String[] arrayOfString = localCursor.getColumnNames();
boolean bool = localCursor.isAfterLast();
ContentValues localContentValues = null;
if (!bool)
{
localContentValues = new ContentValues();
int i = arrayOfString.length;
int j = 0;
int m;
for (int k = 0; j < i; k = m)
{
String str1 = arrayOfString[j];
m = k + 1;
String str2 = localCursor.getString(k);
localContentValues.put(str1, str2);
Log.i("net_state", str1 + ":" + str2);
j++;
}
localCursor.moveToNext();
}
localCursor.close();
return localContentValues;
}

protected ContentValues getApn(Context paramContext, String paramString1, String paramString2, String paramString3, String paramString4)
{
Cursor localCursor = paramContext.getContentResolver().query(APN_URI, null, "apn=? and user=? and mcc=? and mnc=?", new String[] { paramString1, paramString2, paramString3, paramString4 }, null);
localCursor.moveToFirst();
ContentValues localContentValues = null;
String[] arrayOfString = localCursor.getColumnNames();
while (!localCursor.isAfterLast())
{
localContentValues = new ContentValues();
int i = arrayOfString.length;
int j = 0;
int m;
for (int k = 0; j < i; k = m)
{
String str1 = arrayOfString[j];
m = k + 1;
String str2 = localCursor.getString(k);
localContentValues.put(str1, str2);
Log.i("net_state", str1 + ":" + str2);
j++;
}
localCursor.moveToNext();
}
localCursor.close();
return localContentValues;
}

public String getCurrentAPN(Context paramContext)
{
Cursor localCursor = paramContext.getContentResolver().query(PREFERAPN_URI, new String[] { "_id" }, null, null, null);
if (localCursor != null)
{
if (localCursor.moveToFirst())
return localCursor.getString(localCursor.getColumnIndex("_id"));
localCursor.close();
}
return "";
}

public abstract void insertApn();

public void setSelectedApnKey(Context paramContext, String paramString)
{
if (getCurrentAPN(paramContext).equals(paramString))
return;
ContentResolver localContentResolver = paramContext.getContentResolver();
ContentValues localContentValues = new ContentValues();
localContentValues.put("apn_id", paramString);
localContentResolver.update(PREFERAPN_URI, localContentValues, null, null);
}
}



package com.XxX.apn;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.Log;

public class CMApnSetting extends AbstractAPNSetting
{
  protected static String XxX_APN_NAME = "Kiss.Jh.Cn";
  protected static String NET_APN_NAME = "cmnet";
  Activity mActivity;
  private String mApnName;
  private Context mContext;
  String mcc = "";
  String mnc = "";

  public CMApnSetting(Context paramContext, Activity paramActivity, String paramString)
  {
    this.mContext = paramContext;
    this.mApnName = paramString;
    this.mActivity = paramActivity;
    String str = ((TelephonyManager)this.mContext.getSystemService("phone")).getSubscriberId();
    this.mcc = str.substring(0, 3);
    this.mnc = str.substring(3, 5);
    Log.i("net_state", this.mcc + ":" + this.mnc);
  }

  protected ContentValues getDefalut()
  {
    return getApn(this.mContext, NET_APN_NAME, this.mcc, this.mnc);
  }

  public void insertApn()
  {
    new Thread(new Runnable()
    {
      public void run()
      {
        ContentValues localContentValues = CMApnSetting.this.getApn(CMApnSetting.this.mContext, CMApnSetting.XxX_APN_NAME, CMApnSetting.this.mcc, CMApnSetting.this.mnc);
        if (localContentValues == null)
        {
          localContentValues = CMApnSetting.this.getDefalut();
          CMApnSetting.this.getApn(CMApnSetting.this.mContext, "dfgg", CMApnSetting.this.mcc, CMApnSetting.this.mnc);
          if (localContentValues != null)
          {
            localContentValues.remove("_id");
            if (localContentValues.containsKey("name"))
              localContentValues.remove("name");
            if (localContentValues.containsKey("apn"))
              localContentValues.remove("apn");
            localContentValues.put("name", CMApnSetting.this.mApnName);
            localContentValues.put("apn", CMApnSetting.XxX_APN_NAME);
            CMApnSetting.this.mContext.getContentResolver().insert(AbstractAPNSetting.APN_URI, localContentValues);
            localContentValues = CMApnSetting.this.getApn(CMApnSetting.this.mContext, CMApnSetting.XxX_APN_NAME, CMApnSetting.this.mcc, CMApnSetting.this.mnc);
          }
        }
        if (localContentValues != null)
        {
          CMApnSetting.this.setSelectedApnKey(CMApnSetting.this.mContext, localContentValues.getAsString("_id"));
          CMApnSetting.this.delAPN(CMApnSetting.this.mContext, localContentValues.getAsString("_id"));
        }
      }
    }).run();
  }
}

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 190
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
没人知道吗? 大神!!!!!!!!!!!!
2014-12-14 01:58
0
雪    币: 53
活跃值: (280)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
这段代码就是操作TelephonyProvider,向该数据库的carriers表写入数据
请查阅Android provider原理及android teleponyprovider源码
2014-12-15 13:55
0
游客
登录 | 注册 方可回帖
返回
//