在 Android 上以编程方式检测和更改数据连接 (GPRS/UMTS)

发布于 2024-09-05 12:46:06 字数 192 浏览 2 评论 0原文

我知道不幸的是,无法在普通 Android 上以编程方式检测和更改数据连接 (GPRS/UMTS),常见的解决方法是编辑 APN 设置。这并不是一个好的解决方案。

然而,在我的设备(Xperia X10)上,我在“数据漫游”附近有一个附加设置,允许启用或禁用彩信和数据。我想这是索尼爱立信做的个性化设置,也许其他厂商也有类似的东西。有没有办法访问此设置?

I know that unfortunately detecting and changing programmatically data connection (GPRS/UMTS) on vanilla Android is not possible, and the common workaround is to edit APN settings. This is hardly a nice solution.

However on my device (Xperia X10) I have an additional setting near "data roaming", that allows to enable or disable MMS and data. I suppose that this is a personalization made by Sony Ericsson, and maybe even other vendors have something like this. Is there a way to access this setting?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

套路撩心 2024-09-12 12:46:06

我没有 SE 手机,但我查看了它的系统转储并且:

  • 在 AOSP 源中,com.android.internal.telephony 接口中有两个内部方法:enableDataConnectivity() 和disableDataConnectivity()。该接口及其实现是系统的一部分。
  • com.android.phone.PhoneInterfaceManager 中还有两个与上面名称相同的方法,它是 Phone.apk 应用程序的一部分。这些方法只是调用上面/系统的方法。
  • Sony 修改了 com.android.phone.PhoneInterfaceManager.enableDataConnectivity(),因此它对共享首选项中存储的布尔值进行额外检查。如果为 false,则 enableDataConnectivity() 方法始终调用 com.android.internal.telephony 的disableDataConnectivity() 。
  • 当然,这个布尔值是通过首选项屏幕控制的:“彩信和数据”。它存储在“com.android.phone_preferences”首选项容器中,首选项键为:“data_service_key”。此外,当您切换此复选框时,设置活动会自动调用 com.android.internal.telephony 中的方法来立即切换数据状态。

如果您想向您的 ROM 添加数据连接小部件或类似的东西,那么:

  • 您需要 root。
  • 您需要“android.uid.phone”sharedUserId 才能访问上述设置。

我认为最好修改 Phone.apk,这样它就会捕获启用/禁用数据的特殊意图。它将设置 data_service_key 布尔值并调用 com.android.internal.telephony 中的方法之一。这应该是一件很容易做的事情,然后你将能够非常轻松地创建小部件、应用程序和其他东西 - 他们会使用这种特殊的意图。

I don't have SE phone, but I've looked into its system dump and:

  • In AOSP sources there are two internal methods in com.android.internal.telephony interface: enableDataConnectivity() and disableDataConnectivity(). This interface and its implementation is a part of the system.
  • There are also two methods with same names as above in com.android.phone.PhoneInterfaceManager which is a part of Phone.apk app. These methods just call above/system ones.
  • Sony modified com.android.phone.PhoneInterfaceManager.enableDataConnectivity(), so it does additional check for boolean stored in sharedPreferences. If it's false, then enableDataConnectivity() method always calls disableDataConnectivity() of com.android.internal.telephony .
  • Of course this boolean is controlled through preferences screen: "MMS & data". It's stored in "com.android.phone_preferences" preferences container and pref key is: "data_service_key". Additionally when you switch this checkbox, settings activity automatically calls methods from com.android.internal.telephony to switch data state immediately.

If you want to add data connection widget or something like that to your rom, then:

  • You need root.
  • You need "android.uid.phone" sharedUserId to access above settings.

I think it would be best to modify Phone.apk, so it will catch special intent to enable/disable data. It would set data_service_key boolean and call one of methods from com.android.internal.telephony. This should be quite easy thing to do and then you will be able to create widgets, apps and other stuff very easily - they would use that special intent.

栀梦 2024-09-12 12:46:06

您是否看过SE 开发者专区?我发现它非常有用。

Have you looked at SE developer zone? I found it to be pretty useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文