I would like to know whether there is an intent(like "android.intent.action.WALLPAPER_CHANGED"-notifies when a wallpaper has been changed) that would notify my broadcast receiver when a ringtone has been changed or a when a new ringtone has been set.
If there isn't Is there any other way to notify my BroadcastReceiver that the ringtone has been changed
There's no intent for something like "RINGTONE_CHANGED":
http://developer.android.com/reference/android/content/Intent.html
I wonder if that's possible without hacking into the Android-system, especially as a change of ringtones will not always mean the the "system"-ringtone has been changed (as with the wallpaper), e.g. you can change a ringtone just for one contact ... so as there's no event you can connect to, I would guess, the answer is: no.
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.
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 am trying to cancel an alarm that was set last time my app was run. This alarm has a PendingIntent that was set with PendingIntent.getBroadcast and an inner Intent that contains some variables set by intent.putExtra. My question is this, I know that alarms can be canceled by calling alarmManager.cancel(pendingIntent) where pendingIntent is the same as the one used to set the alarm. But, if the variables placed into the intent are changed will the alarm still be canceled? For example, I set an alarm with intent.putExtra("Joe") where Joe is a contact name. Later my app is closed and when it is re-run I try and cancel the alarm for "Joe" but the user has changed the name of the contact to "Jones". Can I cancel the alarm without knowing the variables I put into the intent?
Thanks!
I think it should cancel the alaram anyway, even though some data is different. The cancel method says:
Any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be canceled.
And filterEquals says:
Determine if two intents are the same for the purposes of intent resolution (filtering). That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.
Anyhow, I'd still test it myself.
According to this question (which references the documentation), anything you add using putExtra is not taken into account when checking if an intent is equal to another one.
It shouldn't matter if the extra data is changed.
I register a broadcastreceiver in AndroidMainfest.xml
And in my app, a function is that User can set a time and at this time the app will send a notification. I get the arguments User set ,and use alarmManager to set a task which will happened at the time user set.
But I find that GOOGLE API said that:
If there is already an alarm for this Intent scheduled (with the equality of two intents being defined by filterEquals(Intent)), then it will be removed and replaced by this one.
So if I want set two or more task,the Intent will be replaced , and at end I can only get one notification,it's not the result I want.
And then I found the intent was identified by action, data, type, class, and categories,
but I can't change action(the intent's action is the intent-filter's action was registred in the AndroidMainfest.xml ),but at the time that I change the other arguments I can't even receive a broadcast.
I thought there are four ways to solve this problem,but I only made one..
create lots of broadcastreceiver and register these in
AndroidMainfest.xml,and in this way I could change the intent's
action
register the broadcastreceiver in the program ,but I didn't
make it
use service + Timer class ..
To make two intent different without change action.
Any help will be appreciated!!
Intent intent = new Intent("aaa"); //there was a broadcastreceiver's intent-filter "aaa"
intent.putExtra("title", title);
intent.putExtra("table", "计划");
PendingIntent pi = PendingIntent.getBroadcast(Alarm.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager)getSystemService(Alarm.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+time, pi);
The code is in onClickListener{onClick(){}}
Instead of Broadcasting which is not letting you to set repeat alarm you can use the calendar Object and set the alarm at whatever desired time. Once the alarm gets ON, your code will run automatically and as many times you have set the alarm.
You can also take a help of the following tutorial. I am sure it will help you out somehow.
http://blog.mikesir87.io/2013/04/android-creating-an-alarm-with-alarmmanager/
I've been searching for this for a while and keep coming up short. However I have setup notifications before where selecting it launches an activity, now I'm trying to mod that code.
This time I'm looking for a solution to run just a single line of code when the notification is selected. I want it to set a button from invisible to visible. So when my notification is cleared I want the code below to take place, not launch an activity or intent:
butNX.setVisibility(0);
Any input on the matter? thanks in advance.
I wasn't try this, but i think it will resolve your problem.
1. Set up a Receiver where you need it.
2. Create an Intent and add the extras to it something like this: intent.putExtra("MODE","VIS");.
3. Craete a PendingIntent which will broadcast your intent to your receiver.
PendingIntent pIntent=PendingIntent.getBroadcast(yourContext,yourReqCode,
yourIntent,yourFlags);
4.Set notification
So while receiver will receive your broadcast it should to check what to do with this intent by data which you send...