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

问题描述

有人知道,如果有一个编程的方式来使用特定的定义APN这是不是默认的设备上?

Someone know if there's a programmatically way to use a specific defined APN on the device which is not the default one?

感谢。

推荐答案

您可以通过编程方式查询并设置preferred APN使用URI 内容://电话/运营/ preferapn 。要设置pferred APN你必须通过在现有APN条目的数据库ID设置一个新的$ P $。如果你通过在APN的显示名称下面的函数可以做到这一点(例如:设置preferredApn(背景下,Giffgaff);

You can programmatically query and set the preferred APN using the uri content://telephony/carriers/preferapn. To set a new preferred APN you have to pass in the database ID of an existing APN entry. The following function can do this if you pass in the display name of the APN (eg: setPreferredApn(context, "Giffgaff");)

public static final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
public static final Uri APN_PREFER_URI = Uri.parse("content://telephony/carriers/preferapn");

public static boolean setPreferredApn(Context context, String name) {
    boolean changed = false;
    String columns[] = new String[] { Carriers._ID, Carriers.NAME };
    String where = "name = ?";
    String wargs[] = new String[] {name};
    String sortOrder = null;
    Cursor cur = context.getContentResolver().query(APN_TABLE_URI, columns, where, wargs, sortOrder);
    if (cur != null) {
        if (cur.moveToFirst()) {
            ContentValues values = new ContentValues(1);
            values.put("apn_id", cur.getLong(0));
            if (context.getContentResolver().update(APN_PREFER_URI, values, null, null) == 1)
                changed = true;
        }
        cur.close();
    }
    return changed;
}

我想我应该补充一点,你需要WRITE_APN_SETTINGS许可,并需要进口android.provider.Telephony和android.provider.Telephony.Carriers

I guess I should add that you need WRITE_APN_SETTINGS permission and need to import android.provider.Telephony and android.provider.Telephony.Carriers

更新4.0 +

该工厂成为了Android 4.0(ICS)的发布禁止。启用WRITE_APN_SETTINGS权限对允许你设置APN更多没有影响。请参见这个问题了解一些相关的链接。在 API页面现在明确规定这个权限是不适合外用,这是在内部执行。

This facility became disabled with the release of Android 4.0 (ICS). Enabling the WRITE_APN_SETTINGS permission has no effect on allowing you to set the APN any more. See this question for some relevant links. On the API page it now states explicitly this permission is not for external use and this is enforced internally.

这篇关于Android的APN执法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 05:51