在我的应用程序中收到 Android 的热关机通知
Receive notification of Android's thermal shutdown in my application
我想在 Android 由于热环境而关闭之前在我的应用程序中收到通知。
这是关机本身的 logcat:
[ 07-26 11:59:16.191 521: 1067 I/system_monitor ]
alarm_callback - Received MAX alarm: batt_therm at Level:1
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
handle_notification - Called
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
handle_notification - Dumping notification
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
name: batt_therm
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
current_level: 0
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
prev_level: 1
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
shutdown_in: 20
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
Adding action: SHUTDOWN
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
handle_notification - Going to callback function
[ 07-26 11:59:16.196 968: 6013 I/libsysmon ]
[ 07-26 11:59:16.196 968: 6013 I/libsysmon ]
[ 07-26 11:59:16.276 521: 1067 E/system_monitor ]
write_miscta_sysmon_log - read error[10022].
[ 07-26 11:59:16.284 186: 186 I/tad ]
MiscTA Unit 10022:
[ 07-26 11:59:16.284 186: 186 I/tad ]
NOT WRITTEN (Identical)
[ 07-26 11:59:16.284 186: 186 I/tad ]
MiscTA: Write of unit 10022 completed - OK
[ 07-26 11:59:16.311 186: 186 I/tad ]
MiscTA Unit 10025:
[ 07-26 11:59:16.312 186: 186 I/tad ]
WRITTEN (Size 50)
[ 07-26 11:59:16.409 186: 186 I/tad ]
Actual erase/write to flash done (count 1, time 1564135156).
[ 07-26 11:59:16.409 186: 186 I/tad ]
MiscTA: Write of unit 10025 completed - OK
[ 07-26 11:59:16.431 186: 186 I/tad ]
MiscTA Unit 10024:
[ 07-26 11:59:16.431 186: 186 I/tad ]
WRITTEN (Size 50)
[ 07-26 11:59:16.494 186: 186 I/tad ]
Actual erase/write to flash done (count 2, time 1564135156).
[ 07-26 11:59:16.494 186: 186 I/tad ]
MiscTA: Write of unit 10024 completed - OK
[ 07-26 11:59:16.501 186: 186 I/tad ]
MiscTA Unit 10023:
[ 07-26 11:59:16.501 186: 186 I/tad ]
WRITTEN (Size 50)
[ 07-26 11:59:16.574 186: 186 I/tad ]
Actual erase/write to flash done (count 3, time 1564135156).
[ 07-26 11:59:16.574 186: 186 I/tad ]
MiscTA: Write of unit 10023 completed - OK
[ 07-26 11:59:16.576 521: 1067 I/system_monitor ]
Shutting down
[ 07-26 11:59:16.996 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:16.996 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:18.009 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:18.009 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:18.221 2217: 2231 I/art ]
Background sticky concurrent mark sweep GC freed 64885(3MB) AllocSpace objects, 0(0B) LOS objects, 10% free, 27MB/30MB, paused 9.626ms total 105.405ms
[ 07-26 11:59:18.336 968: 1034 W/PackageManager ]
Invalid verification token 0 received
[ 07-26 11:59:18.993 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:18.993 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:19.984 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:19.984 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:20.983 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:20.983 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:21.666 968: 1572 W/InputMethodManagerService ]
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@1cafeb50 attribute=null, token = android.os.BinderProxy@224ee282
[ 07-26 11:59:21.727 968: 1028 I/MediaFocusControl ]
AudioFocus requestAudioFocus() from android.media.AudioManager@2079c149 req=1flags=0x0
[ 07-26 11:59:22.064 968: 5233 W/ShutdownThread ]
Disabling Bluetooth...
[ 07-26 11:59:22.069 968: 5232 I/ShutdownThread ]
Sending shutdown broadcast...
[ 07-26 11:59:22.078 968: 5232 I/ShutdownThread ]
Shutting down activity manager...
[ 07-26 11:59:22.084 968: 968 W/SyncManager ]
Writing sync state before shutdown...
[ 07-26 11:59:22.097 1930: 1930 I/GPSManager ]
location.getAccuracy() 5.0
[ 07-26 11:59:22.097 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:22.240 4674: 4750 I/BluetoothAdapterState ]
Bluetooth adapter state changed: 12-> 13
[ 07-26 11:59:22.274 968: 5233 W/ShutdownThread ]
Turning off cellular radios...
[
如何接收关机事件的广播?有可能吗?
日志中有一行声明将在 20 秒后关闭。当该事件发生时,我希望在我的应用程序中收到通知 - 因此应用程序可以在实际关闭之前执行必要的操作。
谢谢。
检查清单文件中的以下内容:
添加权限:
<uses-permission android:name="android.permission.DEVICE_POWER" />
添加收件人:
<receiver android:name=".ShutdownReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
制作广播接收器:
private class ShutDownReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
if(Intent.ACTION_SHUTDOWN.equals(intent.getAction()))
{
Log.i(TAG, "System shutting down");
context.stopService(new Intent(context, BluetoothPanService.class));
}
}
}
在 activity 的主要 onResume() 方法中实例化并注册接收器:
public void onResume()
{
super.onResume();
Log.i(TAG, "Measurement Log Activity has Resumed.");
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
mReceiver = new ShutDownReceiver();
registerReceiver(mReceiver, filter);
}
最后在主要 activity 的 onPause() 中注销接收器:
public void onPause()
{
super.onPause();
Log.i(TAG, "Measurement Log Activity has Paused.");
this.unregisterReceiver(mReceiver);
}
另见 this and this。希望对你有帮助。
我想在 Android 由于热环境而关闭之前在我的应用程序中收到通知。
这是关机本身的 logcat:
[ 07-26 11:59:16.191 521: 1067 I/system_monitor ]
alarm_callback - Received MAX alarm: batt_therm at Level:1
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
handle_notification - Called
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
handle_notification - Dumping notification
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
name: batt_therm
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
current_level: 0
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
prev_level: 1
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
shutdown_in: 20
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
Adding action: SHUTDOWN
[ 07-26 11:59:16.195 968: 6013 I/libsysmon ]
handle_notification - Going to callback function
[ 07-26 11:59:16.196 968: 6013 I/libsysmon ]
[ 07-26 11:59:16.196 968: 6013 I/libsysmon ]
[ 07-26 11:59:16.276 521: 1067 E/system_monitor ]
write_miscta_sysmon_log - read error[10022].
[ 07-26 11:59:16.284 186: 186 I/tad ]
MiscTA Unit 10022:
[ 07-26 11:59:16.284 186: 186 I/tad ]
NOT WRITTEN (Identical)
[ 07-26 11:59:16.284 186: 186 I/tad ]
MiscTA: Write of unit 10022 completed - OK
[ 07-26 11:59:16.311 186: 186 I/tad ]
MiscTA Unit 10025:
[ 07-26 11:59:16.312 186: 186 I/tad ]
WRITTEN (Size 50)
[ 07-26 11:59:16.409 186: 186 I/tad ]
Actual erase/write to flash done (count 1, time 1564135156).
[ 07-26 11:59:16.409 186: 186 I/tad ]
MiscTA: Write of unit 10025 completed - OK
[ 07-26 11:59:16.431 186: 186 I/tad ]
MiscTA Unit 10024:
[ 07-26 11:59:16.431 186: 186 I/tad ]
WRITTEN (Size 50)
[ 07-26 11:59:16.494 186: 186 I/tad ]
Actual erase/write to flash done (count 2, time 1564135156).
[ 07-26 11:59:16.494 186: 186 I/tad ]
MiscTA: Write of unit 10024 completed - OK
[ 07-26 11:59:16.501 186: 186 I/tad ]
MiscTA Unit 10023:
[ 07-26 11:59:16.501 186: 186 I/tad ]
WRITTEN (Size 50)
[ 07-26 11:59:16.574 186: 186 I/tad ]
Actual erase/write to flash done (count 3, time 1564135156).
[ 07-26 11:59:16.574 186: 186 I/tad ]
MiscTA: Write of unit 10023 completed - OK
[ 07-26 11:59:16.576 521: 1067 I/system_monitor ]
Shutting down
[ 07-26 11:59:16.996 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:16.996 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:18.009 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:18.009 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:18.221 2217: 2231 I/art ]
Background sticky concurrent mark sweep GC freed 64885(3MB) AllocSpace objects, 0(0B) LOS objects, 10% free, 27MB/30MB, paused 9.626ms total 105.405ms
[ 07-26 11:59:18.336 968: 1034 W/PackageManager ]
Invalid verification token 0 received
[ 07-26 11:59:18.993 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:18.993 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:19.984 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:19.984 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:20.983 1930: 1930 I/GPSManager ]
location.getAccuracy() 4.0
[ 07-26 11:59:20.983 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:21.666 968: 1572 W/InputMethodManagerService ]
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@1cafeb50 attribute=null, token = android.os.BinderProxy@224ee282
[ 07-26 11:59:21.727 968: 1028 I/MediaFocusControl ]
AudioFocus requestAudioFocus() from android.media.AudioManager@2079c149 req=1flags=0x0
[ 07-26 11:59:22.064 968: 5233 W/ShutdownThread ]
Disabling Bluetooth...
[ 07-26 11:59:22.069 968: 5232 I/ShutdownThread ]
Sending shutdown broadcast...
[ 07-26 11:59:22.078 968: 5232 I/ShutdownThread ]
Shutting down activity manager...
[ 07-26 11:59:22.084 968: 968 W/SyncManager ]
Writing sync state before shutdown...
[ 07-26 11:59:22.097 1930: 1930 I/GPSManager ]
location.getAccuracy() 5.0
[ 07-26 11:59:22.097 1930: 1930 I/AdressUpdate ]
AdressUpdate
[ 07-26 11:59:22.240 4674: 4750 I/BluetoothAdapterState ]
Bluetooth adapter state changed: 12-> 13
[ 07-26 11:59:22.274 968: 5233 W/ShutdownThread ]
Turning off cellular radios...
[
如何接收关机事件的广播?有可能吗? 日志中有一行声明将在 20 秒后关闭。当该事件发生时,我希望在我的应用程序中收到通知 - 因此应用程序可以在实际关闭之前执行必要的操作。
谢谢。
检查清单文件中的以下内容:
添加权限:
<uses-permission android:name="android.permission.DEVICE_POWER" />
添加收件人:
<receiver android:name=".ShutdownReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
制作广播接收器:
private class ShutDownReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
if(Intent.ACTION_SHUTDOWN.equals(intent.getAction()))
{
Log.i(TAG, "System shutting down");
context.stopService(new Intent(context, BluetoothPanService.class));
}
}
}
在 activity 的主要 onResume() 方法中实例化并注册接收器:
public void onResume()
{
super.onResume();
Log.i(TAG, "Measurement Log Activity has Resumed.");
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
mReceiver = new ShutDownReceiver();
registerReceiver(mReceiver, filter);
}
最后在主要 activity 的 onPause() 中注销接收器:
public void onPause()
{
super.onPause();
Log.i(TAG, "Measurement Log Activity has Paused.");
this.unregisterReceiver(mReceiver);
}
另见 this and this。希望对你有帮助。