在Android上使用飞行模式的麻烦 [英] trouble using Airplane Mode on Android

查看:356
本文介绍了在Android上使用飞行模式的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我troube使用飞行模式我的应用程序。该应用程序完美运行良好在我的仿真器,但不是我的真实的电话时,我尽我的apk。

I have troube to use Airplane mode on my app. The app runs perfectly well on my emulator but not in my real phone when I try my apk.

下面是code激活飞机:

Here is the code to activate the Airplane :

Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 1);
        // Post an intent to reload
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        // send a broadcast
        //intent.putExtra("state", !isEnabled);
        intent.putExtra("state", true);
        sendBroadcast(intent);

要desactivate吧:

To desactivate it :

Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
        // Post an intent to reload
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        // send a broadcast
        intent.putExtra("state", false);
        sendBroadcast(intent);

我读,我不能创建的意图(<一个href=\"http://developer.android.com/reference/android/content/Intent.html#ACTION_AIRPLANE_MODE_CHANGED\"相对=nofollow>安卓DOC ),但我看到的人,可以使飞行模式,所以我不明白!

I read that I cannot create the intent (android doc) but I saw people that could make airplane mode so I don't understand!

感谢帮助我!

推荐答案

您的不能播出系统级的意图。这是非法的由Android的标准。

You CANNOT broadcast a System level intent. This is illegal by android's standards.

而不是试图发送的意图,你为什么不只是实现广播reciever听的具体行动,然后当它的变化,有您的应用程序处理。这将是一个更好的方法。你不能也不应该不会期望控制飞行模式,但你的应用程序可以收听电台调用时。您也可以检索,告诉您该系统数据库中的财产,如果它在飞行模式。

Instead of trying to send the intent, why don't you just implement a broadcast reciever to listen to that specific action and then when it changes, have your application handle it. This would be a much better approach. You cannot and should NOT expect to control airplane mode, but your app can listen to when it is invoked. You can also retrieve a property from the System database that tells you if its in airplane mode.

再次不要专注于试图控制它,只是处理它。

Once again Do not focus on trying to control it, just handle it.

这篇关于在Android上使用飞行模式的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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