android - 查询 Android Telephony.Carriers 公共类时出现“获取 Mms 运营商值时出错”
问题描述
我无法获取“服务器”、“mms_proxy”和“mms_port”。我在谷歌的任何地方都没有找到任何关于为什么会这样的官方信息?我会假设如果这是我不能做的事情,那么谷歌会说明这一点。
Android 开发者网站显示了 Telephony.Carriers 类和所有可用的类,但没有说明任何类型的限制,所以在这一点上,我相信可以公平地假设我可以访问这些,而不是让用户找到 APN 值手动,这会让很多人立即放弃而不使用我的应用程序。
我们能否尝试找到关于这里发生的事情的官方答案,我试图以多种方式获取这些信息,所有这些都导致了看似无法解释的非常令人困惑的错误。
我在设备 ZTE Axon 7 上运行 Android 6.01。我的应用程序允许的最低 api 是 api_21 和 api_19 及更高版本中可用的 Telephony.Carriers 类。
我已经在 Manifest 文件中声明了所有必要的权限,并且由于我目前正在 sdk“M”(Android 6)上进行测试,因此我还在运行时明确地从用户那里获得了权限。
这是我运行的 Activity 中的代码,并收到一条错误消息,指出“获取 Mms 载波值时出错”......这是整个问题,也是我陷入困境的地方。
ContentResolver contentResolver = getContentResolver();
int index_ID;
final String[] PROJECT =
{
Telephony.Carriers.TYPE,
Telephony.Carriers.MMSC,
Telephony.Carriers.MMSPROXY,
Telephony.Carriers.MMSPORT,
};
grantMyUriPermission(activity, Telephony.Carriers.CONTENT_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
grantMyUriPermission(activity, Telephony.Carriers.CONTENT_URI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Cursor carriers_cursor = SqliteWrapper.query(activity, contentResolver,
Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), PROJECT, null, null, null);
if (carriers_cursor != null)
{
/*This crap below isn't needed for this situation but helps avoid ERROR*/
index_ID = carriers_cursor.getColumnIndex(Telephony.Carriers._ID);
//--------------------------------------------------------------------------------------
if (index_ID < 0 || !carriers_cursor.moveToFirst())
{
Log.i(TAG, "Error getting Mms Carrier values");
carriers_cursor.close();
return;
}
//--------------------------------------------------------------------------------------
do
{
//Confirm cursor has value assigned to it
Log.i(TAG, "cursor: "+ carriers_cursor);
//Get the available columns names
for (String item : carriers_cursor.getColumnNames())
{
//Name of each column available with Cursor
Log.i(TAG, "item: " + item);
//Attempt to get String value for each available column
try
{
//Use the name of the column, to get the index, to get the String value
Log.i(TAG, "getString(): " + carriers_cursor.getString(carriers_cursor.getColumnIndex(item)));
}
catch (Exception e)
{
Log.i(TAG, "Exception: " + e);
}
}
}
while (carriers_cursor.moveToNext());
carriers_cursor.close();
}
日志输出为:
I/SmsReceiveIntentService:运行 grantMyUriPermission()
I/SmsReceiveIntentService:运行 grantMyUriPermission()
I/NewConversationActivity:获取 Mms 运营商值时出错
就是这样!没有别的事可做……?
解决方案
推荐阅读
- linux - 为什么linux内核TCPIP堆栈不使用一些设计模式来处理skb,比如责任链?
- c++ - 导入 cstring 失败:包括
错误 - python - 如何迭代由对象组成的 numpy.ndarray?还对它们应用各种功能
- azure - Azure Functions (2.0) 上的 Twilio
- javascript - Angular7(在 Angular 6 中没问题) ERROR TypeError: "e[n] is undefined" on firefox only in dev only due to "loading" variable in redux?
- ruby - ENV.fetch 与块或第二个参数有什么区别?
- javascript - 将量角器测试项目从 javascript 移植到 typescript 的步骤
- react-router-v4 - redux-observable 史诗中使用的“connected-react-router”中的`push`不会更改 url 并呈现空白页面
- excel - 基于日期的 Excel VBA 种子
- mysql - 在 mysql 上选择日期列只给出 0000-00-00 结果