- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试更新位于以下位置的首选 APN 数据库表的“名称”列:content://telephony/carriers/preferapn。但是,我的应用程序的 ContentResolver.update() 始终返回 0,这意味着没有更新任何行。我已经拥有该应用程序的 root 访问权限,并在运行 update() 之前以编程方式确认了它。
可以找到有关表列的详细信息here和 here .我还确保引用了 documentation关于如何调用更新功能。
更新方法:
public boolean setAPN(String newAPN, TextView t){
//get URI objects for the tables
final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
//Confirm permissions
PackageManager pm = getPackageManager();
if (pm.checkPermission(permission.WRITE_APN_SETTINGS, getPackageName()) == PackageManager.PERMISSION_GRANTED) {
//Update name field
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();
values.put("name", newAPN);
long rc = resolver.update(PREFERRED_APN_URI, values, null, null);
//Display the row contents (always has the original fields, doesn't update)
Cursor c = getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
c.moveToFirst();
int index = c.getColumnIndex("_id"); //getting index of required column
Short id = c.getShort(index); //getting APN's id from
index = c.getColumnIndex("name");
String name = c.getString(index);
index = c.getColumnIndex("mcc");
String mcc = c.getString(index);
index = c.getColumnIndex("mnc");
String mnc = c.getString(index);
index = c.getColumnIndex("numeric");
String numeric = c.getString(index);
t.setText(" ID:" + id + "\n" +
" APN Name: " + name + "\n" +
" MCC: " + mcc + "\n" +
" MNC: " + mnc + "\n" +
" Numeric: " + numeric + "\n"
);
} else {
t.setText(" You don't have permission to do this. ");
}
return true;
}
如前所述,我也有权限: list 文件中的“android.permission.WRITE_APN_SETTINGS”:
我是否出于特定目的错误地调用了更新函数?还是使用 update() 是错误的方法?
最佳答案
这个问题已经死了快一个月了,但我为这个问题做了一个解决方法并想分享它。解决方法包括复制不包括名称字段的现有首选 APN 条目,将新 APN 插入运营商列表,然后使用新生成的 ID 将新 APN 设置为首选。
public int InsertAPN(String name){
//Set the URIs and variables
int id = -1;
boolean existing = false;
final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
//Check if the specified APN is already in the APN table, if so skip the insertion
Cursor parser = getContentResolver().query(APN_TABLE_URI, null, null, null, null);
parser.moveToLast();
while (parser.isBeforeFirst() == false){
int index = parser.getColumnIndex("name");
String n = parser.getString(index);
if (n.equals(name)){
existing = true;
Toast.makeText(getApplicationContext(), "APN already configured.",Toast.LENGTH_SHORT).show();
break;
}
parser.moveToPrevious();
}
//if the entry doesn't already exist, insert it into the APN table
if (!existing){
//Initialize the Content Resolver and Content Provider
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();
//Capture all the existing field values excluding name
Cursor apu = getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
apu.moveToFirst();
int index;
index = apu.getColumnIndex("apn");
String apn = apu.getString(index);
index = apu.getColumnIndex("type");
String type = apu.getString(index);
index = apu.getColumnIndex("proxy");
String proxy = apu.getString(index);
index = apu.getColumnIndex("port");
String port = apu.getString(index);
index = apu.getColumnIndex("user");
String user = apu.getString(index);
index = apu.getColumnIndex("password");
String password = apu.getString(index);
index = apu.getColumnIndex("server");
String server = apu.getString(index);
index = apu.getColumnIndex("mmsc");
String mmsc = apu.getString(index);
index = apu.getColumnIndex("mmsproxy");
String mmsproxy = apu.getString(index);
index = apu.getColumnIndex("mmsport");
String mmsport = apu.getString(index);
index = apu.getColumnIndex("mcc");
String mcc = apu.getString(index);
index = apu.getColumnIndex("mnc");
String mnc = apu.getString(index);
index = apu.getColumnIndex("numeric");
String numeric = apu.getString(index);
//Assign them to the ContentValue object
values.put("name", name); //the method parameter
values.put("apn", apn);
values.put("type", type);
values.put("proxy", proxy);
values.put("port", port);
values.put("user", user);
values.put("password", password);
values.put("server", server);
values.put("mmsc", mmsc);
values.put("mmsproxy", mmsproxy);
values.put("mmsport", mmsport);
values.put("mcc", mcc);
values.put("mnc", mnc);
values.put("numeric", numeric);
//Actual insertion into table
Cursor c = null;
try{
Uri newRow = resolver.insert(APN_TABLE_URI, values);
if(newRow != null){
c = resolver.query(newRow, null, null, null, null);
int idindex = c.getColumnIndex("_id");
c.moveToFirst();
id = c.getShort(idindex);
}
}
catch(SQLException e){}
if(c !=null ) c.close();
}
return id;
}
//Takes the ID of the new record generated in InsertAPN and sets that particular record the default preferred APN configuration
public boolean SetPreferredAPN(int id){
//If the id is -1, that means the record was found in the APN table before insertion, thus, no action required
if (id == -1){
return false;
}
Uri.parse("content://telephony/carriers");
final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
boolean res = false;
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();
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){}
return res;
}
然后您可以像这样调用该方法:
int identity = InsertAPN(NEW_APN_NAME);
SetPreferredAPN(identity);
关于Android 4.2.1 - 以编程方式更新 APN 设置数据库中的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24054893/
我是一名 iOS 开发人员,有人问我什么类型(整个,即 header 和正文)的请求来点击 APN 以获取设备通知。 我读了很多关于 APN 服务器设置的教程,但我无法理解,因为我对 PhP 和 No
当我靠近 iBeacon 时,我需要得到提醒,为此我正在使用第三方 iBeacon 管理服务,即 https://admin.lighthousebeacon.io/applications/5411
缺少推送通知授权 - 您的应用似乎注册了 Apple 推送通知服务,但应用签名的授权不包括“aps-environment”授权。如果您的应用程序使用 Apple 推送通知服务,请确保您的应用程序 I
考虑这种情况: 应用程序当前不在前台,但在后台处于未挂起状态(appDidEnterbackground:已调用) 设备收到应用程序的 3 个 APN,用户将警报样式设置为“警报” 用户单击最顶部(第
这个问题在这里已经有了答案: Remote notification method called twice (2 个答案) 关闭 7 年前。
我想在 iphone 应用程序中使用简单的 apns,但我不知道是否可以将 apns 与 forge 一起使用(不要使用 Parse 服务),我找不到任何 API,在 phoneGap 中,我可以编辑
我支持一个移动应用程序。最近我收到一封电子邮件,“apns 生产证书即将到期”。之后我检查了我的后端,发现没有使用任何证书,只有身份验证 key 。据我所知,身份验证 key 没有到期 key 。我想
作为一名 iOS 开发者。我知道在我们的项目中以编程方式实现 APN。但是,我假设我们正在从 APN 服务器接收 APN 消息。我不知道 我们如何托管 APN 消息? 如何为我们创建真正的 APN 服
我的应用通过 APNS 发送和接收消息。但如果客户端的通知被触发,则客户端不会收到其他客户端通过 APNS 发送的消息。 这是错误的方式吗?如果不是,当客户端的通知触发时,客户端如何接收消息? 最佳答
我已经从这个 Apns code 为 php 和 objective-c 完成了 apns 代码 并从 this link 设置证书 用于向 iOS 设备发送通知的沙盒和生产 apns 在我的服务器上
从沙箱模式到生产模式,设备 token 有何不同? 我认为我已将一些设备 token 锁定为生产模式,并且无法将它们从开发中插入。 关于如何检查有什么想法吗? 最佳答案 当您使用开发证书构建应用程序时
我有一个 FCM 项目成功向 iOS 和 Android 用户发送推送通知。新 iOS 用户订阅并检索 FCM token 。 但是,我也有许多使用旧 iOS 应用程序并直接订阅 APNS 的用户,我
我真的很难弄清楚如何将消息从我的服务器发送到 APNS。我使用过 Moon-APNS 和 APNS-Sharp,但我遇到了同样的错误,即“参数不正确”。我使用 KeyChain 生成了 p12 文件。
Apple 最近向 APNS 添加了一种新的身份验证方法 ( Apple Push Notification Authentication Key (Sandbox & Production) )。
我正在将 Firebase Messaging 用于 iOS 和 Android 推送通知。 我正在使用新的“APNs 身份验证 key ”机制,而不是“APN 证书” 我收到 Apple 发来的一封
我正在开发一个处理推送通知的 iOS 应用程序。我们的推送通知服务器是用 ColdFusion 编写的,并使用 com.notnoop.apns.SimpleApnsNotification 发送通知
根据 Apple's APNs docs ,从 iOS 13 开始,http api 的客户端 必须 发送 apns-push-type 和 apns-priority 的 header 字段,否则请
我们可以在 Blackberry 中获取 APN 名称,但我是否知道有什么方法可以在应用程序中设置 APN。请帮我解决这个问题? 提前致谢 最佳答案 你当然可以。但我想您知道 apn 仅适用于直接连接
我在一些 stackOverflow 帖子中读到,主机需要打开端口 2195 并支持 apns 下的推送通知。如何让我的服务器支持 apns。 推送通知指南中这一行的含义是什么 要建立可信的提供商身份
在应用程序被批准进入应用程序商店之前,生产 APNS 是否不可用?我可以很好地使用沙箱证书,但生产没有产生任何结果。 最佳答案 如果您使用分发配置文件构建应用程序(与临时构建一样),则可以使用生产推送
我是一名优秀的程序员,十分优秀!