broadcastreceiver

Checking the Networking Connectivity using BroadcastReceiver in Android

旧时模样 提交于 2019-11-27 12:15:39
I am using the BroadcastReceiver to check the network connectivity while my app is running.I have binded the BroadcastReceiver with the Activity inorder to bring few controls like AlertDialog while the connectivity goes down. but now i don't want to restrict this receiver to a particular activity instead i want to make this to be applied for my whole app(All Activities). So what way should i have to proceed to get that done... This is the code that i have used.Please let me know whether my code reaches the standard and please correct me if have gone somewhere wrong. package com.xx.mobile;

How to detect Bluetooth state change using a broadcast receiver?

余生颓废 提交于 2019-11-27 11:55:21
I am trying to make an app that shows a toast when the device's Bluetooth turned on. I wanna do that even when my app is not running. So I should use a broadcast receiver, add some permissions, an intent-filter to android manifest and make a java class but I don't know the details. What should I do? Which permissions should I use? paNji AS far as permissions go, to detect the state change of bluetooth you need to add this to your AndroidManifest.xml. <uses-permission android:name="android.permission.BLUETOOTH" /> An example receiver would look like this, you add this code to where you want to

Screen on/off broadcast listener for a widget on Android Oreo

走远了吗. 提交于 2019-11-27 11:54:22
问题 I have a clock widget Android app which I am now trying to update to API 26 requirements. Up to now I used a background service which registered upon start in its onCreate method a BroadcastReceiver to receive system broadcasts, such as android.intent.action.SCREEN_ON, android.intent.action.SCREEN_OFF, android.intent.action.TIME_SET, android.intent.action.TIMEZONE_CHANGED . This service was then pausing the clock while screen is off and waking it up when screen is back on to save the battery.

DownloadManager.ACTION_DOWNLOAD_COMPLETE broadcast receiver receiving same download id more than once with different download statuses in Android

泄露秘密 提交于 2019-11-27 11:28:56
I am using Android DownloadManger System Service for downloading some files in following way dwnId = mgr.enqueue(new DownloadManager.Request(serveruri) .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE) .setAllowedOverRoaming(false) .setTitle(getAlbumName()) .setDescription(getTrackName()) .setDestinationUri(deviceUri) .setShowRunningNotification(true)); where mgr is Download Manager instance, dwnId is unique ID returned. I am also registering for ACTION_DOWNLOAD_COMPLETE registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager

Registering and unregistering BroadcastReceiver in a fragment

牧云@^-^@ 提交于 2019-11-27 11:17:40
My app has an action bar with 3 fragment tabs. In the second fragment I register and unregister a BroadcastReceiver. I unregister the receiver in onPause and register it in onCreateView and in onResume . getActivity().registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); and getActivity().unregisterReceiver(batteryInfoReceiver); 1) Is it all right to register the same reciever twice (in onCreateView and onResume)?(is it harmless?) 2) Is it enough to just register the reciever in onResume? Mehul Joisar Have a look at life-cycle of Fragments : onCreateView(

How to repeat notification daily on specific time in android through background service

本小妞迷上赌 提交于 2019-11-27 11:15:02
Hi I am working on application where I have set the notification on user entered date and time through background service. Now I want to set notification/alarm daily at 6 pm to ask user does he want to add another entry? How can I achieve this? Should I use the same background service or Broadcast receiver? Please give me better solution for that and tutorial will be great idea. Thanks in advance. Mr. N.V.Rao First set the Alarm Manager as below Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 18); calendar.set(Calendar.MINUTE, 30); calendar.set(Calendar.SECOND, 0

BroadcastReceiver receives multiple identical messages for one event

大兔子大兔子 提交于 2019-11-27 11:14:17
I registered a receiver that listens to network events: <receiver android:label="NetworkConnection" android:name=".ConnectionChangeReceiver" > <intent-filter > <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> receiver is also very simple: public class ConnectionChangeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager

How to read all the coming notifications in android

心已入冬 提交于 2019-11-27 10:52:40
How to read all the coming notifications in android. Is it possible to use the broadcast receiver to listen the incoming notifications and the ability to read the notifications information. First you must declare your intent to receive notifications in your manifest, so that you can get the android.permission.BIND_NOTIFICATION_LISTENER_SERVICE permission. AndroidManifest.xml: <service android:name=".NotificationListener" android:label="@string/service_name" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> <intent-filter> <action android:name="android.service

Using a broadcast intent/broadcast receiver to send messages from a service to an activity

余生长醉 提交于 2019-11-27 10:29:36
So I understand (I think) about broadcast intents and receiving messages to them. So now, my problem/what I can't work out is how to send a message from the onReceive method of a receiver to an activity. Lets say I have a receiver as such: public class ReceiveMessages extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if(action.equalsIgnoreCase(TheService.DOWNLOADED)){ // send message to activity } } } How would I send a message to an activity? Would I have to instantiate the receiver in the activity I want to send

PowerManager.PARTIAL_WAKE_LOCK android

依然范特西╮ 提交于 2019-11-27 09:50:32
I am very confused whether to acquire this wakelock. E.g. I have this type of code that is called from onReceive() of a BroadcastReceiever (CONNECTIVITY_CHANGE, BOOT_COMPLETED etc) asynchronously i.e. I am launching an IntentService from onReceive() which performs heavy lifting. private static void insertInDatabase(Context context /*, some data to be inserted in database*/) { Database helper = Database.getInstance(context); PowerManager pm = (PowerManager) context .getSystemService(Context.POWER_SERVICE); final WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, wakelockName);