Haruyuki Mohri



The getRingerMode of JAudioManager. is Returns the current ringtone mode of Android.
JAudioManager::getRingerMode() is also available in C++Builder.

The current ringtone mode(getRingerMode()), one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE.

int name value
0 RINGER_MODE_SILENT Ringer mode that will be silent and will not vibrate.
1 RINGER_MODE_VIBRATE Ringer mode that will be silent and will vibrate.
2 RINGER_MODE_NORMAL Ringer mode that may be audible and may vibrate.


Several inclusions are necessary to use in C++Builder.

#include <Androidapi.Helpers.hpp>
#include <Androidapi.JNI.GraphicsContentViewText.hpp>
#include <Androidapi.JNI.Media.hpp>
#include <Androidapi.JNIBridge.hpp>


Create variables for _di_JObject and _di_JAudioManager.

class TForm1 : public TForm
__published:  // IDE-managed Components
    TComboBox *ComboBox1;
    TRectangle *Rectangle1;
    TLabel *Label1;
    TTimer *Timer1;
    TRectangle *Rectangle2;
    TButton *Button1;
    void __fastcall Timer1Timer(TObject *Sender);
    void __fastcall Button1Click(TObject *Sender);
private:  // User declarations
    _di_JObject f_sound_;
    _di_JAudioManager f_audio_manager_;
public:       // User declarations
    __fastcall TForm1(TComponent* Owner);

Create a JAudioManager instance.

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
    f_sound_            = TAndroidHelper::Activity->getSystemService(TJContext::JavaClass->AUDIO_SERVICE);
    f_audio_manager_    = TJAudioManager::Wrap((_di_IJavaInstance)f_sound_);

Get the current ringtone mode.

Get ringtone mode with TTimer event.
Change the color(Pink,Yellow,Limegreen) for each ringtone mode.

void __fastcall TForm1::Timer1Timer(TObject *Sender)
    int mode_ = f_audio_manager_->getRingerMode();

    Label1->Text = ComboBox1->Items->Strings[mode_];
    ComboBox1->ItemIndex = mode_;
    switch (mode_) {
    case 0:
        Rectangle1->Fill->Color = TAlphaColorRec::Pink;
    case 1:
        Rectangle1->Fill->Color = TAlphaColorRec::Yellow;
    case 2:
        Rectangle1->Fill->Color = TAlphaColorRec::Limegreen;

Sets the ringer mode.

Each time you press the button on the bottom side, you change the mode.

void __fastcall TForm1::Button1Click(TObject *Sender)
    int mode_ = ComboBox1->ItemIndex + 1;
    if (mode_ >= ComboBox1->Items->Count) mode_ = 0;