Android:启用/禁用自动同步和后台数据

发布于 2024-07-17 13:40:04 字数 326 浏览 5 评论 0原文

我想开发一个应用程序,禁用后台数据(Android 1.5 中的新功能)和自动同步,然后启用 GPRS/EDGE 连接,反之亦然。

我弄清楚了如何通过更改 APN 设置来启用/禁用 GPRS/EDGE。 (奇怪的解决方案。但是;Android 开发人员无法认为用户可能想要禁用 GPRS/EDGE)但是,我找不到启用/禁用自动同步和后台数据的方法。

我研究了 Android 代码,据我了解,同步操作是一个意图。 因此,我想使用 putExtra 达到目的并触发启用/禁用。 但; 我找不到正确的关键字。 或者也许我完全错了。

解决这个问题的正确方法是什么?

I want to develop an application that disables the Background Data (new feature in Android 1.5) and Auto Sync and then enables GPRS/EDGE connection and vice versa.

I figured out how to enable/disable GPRS/EDGE by changing the APN settings. (weird solution. However; Android developers couldn't think a user may want to disable GPRS/EDGE) But, I couldn't find a way to enable/disable Auto Sync and Background data.

I investigated the Android code and as I understood, the Sync operation is an intent. So, I wanted to reach with putExtra to the intent and trigger the enabling/disabling. But; I couldn't find the correct keyword. Or maybe I was totally wrong.

What is the right way to solve this?

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

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

发布评论

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

评论(4

坐在坟头思考人生 2024-07-24 13:40:04

在我的 HTC 梦想中,有一个复选框可以禁用自动同步。 如果您愿意,我可以查找菜单树状图,以便您可以在 Android 源代码中找到回调函数。 但我很确定自动同步不能完全禁用。 取消选中自动同步将阻止定期执行同步,但如果有任何网络数据连接可用,则每次运行具有同步功能的应用程序时都会发生同步。

无论如何,祝你好运。

编辑:

有两种方法可以获得您想要的信息。

首先,我认为您可以使用 android-sources/packages/apps/Settings/src/com/android/settings/Utils.java 中的代码创建一个活动,该活动将征用意图的所有键,然后找到您想要的键。

另一种方法是给制作切换设置应用程序的人写一封友好的邮件(http://smartphoneandroid.com/2008/12/28/toggle-setting-perfect-app-for-android-phone.html),因为他显然找到了解决您的问题。 他的电子邮件地址写在安卓市场的应用程序表中。 我不会在这里写,但如果您无法使用真正的 Android 手机,我可以将其通过您的邮件地址邮寄给您。

In my HTC dreams, there is a checkbox to disable the auto sync. I can look for the menu arborescence if you wish so you can find what the callback function is in the Android source code. But I am pretty sure auto sync cannot be completely disabled. Unchecking auto sync will prevent sync from being performed on a timed basis, but it will occur everytime you run an app with sync capabilities if any network data connection is available.

Good luck anyway.

EDIT :

There are two ways to get the info you desire.

First, I think you can use the code in android-sources/packages/apps/Settings/src/com/android/settings/Utils.java to create an activity that will enlist all the keys of the intent then find the one you want.

The other way is to write a nice mail to the guy who made the Toggle Setting app (http://smartphoneandroid.com/2008/12/28/toggle-setting-perfect-app-for-android-phone.html) since he obviously found a solution to your problem. His email address is written in the app sheet on the android market. I won't write it here, but if you do not have access to real android phone, I can mail it to you on your mail address.

思念绕指尖 2024-07-24 13:40:04

后台数据是安全设置,因此无法通过用户应用程序。 但请记住,这只是一个设置 - 并不是强制执行的。 应用程序应该阅读它并尊重它,但我敢打赌有些应用程序不会。

Background data is a secure setting, so cannot be changed by user applications. But bear in mind, it's just a setting - it's not enforced. Apps are meant to read it and respect it but I bet some don't.

我是有多爱你 2024-07-24 13:40:04

禁用自动同步

ContentResolver.setMasterSyncAutomatically(false);

启用自动同步

ContentResolver.setMasterSyncAutomatically(true);

您需要的权限是

<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />

To Disable the AutoSynch

ContentResolver.setMasterSyncAutomatically(false);

To Enable the AutoSynch

ContentResolver.setMasterSyncAutomatically(true);

Permission you require is

<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
自在安然 2024-07-24 13:40:04

ContentResolver 上的 setMasterSyncAutomatically() 应该可以做到这一点。 检查:general-sync-settings-auto-sync-checkbox-programtically

setMasterSyncAutomatically() on ContentResolver should do it. Check: general-sync-settings-auto-sync-checkbox-programtically

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