android-broadcast

How to create BroadcastReceiver without Activity/Service?

柔情痞子 提交于 2019-12-31 00:55:09
问题 I'm trying to create BroadcastReceiver without activity/service. While I've no problem registering and executing the code when an activity is present in the code when I remove the activity it fails. I do register the BroadcastReceiver using the manifest(!) But it is not being called when the activity is removed from the project. <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <receiver android:name

Is instantiating an AsyncTask from a WakefulBroadcastReceiver recommended?

一曲冷凌霜 提交于 2019-12-30 11:01:42
问题 I can instantiate an AsyncTask from WakefulBroadcastReceiver (see my motivation for favouring AsyncTask over Service), e.g., public abstract class AlarmReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { new AsyncTask<Void,Void,Void>(){ @Override protected Void doInBackground(Void... v) { while (true) { SystemClock.sleep(7000); Log.w("", "alive"); } } }.execute(); } } But is this recommendable? In particular, are there life cycle

Android Widget+Service

谁说胖子不能爱 提交于 2019-12-25 08:13:55
问题 I have a music player which plays music using a service,all the broadcast receivers within that service are defined inside the service and not externally. I am totally new to widgets so i had been seeing a few tutorials.But they didn't help me much I am totally new to pending intents soo.I am so confused right now please help me out... All i want to do is just trigger the broadcast inside the service using the button of the widget ... Here is the copy pasted code which i had been trying to

IntentService does broadcast but onReceive doesn't receive broadcast

笑着哭i 提交于 2019-12-25 06:52:00
问题 (NOTE that at the end of this Question I have an EDIT in which I have replaced one method with what the Answer said to do in order to fix the problem of onReceive never getting called and added onDestroy to fix a new problem that cropped up after fixing first problem. ) Here's how I attempted to capture the broadcast data, but onReceive never gets called since Log.w never displays anything: public class MatchesActivity extends Activity implements DatabaseConnector.DatabaseProcessListener {

Service Broadcast Receiver Logs more than expected

旧街凉风 提交于 2019-12-25 02:29:00
问题 My problem is that I think my service runs multiple times. The service is controlled by a switch calling a method that starts and stops the service. I have a broadcast listener inside my service and the receiver logs whenever it receives a broadcast. at first switch on, it logs two times. After switch off and on, it logs four times. public class Service1 extends Service implements DetectionListener { private static final String TAG = "ListenerService"; private final broadcastReceiver1

Android keep BroadcastReceiver while the app is closed

荒凉一梦 提交于 2019-12-25 00:38:02
问题 I use BroadcastReceiver of ACTION_BATTERY_CHANGED to get an event every time the battery is 50%. I can't declare ACTION_BATTERY_CHANGED in manifest, so I declared the BroadcastReceiver in a Service (START_STICKY). But, when I remove the app from recent apps screen the BroadcastReceiver stops getting battery change events. How can I keep it in background? *In many apps that show battery percent in status bar, the percent is updated while the app is closed. How? 回答1: You really cannot do what

How to retain progress bar state while switching the fragments?

戏子无情 提交于 2019-12-24 11:27:33
问题 I have a navigation drawer where these many options are present Image material Video Material Audio Material We are maintaining separate fragment for each material and every fragment have grid view in which we are populating thumbnail of that material. Once user click on the thumbnail a full material will be downloaded(Using AsyncTask). I am displaying the progress bar over the thumbnail while downloading the full material. Now here i stuck to a problem that suppose progress bar is showing 20

Notification every day at the same time

有些话、适合烂在心里 提交于 2019-12-24 06:46:14
问题 What I want I want a notification every day at the same time. I already read some posts and tutorials/examples but it won't work correctly. Version 1 The Error: Android process / service dies every ~3 minutes after re/starting 11-07 07:33:05.725 4611 6121 I ActivityManager: Process at.htl3r.appmosphere (pid 5238) has died. 11-07 07:33:05.725 4611 6121 W ActivityManager: Scheduling restart of crashed service at.htl3r.appmosphere/.notify.NotifyService in 14648ms 11-07 07:33:20.400 4611 4632 I

BroadcastReceiver Intent.ACTION_PACKAGE_ADDED/REMOVED Android Oreo

穿精又带淫゛_ 提交于 2019-12-24 01:37:09
问题 This is my broadcast receiver class and the implementation of it in main. Problem is that onReceive method never gets called. class MyBroadcastReceiver : BroadcastReceiver() { override fun onReceive(p0: Context?, p1: Intent?) { Toast.makeText(p0, "It works", Toast.LENGTH_LONG).show() } } class MainActivity : AppCompatActivity() { ...... private var broadcastReceiver: MyBroadcastReceiver = MyBroadcastReceiver() override fun onCreate(savedInstanceState: Bundle?) { ...... registerReceiver

Broadcast receiver with AIRPLANE_MODE not working with SDK 26

最后都变了- 提交于 2019-12-23 19:13:26
问题 Normaly, I use a simple code to put a Toast when the user change the AIRPLANE_MODE , and it work using targetSdkVersion 25 . My AirPlaneModeReceiver : public class AirPlaneModeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "I receive a Broadcast", Toast.LENGTH_SHORT).show(); } } The part of the Manifest where I declare my Receiver : <receiver android:name=".AirPlaneModeReceiver"> <intent-filter> <action android