I have a broadcast receiver that listens for incoming calls, then displays a popup. The popup is a dialog type of theme and has FLAG_NOT_FOCUSABLE and FLAG_NOT_TOUCHABLE - basically, it's an informational window that goes away after x seconds, and is not meant to interfere or take focus over anything else.
The issue is that the incoming call intent, built into android, is getting the broadcast after my intent. This is causing that window to be stacked in front of mine. How to I get my window to always be on top?
Thanks!
A hack but solution that I ended up doing is to wait for a second or two after getting the broadcast. At that point, I know the incoming caller intent has processed and displayed the call window and can call my intent.
Related
Can I get a reason why screen is on when I use BroadcastReciever for SCREEN_ON?(It is user have pressed on/off button on phone, or it is some app for example alarmclock ringing)?
PowerManagerNotifier(Notifier.java) is where the ACTION_SCREEN_ON is being broadcasted whenever the system turns on the screen.
https://code.google.com/p/android-source-browsing/source/browse/services/java/com/android/server/power/Notifier.java?repo=platform--frameworks--base
mScreenOnIntent = new Intent(Intent.ACTION_SCREEN_ON);
mScreenOnIntent.addFlags(
Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
As you can see it from the above, the broadcasted intent does not contain any info on the reason for being turned on. So, you are not able to distinguish the reason from the BroadcastReciever for ACTION_SCREEN_ON.
What is the difference between the function FLAG_ONGOING_EVENT and FLAG_NO_CLEAR how do they make the Notification behave differently? Do they both make the Notification permanent.
Documentation says :
FLAG_ONGOING_EVENT: Bit to be bitwise-ored into the flags field that should be set if this notification is in reference to something
that is ongoing, like a phone call. It should not be set if this
notification is in reference to something that happened at a
particular point in time, like a missed phone call.
FLAG_NO_CLEAR :Bit to be bitwise-ored into the flags field that should
be set if the notification should not be canceled when the user clicks
the Clear all button.
I think in these words they have different meanings so mixing these flags will give you a permanent notification until your program process ends , if you use just FLAG_ONGOING_EVENT this cause your notification runs until your binding service like phone call ends and it's also cancelable by developer or it can be clear by user and when you mix it with the other, user can't clear it from status bar.
Is it feasible to make our Android application completely transparent (as if its not active at all) and work on the other apps?
My Requirement:
First last an app and after some few settings, make it transparent. Once its transparent, the user will not know that this app is active, however, our app should respond to only specific controls.
This is because of the Broadcast receiver limitation, I will have to use the Volume button for some actions in my application. But, this button doesn't broadcast. So, currently I am using Power button which is not the requirement.
Please throw some light on this. I did some research but, couldnt find any. :(
This is because of the Broadcast receiver limitation, I will have to use the Volume button for some actions in my application. But, this button doesn't broadcast.
I am not sure it this is right. If you read Android BroadCastReceiver for volume key up and down question, it seems that you can detect it in BroadCastRceiver. I've never tried but it might be worth a try. Do something like following:
In your BroadcastReceiver onReceive function, do something like following:
public void onReceive(Context arg0, Intent intent) {
if (intent!=null){
int volume = (Integer)intent.getExtras().get("android.media.EXTRA_VOLUME_STREAM_VALUE");
// Get the old volume from the SharedPOreferences
// volume variable contains the current volume
// Compare it to the old value saved. If it is greater than old value then user pressed the UP Volume button else DOWN volume.
}
}
Also I am not sure that you can make it transparent and still keep it running. You can have a background of an activity as transparent though. How do I create a transparent Activity on Android?. Hope it helps.
I have managed to get an Activity to start from my onReceive() methdod, but I really need to do a startActivityForResult();.
Is there any way I could do this?
On a side note, how would I make my app become a 'camera' app, as in it would appear when an app started the intent to take a picture?
The important thing to know about broadcast receivers is that you should not add long running processes in it, because after something like 5 seconds your app will crash.
The best thing to do in your case is to intent to other Activity from your broadcast receiver, and from that activity use startActivityForResult(), get the picture and continue from there...
startActivityForResult can only be called from an Activity since it is defined in the Activity class and require instance of activity.
You can only call startAcivity() from broadcast receiver since in onRecieve() you only have access to generic context object and it does not have startActivityForResult method defined in the class..
I want to set a onClickListner for a status bar Notification. How it is possible ? Please help. Now i can load a Activity by using the pending intent. I like to set a onClickListner for the notificatioin.
Regards
Parvathi
It is not possible to set an OnClickListener for a notification. Because of the way notifications are handled/displayed there is no way to guarantee that the process that created the notification will be running at the time the notification is clicked. This means that any code you wrote to provide click handling may not be running.
If you need click listener style behavior you will have to do it using the PendingIntent: set it to start a Service that runs the logic or to use an Intent that is received by a BroadcastReceiver. This will let you perform activity without requiring a UI.