broadcastreceiver

Android AlarmManager in a Broadcastreceiver

自闭症网瘾萝莉.ら 提交于 2019-12-05 02:59:57
I have braodcastreceiver, that broadcast receiver shall schedule an alarm. Usually I would do AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC, time, myPendingIntent); The problem is that getSystemService is not available in a Broadcast receiver only in an Activty. How would I do it here? Thanks, A. AndyAndroid, getSystemService() is part of the Context . You will need to save the Context you receive in your onReceive() method like so... private Context mContext; @Override public void onReceive(Context c, Intent i) { mContext = c; } Then..where you call

Get WiFi Signal Strength of Connected Network

不想你离开。 提交于 2019-12-05 02:33:10
问题 I'm trying to display the signal strength of the connected WiFi network in my Android app. I've tried the following: //Receiver for information on the network info private BroadcastReceiver mNetworkReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d("INFO", "onReceive()"); List<ScanResult> scanResult = mWifi.getScanResults(); for(ScanResult scan : scanResult) { Log.d("INFO","Network strength: " + String.valueOf(scan.level) + " dBm " +

Close Activity Using BroadcastReceiver

走远了吗. 提交于 2019-12-05 02:23:19
问题 i have one activity Main.java is open in my application, i want to close the activity using broadcast receiver , how to close the activity? 回答1: Firstly your Main.java needs to be registered as a receiver. You could register it in Main.java's onResume(): @Override public void onResume() { registerReceiver(broadcastReceiver, new IntentFilter(BroadcasterClassName.NAME_OF_ACTION)); } Then handle the broadcast and finish your activity: private BroadcastReceiver broadcastReceiver = new

Incorrect extras received with all intents but the first one

本小妞迷上赌 提交于 2019-12-05 00:24:37
I have a small application which can be used to set reminders for future events. The app uses an AlarmManager to set the time for when the user should be reminded. When the alarm goes off, a BroadcastReceiver registers this and in turn starts a service to notify the user via a toast and a notification in the status bar. In order to display the correct information in the notification and toast, some extra information is passed along with the intent. The first time a reminder is registered, the info received by the BroadcastReceiver and passed on to the service is correct. But for each following

Scheduled Alarm Manager not working Android

久未见 提交于 2019-12-05 00:21:50
问题 I am trying to start an alarm service that repeats every day at a particular time. I have gone through a lot of threads on stack overflow regarding this but no luck. I followed a few tutorials: http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/ and http://javatechig.com/android/repeat-alarm-example-in-android My service is never started and I do not understand why. Below is my code: My Manifest file: <uses-sdk android:minSdkVersion="8" android

Weird “Receiver not registered” exception

為{幸葍}努か 提交于 2019-12-04 23:49:06
In onResume() I do: registerReceiver(timeTickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); and in onPause(): unregisterReceiver(timeTickReceiver); I see "java.lang.IllegalArgumentException: Receiver not registered" reports in Android Developer Console (there are only 2 reports and my app has thousands of users). The exception is triggered by unregisterReceiver(). What can be happening? I don't feel very confident to just surround it with try-catch. We've seen this error when doing a long press on a particular screen, and then immediately doing two orientation changes (e.g. turning the

BroadcastReceiver permission for adb shell

房东的猫 提交于 2019-12-04 23:12:37
Consider a simple tool using a BroadcastReceiver to achieve a simple goal. Because this should not be used by other applications, it defines a permission with a protectionLevel of signature or signatureOrSystem : <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="any.test"> <permission android:name="any.test.PERMISSION" android:protectionLevel="signatureOrSystem" /> <application android:label="AnyTest"> <receiver android:name=".Receiver" android:exported="true" android:permission="any.test.PERMISSION" /> </application> </manifest> Now I'd like to test this by sending

CONNECTIVITY_CHANGE deprecated in target of Android N

丶灬走出姿态 提交于 2019-12-04 23:03:28
I am getting warning of deprecated declaration of Broadcast Receiver. <!-- NETWORK RECEIVER... --> <receiver android:name=".utils.NetworkUtils" > <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> WARNING: Declaring a broadcastreceiver for android.net.conn.CONNECTIVITY_CHANGE is deprecated for apps targeting N and higher. In general, apps should not rely on this broadcast and instead use JobScheduler or GCMNetworkManager. Is there any other way to use it without deprecated methods? I had the same problem, i did something like that. It

BroadcastReceiver for Screen On/Off in ANDROID When App is not running

核能气质少年 提交于 2019-12-04 22:45:11
I want to detect screen off and on event for that i have created BroadcastReceiver, It only works fine when app is running and when i remove the app from task manager then it does not works. Activity: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try{ BroadcastReceiver myrcver = new BootReceiver(); IntentFilter screenStateFilter = new IntentFilter(); screenStateFilter.addAction(Intent.ACTION_SCREEN_ON); screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(myrcver, screenStateFilter);

“TooManyMessages” Error coming from c2dm.intent.RECEIVE Intent

天涯浪子 提交于 2019-12-04 21:52:11
Does anyone have any documentation on this "TooManyMessages" error . After I call the GoogleCloudMessaging send method I am getting an intent from com.google.android.c2dm.intent.RECEIVE with the following key/value pairs in the extras bundle. Send error: Bundle[{error=TooManyMessages, message_type=send_error, google.message_id=1, android.support.content.wakelockid=1} This means that too many messages were stored in the GCM server for a single device without being delivered (which might happen if your device was offline while many messages were sent by your server). Once the number of such