开发者

Setting airplane mode does not completely work

I've written the code below to set the phone into airplane mode to save power. The devices is being used as a WiFi-Hotspot to relay data from some sensors in a village in Indonesia. The sensors send their data at the same time so I just need to come out of airplane mode for five minutes at midnight and then reenter airplane mode.

The problem is the cellular radio is not shut off and the airplane icon does not appear. Though the the phone reports its status as airplane_mode on, it is still possible to call it. Other widgets in the marketplace seem to fare no better. I've tried "Airplane Mode Wi-Fi Tool". It too can not get the airplane icon to appear nor disable cell radio. When watching LogCat while using the device settings to go to Airplane mode, I can see that much more is happening than when trying from the program.

If I load my program on a Droid, this code works as expected. AIRPLANE_MODE_RADIOS is set to cell, bluetooth, wifi.

The offending device is a Samsung Galaxy 5, I5500 tested with:

-Froyo 2.2 build FROYO.UYJP2 -Froyo 2.2.1 build FROYO.UYJPE

One interesting side note: if I programmatically set airplane mode and then power cycle the device, it comes up in full airplane mode, rejects incoming calls etc.

Do others have similar stories with this or other devices? Is there a way to specifically turn off cell only?

public static void setAirplaneMode(Context context, boolean status) {

    boolean isAM = Settings.System.getInt(context.getContentResolver(),
            Settings.System.AIRPLANE_MODE_ON, 0) != 0;

    String radios = Settings.System.getString(context.g开发者_如何学PythonetContentResolver(),
            Settings.System.AIRPLANE_MODE_RADIOS);

    //This line is reporting all radios affected but annunciator does not seem to think so. Does not show airplane
    Wake.logger("Airplane mode is: " + isAM + " changing to " + status + " For radios: " + radios, false);

    // It appears Airplane mode should only be toggled. Don't reset to
    // current state.
    if (isAM && !status) {
        Settings.System.putInt(context.getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON, 0);
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", 0);
        context.sendBroadcast(intent);
        return;
    }
    if (!isAM && status) {
        Settings.System.putInt(context.getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON, 1);
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", 1);
        context.sendBroadcast(intent);
        return;
    }
}


Classic bit twister error. The extra data argument in the broadcast intent needed to be true/false, not 1/0. Ugh!!!

    intent.putExtra("state", true);  //Not 1!!

One phone worked another didn't. Now both do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜