2

I'd like to trigger an event when the user changes the phone's profile but I'm not sure how. Idealy, I could catch the a broadcast intent and know when the profile has changed but I haven't been able to find any documentation on this.

If I'm correct, the profile system is not a part of the stock AOSP but Cyanogenmod.

I've trudged through the only two profile-related classes I could find:

The only broadcast intent that I could find was here.

Any idea on how this could be accomplished? My application only targets devices running Cyanogenmod 10.1. This is the profile manager from CyanogenMod to give you a clearer idea of what I'm talking about.

enter image description here

Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382

4 Answers4

2

Not sure whether i am right about what you want,but in my case it works good.Try if it can help you.
I used here 2 buttons to set profile as silent and default mode.Trigger your events when those will activate upon button click.

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final TextView text = (TextView) findViewById(R.id.text1);

    Button silent = (Button) findViewById(R.id.silent);
    Button default = (Button) findViewById(R.id.default);

    final AudioManager mode = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

    silent.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            text.setText("The Mobile in Silent Mode"); //i use example case,trigger your event here

            mode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            Toast.makeText(getBaseContext(), "Silent Mode Activated",Toast.LENGTH_LONG).show()
        }
     });

    default.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            text.setText("The Mobile in Default Mode"); //trigger your event here

            mode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            Toast.makeText(getBaseContext(), "Default Mode Activated", Toast.LENGTH_LONG).show();
         }
     });
 }

Apparently this can also help you..

Community
  • 1
  • 1
ridoy
  • 6,274
  • 2
  • 29
  • 60
1

Since those are two separate environments, I don't think it is possible right now to detect when you switch from one to the other.

Teovald
  • 4,369
  • 4
  • 26
  • 45
  • please look at my edited question. I've added more information on what I mean by "Profile". I was talking about the system profile and not the user profile. – Mridang Agarwalla Jul 04 '13 at 12:49
  • In that case that's indeed very different. That's a cyanogen only feature right ? In that case you should maybe move your question there and maybe open a feature request (or even better, a pull request). – Teovald Jul 04 '13 at 15:58
1

How can I trigger an event when the device's profile is changed?

Android does not have any support for this , in other words you can not trigger some event while change the profile .

you can only trigger event when device Ringer mode has change but not for the profile .

even i could not find the profile names of devices and current set profile name which could be the way to make what you are searching for .

dharmendra
  • 7,835
  • 5
  • 38
  • 71
0

As per my discussions with the Cyanogenmod developers, it can be handled by added a BroadcastReceiver for the Intent in ProfileManagerService.java

The issue was that this intent was missing from the ProfileManager.java class and instead existed elsewhere.

The issue for this question can be found on Cyanogenmod's issue tracker.

Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382