android-broadcast

how to register broadcast receiver for low battery in android?

半腔热情 提交于 2019-12-06 13:49:46
I want to register broadcast for low battery. If battery status reached at some level I want to get alert... Please if you have any idea please help me.. You will need to register a BroadcastReceiver for ACTION_BATTERY_LOW . You can do this in the manifest with a <receiver> element or via registerReceiver() from some already-running component of your application. For Battery_Status_Low, You could try registering it through a Service for example, like: BatteryReceiver receiver = new BatteryReceiver(); IntentFilter inf = new IntentFilter(); inf.addAction("android.intent.action.BATTERY_LOW");`

How to receive USB connection status broadcast?

烂漫一生 提交于 2019-12-06 04:36:34
问题 I am trying to detect USB connection in my app, that is, whether or not USB is connected to device. It's being tested on Marshmallow 6.0.1 (sdk23) But I'm unable to receive the broadcast actions ACTION_USB_DEVICE_ATTACHED or ACTION_USB_DEVICE_DETACHED.. I tried using both the dynamic way and the AndroidManifest.xml way, neither worked.. Here's my code: AndroidManifest.xml : <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com

Manifest-declared BroadcastReceiver not picking up explicit broadcast when app is not running

戏子无情 提交于 2019-12-06 03:32:55
I am trying to get two apps to communicate via broadcasts. The first app sends a broadcast using code like the following: Intent outIntent = new Intent("org.example.WHATEVER"); PackageManager pm = this.getPackageManager(); List<ResolveInfo> receivers = pm.queryBroadcastReceivers(outIntent, 0); if (receivers != null) for (ResolveInfo receiver : receivers) { Log.d("Sender", String.format("Polling %s", receiver.activityInfo.packageName)); outIntent = new Intent("org.example.WHATEVER"); outIntent.setPackage(receiver.activityInfo.packageName); sendBroadcast(outIntent); } The receiving end registers

Call broadcast receiver at time of uninstalling application in android [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-06 00:36:50
问题 This question already has answers here : Receiving package install and uninstall events (4 answers) Closed 5 years ago . I want to clean up the junk created by my application at time on UnInstalling the Application. Using ManiFest File:- Added in Manifest File: <receiver android:name="com.netdoers.com.ui.CleanReceiver" > <intent-filter> <action android:name="android.intent.action.PACKAGE_REMOVED" > </action> <data android:scheme="package"/> </intent-filter> </receiver> Created Receiver to

How to broadcast a parcelable object in an intent?

南笙酒味 提交于 2019-12-05 17:56:04
I'm new to Java / Android and trying to develop an adroid application which communicates with a USB CAN Bus adapter. I receive messages from the adapter in a string via my CANBusController class and I have built a parcelable class, CANMessage, which converts the string received into a form I can use (int Id, int Length, byte[] data). Now I'm trying to display the message I have received. I have a Fragment, CANBusControlFragment, which declares a BroadcastReceiver. When a message is a received, I build my CANMessage, place it and its string into a bundle, place the bundle into an Intent, and

How to use NFC ACTIONS

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 13:46:08
I am trying to register a receiver programmatically to get notified once an NFC tag is detected. As shown in my code I registered for the desired action and I created the broadcast receiver programmatically. I also added the required permission in the manifest file but the problem is that onReceive is never called. Please let me know what I am doing wrong and how to fix it. IntentFilter intentFilter1 = new IntentFilter(); intentFilter1.addAction("android.nfc.action.TAG_DISCOVERED"); registerReceiver(mBCR_TAG_DISCOVERED, intentFilter1); private BroadcastReceiver mBCR_TAG_DISCOVERED = new

Android - How to trigger a Broadcast Receiver to call its onReceive() method?

╄→гoц情女王★ 提交于 2019-12-05 13:32:52
问题 I have scheduled alarm for my application. I have implemented broadcast receiver to be triggered once the alarm time reaches. How to manually call broadcast receiver to execute the code inside of onReceive method without replicating the code twice. I thought of having the code in utility singleton call and call that method by having util class instance from anywhere. But is that any other way to call that onReceive method directly or else broadcast intent problematically. android:exported=

Android - Passing simple string over Wi-fi?

牧云@^-^@ 提交于 2019-12-05 04:11:35
问题 I have Wi-fi direct demo. In that we can transfer any image files to other devices. When another device get connected and it shows to send image from gallery. And at other side it shows sent image. But I want to send a simple string and at other side I want to toast that string. Here I am posting a code in which they have implemented file transfer. I am very confused in this code. I am not getting where to change to pass only string. Please help me. Thanks. DeviceDetailFragment.java /** * A

Local broadcast from Service not received by Activity

僤鯓⒐⒋嵵緔 提交于 2019-12-05 02:39:11
I have an Activity in which I am registering a BroadcastReceiver locally as follows: public class SomeActivity extends Activity{ public static final String PERFORM_SOME_ACTION = "PERFORM_SOME_ACTION"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.some_activity_layout); ..... ..... IntentFilter filter = new IntentFilter(); filter.addAction(PERFORM_SOME_ACTION); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // perform some action ... } }; registerReceiver(receiver

BroadcastReceiver for WALLPAPER_CHANGED calls onReceive() multiple times : Android

橙三吉。 提交于 2019-12-04 22:50:59
I have a BroadcastReceiver and declared it like this: <receiver android:name="com.services.Receiver" android:enabled="true" android:exported="true" > <intent-filter android:priority="999" > <action android:name="android.intent.action.WALLPAPER_CHANGED" /> </intent-filter> </receiver> and the receiver is: @Override public void onReceive(final Context context, final Intent intent) { change_wallpepar.myPrefs = context.getSharedPreferences("myPrefs", Context.MODE_PRIVATE); new Handler().postDelayed(new Runnable() { @Override public void run() { Log.d("MAYUR", "<< wallpepar changed >>"); if (change