Вы находитесь на странице: 1из 3

API DOCUMENTATION

Honeywell Android Battery Swap Intent API

Summary
The Battery Swap Intent API allows applications to receive broadcast intents and handle battery swap
transitions. Applications may save the application context and release resources before swapping the
battery and resume operations after the battery swap is completed.

This API is available on Honeywell Android handheld computers that support the hot-swap battery
feature. Applications may receive the battery swap intents using an Android broadcast receiver without
a Honeywell SDK.

To see if your Android computer supports the hot-swap battery feature, you may press and hold the
power button until it displays a popup menu. You shall see a menu option for battery swap. Please
follow the onscreen instructions to properly activate the hot-swap battery feature before removing the
battery. For more information regarding the hot-swap battery feature, please refer to the Android
computer’s user manual.

Interface Details
Battery Swap Started Intent
This intent is broadcasted immediately after the user confirms the start of hot-swap battery operation.
This intent is an ordered broadcast.

Action: "com.honeywell.batteryswap.STARTED"

Data URI: None

MIME Type: None

Battery Swap Completed Intent


This intent is broadcasted after a battery swap is completed.

Action: "com.honeywell.batteryswap.COMPLETED"

Data URI: None

MIME Type: None

Extras

"EXTRA_UNCONTROLLED" (boolean): Set to true if the user removed the battery without first
activating the how-swap battery feature on the Android computer; otherwise, set to false.

Honeywell Android Battery Swap Intent API


API DOCUMENTATION

Xamarin.Android Code Snippet: MainActivity


using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Content;
using Android.OS;

namespace BatterySwapDemo.Droid
{
[Activity(Label = "BatterySwapDemo", Icon = "@drawable/icon", Theme = "@style/MainTheme",
MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize |
ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
public const string BatterySwapStarted = "com.honeywell.batteryswap.STARTED";
public const string BatterySwapCompleted = "com.honeywell.batteryswap.COMPLETED";

private BatteryBroadcastReciever mBatteryBroadcastReceiver = null;

protected override void OnCreate(Bundle bundle)


{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(bundle);

global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new BatterySwapDemo.App());

// Register a broadcast receiver to receive battery swap intents.


mBatteryBroadcastReceiver = new BatteryBroadcastReciever();
IntentFilter intentFilter = new IntentFilter();
intentFilter.AddAction(BatterySwapStarted);
intentFilter.AddAction(BatterySwapCompleted);
RegisterReceiver(mBatteryBroadcastReceiver, intentFilter);
}

protected override void OnDestroy()


{
UnregisterReceiver(mBatteryBroadcastReceiver);
}

class BatteryBroadcastReciever : BroadcastReceiver


{
/// <summary>
/// Implements the BroadcastReceiver interface.
/// </summary>
/// <param name="context">The Context in which the receiver is running.</param>
/// <param name="intent">The received intent.</param>
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action == BatterySwapStarted)
{
// User has started the hot-swap battery procedure.
// Add application logic to save data, release resources, etc.
// before the battery is removed.
}
else if (intent.Action == BatterySwapCompleted)
{
if (intent.GetBooleanExtra("EXTRA_UNCONTROLLED", true))
{
// Battery has been replaced; however, the user has not started

Honeywell Android Battery Swap Intent API


API DOCUMENTATION

// the hot-swap battery procedure before the battery was removed.


}
else
{
// Battery swap completed. The application may resume normal
// operations.
}
}
}
}
}
}

Honeywell Android Battery Swap Intent API

Вам также может понравиться