receiver

android 监听开机(关机)

旧街凉风 提交于 2021-02-13 14:05:21
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> <receiver android:name=".BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.ACTION_SHUTDOWN"/> </intent-filter> </receiver> public class BootReceiver extends Receiver { public void onReceive(Context context, Intent intent) { if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction()) { ... } } } 来源: oschina 链接: https://my.oschina.net/u/189801/blog/103144

How to use Android AlarmManager in Fragment in Kotlin?

六月ゝ 毕业季﹏ 提交于 2021-01-12 06:30:21
问题 I can't seem to get the AlarmManager to work inside a Fragment. My receiver's onReceive() method never gets executed. I assume that I might use context in a wrong way but then again I also couldn't get it to work inside an Activity. I've also registered the receiver in my manifest. MyFragment.kt class MyFragment : Fragment() { ... override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) var alarmMgr: AlarmManager? = null lateinit var

How to use Android AlarmManager in Fragment in Kotlin?

非 Y 不嫁゛ 提交于 2021-01-12 06:29:15
问题 I can't seem to get the AlarmManager to work inside a Fragment. My receiver's onReceive() method never gets executed. I assume that I might use context in a wrong way but then again I also couldn't get it to work inside an Activity. I've also registered the receiver in my manifest. MyFragment.kt class MyFragment : Fragment() { ... override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) var alarmMgr: AlarmManager? = null lateinit var

How to use Android AlarmManager in Fragment in Kotlin?

时光毁灭记忆、已成空白 提交于 2021-01-12 06:27:08
问题 I can't seem to get the AlarmManager to work inside a Fragment. My receiver's onReceive() method never gets executed. I assume that I might use context in a wrong way but then again I also couldn't get it to work inside an Activity. I've also registered the receiver in my manifest. MyFragment.kt class MyFragment : Fragment() { ... override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) var alarmMgr: AlarmManager? = null lateinit var

Polling using Select function in C++ on Windows

偶尔善良 提交于 2020-07-22 09:16:21
问题 I am new in Socket Programming . I am trying to create a Application that uses Sockets for Communication. I have doubt in the Receive function because sometime it just hangs in recvfrom function. I am using select function for polling. It works when Camera is connected but If I remove Camera it doesn't show the Error Message. My Code for Polling: FD_ZERO(&m_readFds); FD_SET(Sock, &m_readFds); m_timeInterval.tv_usec = 30; //30 Microseconds for Polling m_socketLength = sizeof(m_cameraInfo); m

Is it possible that onPause() gets called if onResume() hasn't been called before?

蹲街弑〆低调 提交于 2020-06-17 07:57:10
问题 I register receiver in onResume() and unregister it in onPause() method. I can strange error in my Crashlytics reports: Fatal Exception: java.lang.RuntimeException Unable to pause activity {package-here}: java.lang.IllegalArgumentException: Receiver not registered: Caused by java.lang.IllegalArgumentException Receiver not registered: It happened 3 times (3 users) on 20k installs. Is it possible that onPause() gets called if onResume() hasn't been called before? I thought it isn't. 回答1: If it

Is it possible that onPause() gets called if onResume() hasn't been called before?

久未见 提交于 2020-06-17 07:57:08
问题 I register receiver in onResume() and unregister it in onPause() method. I can strange error in my Crashlytics reports: Fatal Exception: java.lang.RuntimeException Unable to pause activity {package-here}: java.lang.IllegalArgumentException: Receiver not registered: Caused by java.lang.IllegalArgumentException Receiver not registered: It happened 3 times (3 users) on 20k installs. Is it possible that onPause() gets called if onResume() hasn't been called before? I thought it isn't. 回答1: If it

品茗论道说广播(Broadcast内部机制讲解)

…衆ロ難τιáo~ 提交于 2020-04-11 12:12:24
品茗论道说广播(Broadcast内部机制讲解) 侯 亮 1 概述 我们在编写Android程序时,常常会用到广播(Broadcast)机制。从易用性的角度来说,使用广播是非常简单的。不过,这个不是本文关心的重点,我们希望探索得再深入一点儿。我想,许多人也不想仅仅停留在使用广播的阶段,而是希望了解一些广播机制的内部机理。如果是这样的话,请容我斟一杯红茶,慢慢道来。 简单地说,Android广播机制的主要工作是为了实现一处发生事情,多处得到通知的效果。这种通知工作常常要牵涉跨进程通讯,所以需要由AMS(Activity Manager Service)集中管理。 在Android系统中,接收广播的组件叫作receiver,而且receiver还分为动态和静态的。动态receiver是在运行期通过调用registerReceiver()注册的,而静态receiver则是在AndroidManifest.xml中声明的。动态receiver比较简单,静态的就麻烦一些了,因为在广播递送之时,静态receiver所从属的进程可能还没有启动呢,这就需要先启动新的进程,费时费力。另一方面,有些时候用户希望广播能够按照一定顺序递送,为此,Android又搞出了ordered broadcast的概念。 细节如此繁杂,非一言可以说清。我们先从receiver这一侧入手吧。 2 两种receiver

Within a Django Model, how can I prevent a delete based on a particular field?

China☆狼群 提交于 2020-02-28 12:29:33
问题 In the following, I have a Post model. A Post object has a status field that can be 'unpublished' or 'published' . if status is 'published' , I'd like to prevent the object from being deleted, and would like to keep this logic encapsulated in the model itself. from model_utils import Choices # from Django-Model-Utils from model_utils.fields import StatusField class Post(model.Models) STATUS = Choices( ('unpublished', _('Unpublished')), ('published', _('Published')), ) ... status = StatusField

Within a Django Model, how can I prevent a delete based on a particular field?

烈酒焚心 提交于 2020-02-28 12:27:49
问题 In the following, I have a Post model. A Post object has a status field that can be 'unpublished' or 'published' . if status is 'published' , I'd like to prevent the object from being deleted, and would like to keep this logic encapsulated in the model itself. from model_utils import Choices # from Django-Model-Utils from model_utils.fields import StatusField class Post(model.Models) STATUS = Choices( ('unpublished', _('Unpublished')), ('published', _('Published')), ) ... status = StatusField