我想知道 Android 是如何做到这一点的。
示例:
那么这个APN的变化是如何完成的呢?
为什么: 我想使用其他 APN 连接到互联网,而不是默认或 MMS APN。
最佳答案
以下 Activity 解决了您更改默认 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);
}
}
}
关于Android - 处理不断变化的 apn 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8575717/
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类
在启用Rack::Deflater来gzip我的响应主体时偶然发现了一些奇怪的东西。也许我遗漏了一些东西,但启用此功能后,响应被压缩,但是资源的ETag在每个请求上都会发生变化。这会强制应用程序每次都响应,而不是发送304。这在没有启用Rack::Deflater的情况下有效,我已经验证页面源没有改变。我正在运行一个使用thin作为Web服务器的Rails应用程序。Gemfile.lockhttps://gist.github.com/2510816有没有什么方法可以让我从Rack中间件获得更多的输出,这样我就可以看到发生了什么?提前致谢。 最佳答案
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
require"socket"server="irc.rizon.net"port="6667"nick="RubyIRCBot"channel="#0x40"s=TCPSocket.open(server,port)s.print("USERTesting",0)s.print("NICK#{nick}",0)s.print("JOIN#{channel}",0)这个IRC机器人没有连接到IRC服务器,我做错了什么? 最佳答案 失败并显示此消息::irc.shakeababy.net461*USER:Notenoughparame
考虑一下:现在这些情况:#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2我需要用其他字符串输出URL。我如何保证&符号不会被转义?由于我无法控制的原因,我无法发送&。求助!把我的头发拉到这里:\编辑:为了澄清,我实际上有一个像这样的数组:@images=[{:id=>"fooid",:url=>"http://
我对图像处理完全陌生。我对JPEG内部是什么以及它是如何工作一无所知。我想知道,是否可以在某处找到执行以下简单操作的ruby代码:打开jpeg文件。遍历每个像素并将其颜色设置为fx绿色。将结果写入另一个文件。我对如何使用ruby-vips库实现这一点特别感兴趣https://github.com/ender672/ruby-vips我的目标-学习如何使用ruby-vips执行基本的图像处理操作(Gamma校正、亮度、色调……)任何指向比“helloworld”更复杂的工作示例的链接——比如ruby-vips的github页面上的链接,我们将不胜感激!如果有ruby-
我有一个super简单的脚本,它几乎包含了FayeWebSocketGitHub页面上用于处理关闭连接的内容:ws=Faye::WebSocket::Client.new(url,nil,:headers=>headers)ws.on:opendo|event|p[:open]#sendpingcommand#sendtestcommand#ws.send({command:'test'}.to_json)endws.on:messagedo|event|#hereistheentrypointfordatacomingfromtheserver.pJSON.parse(event.d
我正在尝试解析网页,但有时会收到404错误。这是我用来获取网页的代码:result=Net::HTTP::getURI.parse(URI.escape(url))如何测试result是否为404错误代码? 最佳答案 像这样重写你的代码:uri=URI.parse(url)result=Net::HTTP.start(uri.host,uri.port){|http|http.get(uri.path)}putsresult.codeputsresult.body这将打印状态码和正文。