broadcastreceiver

Passing parameters to the BroadcastReceiver

穿精又带淫゛_ 提交于 2019-12-06 03:23:30
问题 I'm trying to pass an int value from my Service to the CallReceiver class, unfortunately the CallReceiver.value always equals 0, even after set with another value. When I'm trying to pass it as a parameter to the constructor situation is exactly the same, and so with the setter methods called from service. Is there really no way to pass there any data? Service: SharedPreferences settings = getSharedPreferences("SETTINGS", 0); int value = settings.getInt("value1", 0); // here the correct value

unregister BroadcastReceiver after app kill/crash

断了今生、忘了曾经 提交于 2019-12-06 03:23:26
I register my custom BroadcastReceiver with registerReceiver() in onStart() and unregisterReceiver() in onStop() . Everything works fine, until someone kills the app during runtime. A new app start registered the BroadcastReceiver a second (or more) time. How can I be sure, that only one instance is registered? 来源: https://stackoverflow.com/questions/28045342/unregister-broadcastreceiver-after-app-kill-crash

Dataflow between Android BroadcastReceiver, ContentProvider, and Activity?

被刻印的时光 ゝ 提交于 2019-12-06 02:52:19
问题 I've developed an application that receives a Broadcast and then launches an Activity , where that Activity queries a ContentProvider which pulls information out of the DNS in real-time. I'd like to be able to shuffle this so that instead of going: BroadcastReceiver.onReceive() { Intent intent = new Intent(...); intent.setData(...); // set a single String data context.startActivity(intent); } Activity.onCreate() { String value = intent.getData(); // get the String data Cursor =

How to register a receiver in the main activity?

≡放荡痞女 提交于 2019-12-06 02:34:54
I have a SmsReceiver class that I want to register in the main activity, what exactly should I do ? I am new to Android. Either you can do 2 things: Create and define BroadcastReceiver in the Manifest Create and register the BroadcastReceiver in code. For option 2 (which you are asking): Create a BroadcastReceiver in code (MyBroadcastReceiver). Declare MyBroadcastReceiver in the scope of your Activity : MyBroadcastReceiver mMyBroadcastReceiver; Register the BroadcastReceiver in your Activity by: IntentFilter filter = new IntentFilter(android.provider.Telephony.SMS_RECEIVED); this

do I need a wake lock in my broadcastreceiver if I'm not starting a service or an activity?

我的未来我决定 提交于 2019-12-06 02:33:58
问题 I have a broadcastreceiver called by an Alarm (scheduled with AlarmManager). In this receiver I'm only querying a register from the database, and launching a notification. I readed that a wake lock is needed when a service or an activity is started from a broadcast receiver, but, do I need a wake lock if I only want to show a notificacion (in the notification panel)? 回答1: In this receiver I'm only querying a register from the database, and launching a notification. Do not do database I/O on

Is it possible to call onReceive method from a dialog?

你。 提交于 2019-12-06 02:10:48
I have a custom dialog with editText and save button . When button clicked, I want it call MyReceiver . But the log and Toast in MyReceiver never get displayed. Reminder final AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); View promptView = getLayoutInflater().inflate(R.layout.dialog_with_edittext, null); Button save = (Button) promptView.findViewById(R.id.okBtn); final EditText task = (EditText) promptView.findViewById(R.id.task); time = (EditText) promptView.findViewById(R.id.time); date = (EditText) promptView.findViewById(R

BroadcastReceiver for BOOT_COMPLETED is too slow

人走茶凉 提交于 2019-12-06 02:04:17
问题 The below is my manifest file. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mccheekati.test_trail"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <receiver android:name

What is the Context passed into onReceive() of a BroadcastReceiver?

假装没事ソ 提交于 2019-12-06 01:59:43
What is the context that is passed int the onReceive method of a BroadcastReciver : public void onReceive (Context context, Intent intent) According to the official documentation : The Context in which the receiver is running. A little research gives below result... For static receiver public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.e("PANKAJ", "Context class " + context.getClass().getName()); Log.e("PANKAJ", "Application Context class " + context.getApplicationContext().getClass().getName()); } } I got below log 08-05

Android BatteryManager Returns only 1

a 夏天 提交于 2019-12-06 01:40:15
I am attempting to read the state of the Android battery when my repeating alarm broadcaster is called I have the following setup: public class RepeatingAlarm extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Acquire the make of the device final String PhoneModel = android.os.Build.MODEL; final String AndroidVersion = android.os.Build.VERSION.RELEASE; // Grab the battery information int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); final float batteryPct = level / (float

Does AlarmManager require the PendingIntent to be of Type BroadcastReceiver?

一个人想着一个人 提交于 2019-12-06 01:24:28
The documentation for AlarmManager seems to imply (but does not outright explicitly require) that the PendingIntent you pass in to any of the set() methods should be of the type BroadcastReceiver , but I tested passing in other component types (like an IntentService ) and it seemed to work fine. Is it safe to use non- BroadcastReceiver Intents with AlarmManager ? Yes, and it has always worked, but I suspect not in the way that you're thinking. You can use any PendingIntent with an alarm; this could indeed be an activity or service PendingIntent. If it's a service PendingIntent, then the OS