- 1、本文档共6页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
android APN的打开与关闭
android APN的打开与关闭
由于Android对于APN的网络API没有公开,不过我们可以阅读源代码,然后进行数据库操作,系统会自动监听数据库的变化,从而实现开启或者关闭APN。大家可以研究一下frameworks/base/core/java/android/provider/Telephony.java这个类,比较重要的就是 URI 和数据库字段: content://telephony/carriers字段可以在Telephony.java中找到。其实原理很简单 :1 、 当开启APN的时候,设置一个正确的移动或者联通的APN2、 关闭的时候设置一个错误APN就会自动关闭网络看代码:Activity:Java代码package cc.mdev.apn;import java.util.ArrayList;import java.util.List;import android.app.Activity;import android.content.ContentValues;import android.database.Cursor;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;public class Main extends Activity {Uri uri = Uri.parse(content://telephony/carriers);@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);Button open= (Button) findViewById(R.id.open);Button close= (Button) findViewById(R.id.close);open.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {openAPN();}});close.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {closeAPN();}});}public? void openAPN(){ListAPN list = getAPNList();for (APN apn : list) {ContentValues cv = new ContentValues();cv.put(apn, APNMatchTools.matchAPN(apn.apn));cv.put(type, APNMatchTools.matchAPN(apn.type));getContentResolver().update(uri, cv, _id=?, new String[]{apn.id});}}public void closeAPN(){ListAPN list = getAPNList();for (APN apn : list) {ContentValues cv = new ContentValues();cv.put(apn, APNMatchTools.matchAPN(apn.apn)+mdev);cv.put(type, APNMatchTools.matchAPN(apn.type)+mdev);getContentResolver().update(uri, cv, _id=?, new String[]{apn.id});}}private ListAPN getAPNList(){String tag = Main.getAPNList();//current不为空表示可以使用的APNString? projection[] = {_id,apn,type,current};Cursor cr = this.getContentResolver().query(uri, projection, null, null, null);ListAPN list = new ArrayListAPN();while(cr!=nu
文档评论(0)