w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Broadcast Receiver Not working in 4.1.1
As you have already known that the broadcast receiver will not work unless user manually starts an application For that purpose, you should not be surprised that your broadcast receiver will not work until user Manually open your application once. That is to say, you have to make a launcher activity which user is able to click and open it manually. And what's more, it is better to Open and stay in your application for like 20s since I remember that the change of application configuration will take 10 or 20s to be saved.

Categories : Android

Broadcast Receiver not working when registered via manifest
Incoming call broadcast receiver not working (Android 4.1) they said that as of android 4.1 the system no longer sends broadcasts to app components without an activity...is this true? That has been the case since Android 3.1. Something must explicitly run one of your components before your manifest-registered BroadcastReceivers will work, and the typical solution for this is to have an activity (the same one that provides app configuration, help, license agreements, etc.) that the user launches. Please read the Android 3.1 release notes for more.

Categories : Android

Broadcast receiver highest priority not working
First of all, you shouldn't register the receiver in code if it's already mentioned in the manifest. Then, the name of the receiver is invalid, it should either be a full class name, or the shorthand, which will be appended to the application package name. In case if BCreceiver is in the main package, the attribute value should be ".BCreceiver". Last mention is that you shouldn't really change the priority, there is no such thing as intercepting a broadcast in Android (as far as I know), so all BroadcastReceivers subscribed to an action will receive the broadcast when it's fired. Try these fixes and update your question.

Categories : Android

Broadcast Receiver within Service stops working after some time
I'm sorry but I have only a try out for you, try making your service foreground so that the system won't kill it and handle it perfectly all the time here a code to set it foreground: NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent bIntent = new Intent(this, urmainactivity.class); PendingIntent pbIntent = PendingIntent.getActivity(this, 0, bIntent,0); NotificationCompat.Builder bBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("write the title") .setContentText("write subtitle") .setAutoCancel(true) .setOngoing(true) .setContentIntent(pbIntent);

Categories : Android

Can we use GCM to send push notification wihout starting the app even once as broadcast receiver not working for android 3.0+
User will be shown permissions about your app, there is a way an application can start right after installation, and BroadcastReceiver work since API Level 1 to the latest API. But since API Level 11 (version 3.0) you need to use this. Intent intent = new Intent("com.mypackage.yourapp.custom.intent.action.ADDON_REQ"); intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); sendBroadcast(intent);

Categories : Java

Get SMS ID from broadcast receiver
You are referring to the message ref id that is used to do dedup right? That field is in the SMSMessage however the api is not public. You will have to do some reflection to dig it out. Look in com.android.internal.telephony.SmsMessageBase

Categories : Android

Android Broadcast Receiver
It seems you should add intent-filter for your receiver, as below <receiver android:name="com.example.contactlistnew.AlarmReceiver"> <intent-filter> <action android:name="android.alarm.demo.action" /> </intent-filter> </receiver>

Categories : Android

BroadCast Receiver Error
The problem is most likely to be that you're binding to the Service but when you click on a list item, you're calling finish() which will terminate the Activity. There isn't anything in your code which shows you unbinding from the Service. It seems you're confusing the issue by not only starting the Service but binding to it and also using a BroadcastReceiver. The purpose of binding to a Service is to allow direct communication between (for example) an Activity and the Service in which case, communicating via a BroadcastReceiver isn't necessary. The most important aspect is if you bind to a Service, make sure you unbind from it in either onPause(), onStop() or onDestroy() depending on requirements.

Categories : Android

Broadcast receiver for notifications
One possible way, that would not read everything in the notification would be to set up your application as Accessability application that's allowed to listen to (pretty much) everything. But in 4.3 they have added the NotificationListenerService. Best guideance is probably to look at the docs. There's an another example available: https://github.com/kpbird/NotificationListenerService-Example

Categories : Android

Broadcast receiver in an activity
1. You are registering your receiver programmatically with registerReceiver(sendBroadcastReceiver, new IntentFilter(SENT)); So there is no need to add it to the Manifest aswell. 2. You have a custom BroadcastReceiver-class called "sentReceiver", so you should use this objecttype when you instantiate it. So you need to change BroadcastReceiver sendBroadcastReceiver= new sentReceiver(); to SentReceiver sendBroadcastReceiver = new sentReceiver(); 3. I think you are calling your stuff in the wrong order. So that the receiver is not ready listening when it should be.

Categories : Android

Broadcast Receiver not going off in android app
Silly doubt, but did you register the BroadcastReceiver and the required IntentFilter? EDIT: In your manifest file you should have the below lines inside the application node <receiver android:name="your_receiver_name" > <intent-filter> <action android:name="your_action_name" > </action> </intent-filter> </receiver> The other way to this dynamically is, call registerReceiver (BroadcastReceiver receiver, IntentFilter filter) For a nice tutorial on how to use Broadcast Filters you can visit this Vogella Tutorial Hope this will clear your doubt and resolve the issue.

Categories : Android

multiple intent in broadcast receiver
Register another broadcast receiver which responds to call incoming state set one flag which you can check in your receiver Intent.ACTION_SCREEN_ON) if flag is already set then skip to starting activity and reset flag else start activity like if(action.equalsIgnoreCase("android.intent.action.PHONE_STATE")) { if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals( TelephonyManager.EXTRA_STATE_RINGING)) { incomingcall = true; } } and check if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)){ if(incomingcall ==true) { //skip the reciver and reset flag incomingcall = false; } else{ Intent i = new Intent(context, MainScreenActivity.class); i.putExtras(intent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); Log.e("

Categories : Android

Broadcast receiver push notification
try my solution it worked for me: link your broadcast receiver to your service by adding public void onReceive(Context context, Intent intent) { //add the following Intent e = new Intent(context, urservice.class); context.startService(e); } then register your receiver in your service onCreate() like so @Override public void onCreate() { super.onCreate(); IntentFilter filter = new IntentFilter(Intent.BOOT_COMPLETED); filter.addAction(Intent.USER_PRESENT); BroadcastReceiver mReceiver = new ParseBroadcastReceiver(); registerReceiver(mReceiver, filter); } then just delete your 'broadcastreceiver' from the manifest, lastly surly you want the service to live as long as possible,,, well then you need also 2 codes for the service in your int onStartCommand(Int

Categories : Android

1 broadcast receiver instance at any given time
You could just a static boolean field in your ConnectivityChangeBroadcastReceiver to keep track of whether the method is currently executing. public class ConnectivityChangeBroadcastReceiver extends BroadcastReceiver { private static boolean currentlyReceiving = false; @Override public void onReceive(Context context, Intent intent) { if(!currentlyReceiving) { currentlyReceiving = true; doYourLongTaskHere(); currentlyReceiving = false; } } } I'm not sure if every broadcast will be run in a different thread or not, so you may want to throw the block within the if statement into a synchronized block.

Categories : Android

Android: using sharedPreferences in a broadcast receiver
getDefaultSharedPreferences() returns you a SharedPreferences file with the name based on the app package. It is like saying context.getSharedPreferences("com.your.package_preferences", context.MODE_PRIVATE); Then in your receiver you say context.getSharedPreferences("sharedPrefs", context.MODE_PRIVATE); which gets you shared preferences with a different name. Therefore you are saving to one SharedPreference file but attempting to retrieve from another. Try using getSharedPreferences("MySmsSharedPrefs", context.MODE_PRIVATE); in both save and restore. i.e in the Acvtivity and the Receiver Here is the sauce to confirm: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/preference/PreferenceManager.java ** * Gets a SharedPrefere

Categories : Android

We cannot stop activity Broadcast receiver
Thats because you already unregistered it in onPause method. If you see the activity life cycle, you can see that onPause is called before onStop. How about unregistering it only once in the onPause method and see if there is BroadcastReceiver leakage? Another thing, I've noticed is that you are registering the same receiver again in onResume method, is that what you really want? See the life cycle diagram, that will definitely be handy to you. :)

Categories : Android

communication between activity and broadcast receiver
No, you are trying to instantiate an Activity via its constructor. Never do that - Activities have special initialization steps that allow them to become proper Activities (and as a result Contexts). The Context class (which your BroadcastReceiver receives an instance of via the onReceive() method) is the the class that contains methods such as getSharedPreferences(). Use that instead. public class MyReceiver extends BroadcastReceiver { @Override public void onReceive (Context context, Intent intent){ String s = context.getSharedPreferences("Shared_Prefs_Name",Context.MODE_PRIVATE).getString("Key","def_value"); } }

Categories : Android

No response after broadcast receiver from service
To trigger a broadcast, you have to register the receiver in the onResume() method like this: registerReceiver(myBR, new IntentFilter("hello")); and unregister the broadcast in the onPause() method unregisterReceiver(myBR);

Categories : Android

How to unregister the broadcast receiver in android
You can call unregisterReceiver (BroadcastReceiver receiver) to unregister the broadcast receivers. The context you have received as part of sendSMS should be stored and then later the same can be used to unregister the receiver. EDIT: private static Context mContext = null; static BroadcastReceiver mSentReceiver = new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(mContext, "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(mContext, "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager

Categories : Android

Read NFC tag using Broadcast receiver in Android
the only way i figured out was polling the isconnected method in a separate thread. i tried to receive the intent nfc.action.TECH_DISCOVERED in a receiver but it didn't work, you can use an activity with the singletop launchmode instead

Categories : Android

Broadcast Receiver Long Binary SMS
Found out that it was not an issue with the client side but in the server side. They didn't include in the User Data Header the part to indicate that the message is a concatenated SMS. If the protocol is followed, Android will be able to detect it and handle them accordingly, waiting for all SMS to arrive and fire the SMS broadcast receiver once containing all received SMS.

Categories : Android

Broadcast Receiver in a remote process
I also have this problem, the broadcast is received but it always has a warning for "Failure filling in extras". The solution is wrap your Parcelable in a Bundle and add the Bundle as extra to the PendingIntent. The problem is that when executing the PendingIntent it needs to copy the intent extras to another intent, but to copy the Parcelables it needs to unparcel and parcel again and on unparcel it uses the default ClassLoader and not your class ClassLoader, so it doesn't find the class to unparcel. But if you wrap in a Bundle, it copy the whole Bundle to the intent and no unparcel is done.

Categories : Android

Broadcast receiver. Huge data
Does somebody know the max size of content which I can send via broadcast? I would expect you to start running into problems around the 1MB mark for the entire parceled Intent, as there are limits on Binder-based IPC, which underlies the Intent system. How the size of data affect on productivity of the device? Since Intent objects get copied between processes as a result of broadcasts, you will consume a fair amount of RAM while the broadcast is going on, plus a fair amount of CPU time to copy the memory between processes. I would agree with rciovati's comment: "IHMO a few kb are "huge" for passing with Intent".

Categories : Java

How to build a Broadcast Receiver for Bluetooth
The android SDK has a built in sample for a bluetooth chat application , you can refer to this link to find its location depending your SDK version. In it you will find a file named as BluetoothChatService.java please refer to it, it has a very decent broadcast receiver built into it. In it follwing functions are used to get the connection state,every time there is a change /** * Set the current state of the chat connection * @param state An integer defining the current connection state */ private synchronized void setState(int state) { if (D) Log.d(TAG, "setState() " + mState + " -> " + state); mState = state; // Give the new state to the Handler so the UI Activity can update mHandler.obtainMessage(BluetoothChat.MESSAGE_STATE_CHAN

Categories : Android

Broadcast receiver not detecting keyevents
yeah what you want to do is possible just few things I want to clear out, showing toast while screen is off is no use also detecting power button and screen state is the same and I'll show you how to detect screen state and show toast only, but the power button I still don't know the way to detect it since power button is only managed by System, I think you'll need root to adjust or add functions to power button. any way here is the code you'll need: 1 - you'll need an activity that can start/stop detecting screen state, a service that keeps your app working in background, lastly the Broadcastreceiver. so from the activity you should start service : startService(new Intent(MainActivity.this, yourservice.class)); make sure to stop it after you are done stopService(new Intent(MainActivi

Categories : Java

AlarmManager or Broadcast receiver battery widget
That depends upon your definition of "better". You cannot register for ACTION_BATTERY_CHANGED broadcasts from the manifest, so you would have to have a service running all the time that manages a dynamically-registered receiver for this broadcast. Many users dislike this. AlarmManager avoids the need for the continuously-running service, but it will mean that your app widget will lag a bit on finding out of battery level changes. However, you could allow the user to control the polling frequency, via a SharedPreference, rather than hard-coding it to be five minutes. That way, the user is in control over how much CPU/battery is consumed by your app from the polling, and therefore is in control over how much lag there will be.

Categories : Android

Locally managed broadcast receiver leak?
You should absolutely unregister it in onDestroy because onDestroy doesn't mean your app is finished- just your Activity. Other Activities in your app could still be running, so that receiver would cause a leak.

Categories : Android

App crashes when receives SMS in Broadcast Receiver class
java.lang.RuntimeException: Unable to start receiver com.test.example.SmsReceiver: java.lang.NullPointerException E/AndroidRuntime( 1043): at com.test.example.SmsReceiver.onReceive(SmsReceiver.java:20) There's a NullPointer there. What happens in line 20 of SmsReceiver.java? Is there any possibility that mPlay can be null?

Categories : Android

How to send text using AlarmManager and broadcast receiver?
you could add a broadcast receiver to receive the SMS_SENT intent. this would help you determine if the issue is that the SMS is never sent vs. your Handset never receives it for some reason (e.g., SMSC/routing issues, etc.) here is an example of such a broadcast receiver: //---when the SMS has been sent--- smsReceiver = new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { String result = ""; switch (getResultCode()) { case Activity.RESULT_OK: result = "Message sent"; break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: result = "Generic failure";

Categories : Android

Single Broadcast receiver for all activities in Android?
You can listen to Network Connection Changes through this call and send message to other Activities , other Activities can listen to these messages through Handlers. You can unregister when your Application Exits. Read Message and Handler Concept here

Categories : Android

How to start a class which extends broadcast receiver?
Creating broadcast reciever public class Yourclass extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show(); } } 2.Registering broadcast reciever You can register this either in manifest or by writing Context.registerReceiver() method. Here is the example for manifest <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <receiver android:name="MyReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"> </action> </intent-filter> </receiver> </application> When your applicatio

Categories : Android

android update widget from broadcast receiver
it seems that AppWidgetProvider extends BroadcastReceiver so here is my code : public class ExampleAppWidgetProvider extends AppWidgetProvider { DateFormat df = new SimpleDateFormat("hh:mm:ss"); public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { //my update code here } @Override public void onReceive(Context context, Intent intent) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext()); ComponentName thisWidget = new ComponentName(context.getApplicationContext(), ExampleAppWidgetProvider.class); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget); if (appWidgetIds != null && appWidgetIds.length > 0) {

Categories : Android

Unable to trigger Broadcast SMS receiver in MIUI Rom
http://miuiandroid.com/community/threads/sms-notification-not-working.16464/ This might solve the problem. I did not check it since I have moved to cm again for testing . but seems to solve exactly what I need. And description makes sense. Miui takes preference and takes away the SMS before any other app can receive it.

Categories : Android

Android broadcast receiver not fire after screen off
try doing this in your oncreate: IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); BroadcastReceiver mReceiver = new ScreenReceiver(); registerReceiver(mReceiver, filter);

Categories : Android

Android start service using broadcast receiver
In your activity, create a BroadcastReceiver variable private BroadcastReceiver mBootCompletedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // start your service right here... } }; and onCreate or onResume events of Activity you should register for that BroadcastReceiver super.registerReceiver(mBootCompletedReceiver, new IntentFilter("android.intent.action.BOOT_COMPLETED")); and onDestory or onStop or onPause whatever you in situation should unregister this BroadcastReceiver for not receiving this updates anymore. super.unregisterReceiver(mBootCompletedReceiver);

Categories : Misc

Using a broadcast receiver and getcontentresolver() to build a callerID
You need a concrete MainActivity instance to call updateMessageBox(). Ether start a new activity (or display a notification, or toast, or different) when the broadcast is recived, or your activity should register a reciver in its onResume() method, and unregister it in its onPause() method. The first way would mean your application recives all SMS messages, the second way would mean that messages are ignored while the user is not within your activity. Which method you wish to choose depends on your application. Especially for the second option, see a related question about BroadcastRecivers within Activities.

Categories : Java

Android broadcast receiver not receiving intent
Try it again like this. The category may need to be added <!-- for receiving logs --> <receiver android:name = "LogReceiver" android:enabled="true"> <intent_filter> <action android:name="com.me.intent.finishlog" /> <category android:name="android.intent.category.DEFAULT" /> </intent_filter> </receiver>

Categories : Android

Android Broadcast receiver not receving income SMS
I had the same problem and I've fixed it by adding two more actions to the manifest registered receiver so it will look like this: <receiver android:name=".SmsReceiver"> <intent-filter android:priority="100"> <action android:name="android.intent.action.PHONE_STATE"/> <action android:name="android.provider.telephony.SMS_RECEIVED"/> <action android:name="com.your.package.android.action.broadcast"/> </intent-filter> </receiver> also add permission : <uses-permission android:name="android.permission.RECEIVE_SMS" /> And for comparsion of Strings do not use equals operator, but equals method instead.(Note. equalsIgnoreCase() should be better for you.) so it will be like: if(SMS_RECEIVED.equalsIgnoreCase(actio

Categories : Android

Static SharedPref gives uninitialized value in Broadcast Receiver
Check this link: Static variable loses value Maybe static variables are loosing its value in your case . static variables can loose value in the following cases: 1) Class is unloaded. 2) JVM shuts down. 3) The process dies. Instead of using static variables and functions , try using a public class instead. Hope it helps EDIT 1: Example code of using a public class for preferences instead of static methods public class PreferenceForApp { Context context; SharedPreferences prefs; public PreferenceForApp(Context context) { this.context = context; prefs = context.getSharedPreferences(AllConstants.PREFS_NAME, 0); } public Boolean getIsDeviceValidated() { return prefs.getBoolean("Validated", false); } public void setIsDeviceVa

Categories : Android

Programmatically make a call in broadcast receiver
Create another activity say CallActivity, start this activity from your receiver e.g Intent i=new Intent(); i.setClass(context,callActivity.class); i.putExtra("number","phone_number"); i.setFlags(Intent.Flag_Activity_newTask); context.startActivity(i); Now in onCreate() method of CallActivity, just launch call phone intent: Intent myIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "XXXXXXXXXXX"));; startActivity(myIntent);

Categories : Android



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.