在Android编程设置APN [英] Set APN programmatically on Android

查看:530
本文介绍了在Android编程设置APN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我想获取所有可用的APN,并检查客户端APN可用。我想用这个客户端APN运行我的应用程序。

In my Android application I would like get all the available APNs and check if the client APN is available. I would like to run my app using this client APN.

有没有办法来实现这一目标在Android?

Is there a way to achieve this on Android?

推荐答案

如果你想读的APN为Android 4.2及以上,他们是换做。我测试了它,和它的作品。

If you want to read the APN for Android 4.2 and more they are a change to do. I tested it, and it works.

在安卓4.1及以上版本使用这样的:

In Android 4.1 and above use this:

Cursor c = getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), null, null, null, null);

和为Android 4.2和更多使用code:

And for Android 4.2 and more use this code:

private static final String[] APN_PROJECTION = {
     Telephony.Carriers.TYPE,            // 0
     Telephony.Carriers.MMSC,            // 1
     Telephony.Carriers.MMSPROXY,        // 2
     Telephony.Carriers.MMSPORT          // 3
 };

这行:

final Cursor apnCursor =SqliteWrapper.query(context, this.context.getContentResolver(), Uri.withAppendedPath(Carriers.CONTENT_URI, "current"), APN_PROJECTION, null, null, null);

该SQLiteWrapperClass是隐藏的(我发现这个班在互联网上)。

The SQLiteWrapperClass is hidden (I found this class on the Internet).

import android.database.sqlite.SqliteWrapper;

这篇关于在Android编程设置APN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆