一.
Apn设置,即“接入点名称”设置,Apn的全称是Access Pointname,是用户在通过手机上网时必须配置的一个参数,它决定了您的手机通过哪种接入方式来访问移动网络。
对于移动终端用户来说,可以访问的外部网络类型有很多,例如:Internet、WAP网站、集团企业内部网络、行业内部专用网络。而不同的接入点所能访问的范围以及入的方式是不同的,网络侧如何知道移动终端激活以后要访问哪个网络从而分配哪个网段的 IP呢,这就要靠 APN来区分了,即 APN决定了用户的移动终端通过哪种接入方式来访问什么样的网络。
常见的 APN有:中国移动的 cmnet 和 cmwap、中国联通的uninet 和 uniwap、中国电信的 ctnet 和 ctwap
1.1.apns-conf.xml
<apn carrIEr="中国移动物联网2G" mcc="460" mnc="04" apn="cmmtm" type="default,supl" /> <apn carrIEr="中国联通物联网gzm2mapn" mcc="460" mnc="06" apn="unim2m.gzm2mapn" port="80" type="default,supl" /> <apn carrIEr="中国联通物联网njm2mapn" mcc="460" mnc="06" apn="unim2m.njm2mapn" type="default,supl" /> <apn carrIEr="中国电信物联网m2m" mcc="460" mnc="03" apn="CTNET" user="m2m" password="vnet.mobi" type="default" /> <apn carrIEr="中国移动物联网卡00" mcc="460" mnc="00" apn="cmiot" type="default,supl" /> <apn carrIEr="中国移动物联网卡02" mcc="460" mnc="02" apn="cmiot" type="default,supl" />
1.2.
// 解释:// imsI是国际移动用户识别码的简称(International Mobile Subscriber IDentity)// imsI共有15位,其结构如下:// MCC+MNC+MIN// MCC:Mobile Country Code,移动国家码,共3位,中国为460;// MNC:Mobile NetworkCode,移动网络码,共2位// 在中国,移动的代码为电00和02,联通的代码为01,电信的代码为03// 合起来就是(也是AndroID手机中APN配置文件中的代码):// 中国移动:46000 46002// 中国联通:46001// 中国电信:46003// 举例,一个典型的imsI号码为460030912121001
1.3.
cmnet(China Mobile Network) 中国移动互联网cmiot 中国移动物联网的简称
1.4.
查询当前apn信息content query --uri content://telephony/carrIErs/preferapn修改接入点content insert --uri content://telephony/carrIErs/preferapn --bind apn_ID:i:123456后面的123456换成查询到的ID
二.
2.1.APN Uri介绍
content://telephony/carrIErs代表的是APN数据库的位置,所有的APN都在这个数据库中。content://telephony/carrIErs //取得全部apn列表content://telephony/carrIErs/preferapn //取得当前设置的content://telephony/carrIErs/current //取得current=1的apn列表content://telephony/carrIErs/restore //恢复默认设置
2.2.权限
<!--开关APN的权限 --> <uses-permission androID:name="androID.permission.WRITE_APN_SETTINGS" /> <!-- 允许读取电话状态SIM的权限 --> <uses-permission androID:name="androID.permission.READ_PHONE_STATE" />
2.3.
package com.gatsby.apn;import androID.app.Activity;import androID.content.ContentResolver;import androID.content.ContentValues;import androID.content.Context;import androID.database.Cursor;import androID.net.Uri;import androID.os.Bundle;import androID.telephony.TelephonyManager;import androID.util.Log;public class MainActivity extends Activity { public static final Uri APN_URI = Uri.parse("content://telephony/carrIErs"); public static final Uri CURRENT_APN_URI = Uri.parse("content://telephony/carrIErs/preferapn"); @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); int czyhID = addAPN(); SetAPN(czyhID); } // apn carrIEr="中国移动物联网卡08" mcc="460" mnc="08" apn="cmiot" type="default,supl" // 新增一个3GWap接入点 public int addAPN() { int ID = -1; String NUMERIC = getSIMInfo(); Log.d("gatsby", "NUMERIC->" + NUMERIC); if (NUMERIC == null) { return -1; } ContentResolver resolver = this.getContentResolver(); ContentValues values = new ContentValues(); values.put("name", "中国移动物联网卡08");// apn中文描述 values.put("apn", "cmiot"); // apn名称 values.put("mcc", "460");// apn类型 values.put("mnc", "08"); values.put("numeric", NUMERIC);// 中国移动:46000 46002 values.put("type", "default,supl"); // apn类型 Cursor c = null; Uri newRow = resolver.insert(APN_URI, values); if (newRow != null) { c = resolver.query(newRow, null, null, null, null); int idindex = c.getColumnIndex("_ID"); c.movetoFirst(); ID = c.getShort(idindex); } if (c != null) c.close(); return ID; } public voID SetAPN(int ID) { ContentResolver resolver = this.getContentResolver(); ContentValues values = new ContentValues(); values.put("apn_ID", ID); resolver.update(CURRENT_APN_URI, values, null, null); } protected String getSIMInfo() { TelephonyManager iPhoneManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); return iPhoneManager.getSimOperator(); }}
三.
3.1.
adb root adb remount adb push Z:\ZK-R31X_5.1_RK3128_Firmware\ZK_R31A_RK312X_ANDROID5.1\out\target\product\rk312x\system\etc\apns-conf.xml system/etc adb shell cd /data/data/com.androID.provIDers.telephony/databasesrm -rf /data/data/com.androID.provIDers.telephony/databases/telephony.db
3.2.
package com.gatsby.test;import java.io.DatainputStream;import java.io.DataOutputStream;import java.io.file;import java.io.fileOutputStream;import java.io.inputStream;import java.util.Timer;import java.util.TimerTask;import androID.annotation.Suppresslint;import androID.app.Activity;import androID.content.Context;import androID.os.Build;import androID.os.Bundle;import androID.os.Handler;import androID.os.Message;import androID.util.Log;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.Widget.button;import androID.Widget.Toast;public class MainActivity extends Activity implements OnClickListener { private button btn1; private boolean isoncl = true; private static String UPDATE_Title = "copying file!"; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); btn1 = (button) findVIEwByID(R.ID.btn1); btn1.setonClickListener(this); } @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub switch (v.getID()) { case R.ID.btn1: if (isoncl) { isoncl = false; // set update Title btn1.setText(UPDATE_Title); btn1.setTextSize(64); Toast.makeText(MainActivity.this, "update file start", Toast.LENGTH_SHORT).show(); // NO.1 copy the asserts to /mnt/sdcard/ copyfilesFassets(this, "apns-conf.xml", "/mnt/sdcard/apns-conf.xml"); // NO.3 remount the system in case the system is read only if (Build.VERSION.SDK_INT >= 25) { RootCommand("mount -o rw,remount -t ext4 /system"); RootCommand("mount -o rw,remount -t ext4 /vendor"); } else { RootCommand("mount -o remount,rw /system"); } // NO.4 RootCommand("busyBox cp -rf /mnt/sdcard/apns-conf.xml /system/etc/apns-conf.xml"); // NO.5 Toast.makeText(MainActivity.this, "copy file successfully! To Repoot ", Toast.LENGTH_LONG).show(); timer.schedule(task, 10000); } break; } } Timer timer = new Timer(); @Suppresslint("HandlerLeak") Handler handler = new Handler() { public voID handleMessage(Message msg) { switch (msg.what) { case 1: // NO.7 reboot RootCommand("rm -rf /mnt/sdcard/apns-conf.xml"); RootCommand("rm -rf /data/data/com.androID.provIDers.telephony/databases/telephony.db"); RootCommand("reboot"); break; } super.handleMessage(msg); } }; TimerTask task = new TimerTask() { public voID run() { Message message = new Message(); message.what = 1; handler.sendMessage(message); } }; public voID copyfilesFassets(Context context, String oldpath, String newPath) { try { inputStream is = context.getAssets().open(oldpath); fileOutputStream fos = new fileOutputStream(new file(newPath)); byte[] buffer = new byte[1024]; int byteCount = 0; while ((byteCount = is.read(buffer)) != -1) { fos.write(buffer, 0, byteCount); } fos.flush(); is.close(); fos.close(); } catch (Exception e) { e.printstacktrace(); } } private voID RootCommand(String cmd) { Process process = null; DataOutputStream os = null; DatainputStream is = null; try { process = Runtime.getRuntime().exec("/system/xbin/su"); os = new DataOutputStream(process.getoutputStream()); os.writeBytes(cmd + "\n"); os.writeBytes("exit\n"); os.flush(); int aa = process.waitFor(); is = new DatainputStream(process.getinputStream()); byte[] buffer = new byte[is.available()]; is.read(buffer); String out = new String(buffer); Log.d("xinhua", out + aa); } catch (Exception e) { e.printstacktrace(); } finally { try { if (os != null) { os.close(); } if (is != null) { is.close(); } process.destroy(); } catch (Exception e) { } } }}
总结
以上是内存溢出为你收集整理的RK APN设置全部内容,希望文章能够帮你解决RK APN设置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)