broadcastreceiver

How to register broadcast receiver?

ⅰ亾dé卋堺 提交于 2019-11-29 08:15:50
Here is my source code and it keeps force closing everytime I run it... public class MainActivity extends Activity { private static String content; private static String phone; private String number; private String message; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context context, Intent intent) { //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage[] msgs

Broadcast-receiver which always receives broadcast (even in background) for API Level +26

喜夏-厌秋 提交于 2019-11-29 08:12:02
I'm posing this as Q&A style because I found this idea working. And it's a fix to the hard problem to crack for beginners with Android. Google has deprecated registering Broadcast Receiver into manifest like this below from API Level 26+ ( Except Some ) <receiver android:name=".MyBroadcastReceiver" android:exported="true"> <intent-filter> <action android:name="android.net.wifi.STATE_CHANGE" /> </intent-filter> </receiver> But, If one wants to receive particular device state changes like Internet Connectivity Changes (Which isn't allowed) while the app is in background and if it's important for

Intent PACKAGE_ADDED not registering

强颜欢笑 提交于 2019-11-29 08:06:29
Hello i am trying to detect application installed so that i can do some analysis on the application and i am using this example i found on stackoverflow to listen for package installs from my current application but nothing is happening in my logcat. void registerReceiver() { IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); filter.addDataScheme("package"); } public void onReceive(Context context, Intent intent) { String actionStr = intent.getAction(); if (Intent.ACTION_PACKAGE

How to raise an alert dialog from BroadcastReceiver class?

寵の児 提交于 2019-11-29 08:01:40
I have used a timer method in an Activity class. In that method I have an intent from Activity class to a BroadcastReceiver class. This BroadcastReceiver class will call on every 15 minutes at background by using AlarmManager . When I call the BroadcastReceiver class I would like to raise an AlertDialog . public void timerMethod(){ Intent intent = new Intent(Activity.this, BroadcastReceiverClass.class ); PendingIntent sender = PendingIntent.getBroadcast( QualityCallActivity.this,0, intent, 0 ); // We want the alarm to go off 30 seconds from now. long firstTime = SystemClock.elapsedRealtime();

Getting multiple broadcasts from intents?

左心房为你撑大大i 提交于 2019-11-29 07:35:10
http://mobiforge.com/developing/story/sms-messaging-android I used the example code in the above link my own application for sending an SMS, but I run into a problem when checking the sent status of my message. What happens is, the toast message will pop up for every message I have attempted to send. So basically, let's say I've already sent 3 messages. When I go to send my 4th message, the toast message will pop up 4 times. It seems that perhaps the BroadcastReceiver is receiving the same broadcast from every intent used so far? I cannot figure out exactly why this is happening, or how to

BroadcastReceiver and AlarmManager Android

别说谁变了你拦得住时间么 提交于 2019-11-29 07:32:03
I am trying to use an alarm manager with BroadcastReceiver. I try to use the example given in Tutorial: System Services and BroadcastReceiver . but when I run the example after the end of the time the toast doesn't show up. the code is below: My main Activity: public class AlarmActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_alarm); } public void startAlert(View view) { EditText text = (EditText) findViewById(R.id.time); int i = Integer

Android app update broadcast

谁说我不能喝 提交于 2019-11-29 07:29:18
So, im working on something that requires me to know when another application on the device is being updated. So my question is quite simple, does lets say YouTube or Spotify send a broadcast when the application is updating, and if so, what do i need to catch with my broadcastReceiver. Your intent filter should be like: <intent-filter> <action android:name="android.intent.action.PACKAGE_REPLACED" /> <data android:scheme="package" /> </intent-filter> And onReceive method from your BroadcastReceiver should be: @Override public void onReceive(Context context, Intent intent) { Uri data = intent

Android NFC tag received with broadcastreceiver

为君一笑 提交于 2019-11-29 07:07:55
I'm trying to catch NFC tag in broadcast receiver so I wrote a simple BR that prints "asd" in the onReceive(). In the manifest xml it's desribed like that: and I receive only this and no print at all.... 01-31 16:37:18.980: ERROR/MediaPlayer(990): setAudioStream called in state 8 01-31 16:37:18.980: ERROR/MediaPlayer(990): error (-38, 0) 01-31 16:37:18.980: ERROR/MediaPlayer(990): start called in state 0 01-31 16:37:18.980: ERROR/MediaPlayer(990): error (-38, 0) 01-31 16:37:18.988: ERROR/MediaPlayer(990): Error (-38,0) When I use activity to handle the intent like this: <activity android:name=

Unable to instantiate receiver java.lang.ClassNotFoundException

早过忘川 提交于 2019-11-29 06:40:57
I got an error in my android application when it tries to instantiate a receiver that i use to start a service on boot up. The error is obvious, it can not find the class file of my receiver. But everything is ok with my manifest file, the packages and all and i have no clue what is happening. Here is my code: package dti.obd.reader; import dti.obd.reader.service.MainService; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent

Android broadcast receiver doesn't receive ACTION_SCREEN_ON

大城市里の小女人 提交于 2019-11-29 05:13:17
I tried to register the receiver in my service with the following code: IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); ScreenReceiver SR = new ScreenReceiver(); registerReceiver(SR, filter); and this is my broadcast receiver: public class ScreenReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { System.out.println("RECEIVED"); } } I have even declared it in the manifest but without any filters: <receiver android:name=".ScreenReceiver" android:enabled="true" /> But whatever I do, I can't seem to be able to receive the intent