Git Product home page Git Product logo

Comments (19)

c19354837 avatar c19354837 commented on August 25, 2024 3

V 1.5.1 is available. It'll show volume UI by default for iOS when you press the physical volume button

setVolumn(value, { showUI: false }) will hide the UI again for iOS.

Android shows the UI always

from react-native-system-setting.

c19354837 avatar c19354837 commented on August 25, 2024 2

For Android, you can add these codes in yourPorject/src/main/java/.../MainActivity.java

public class MainActivity extends ReactActivity {
    @Override
    protected String getMainComponentName() {
        return "SystemSettingExample";
    }

    // hide the system volume UI
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_LOWER, 0);
        }
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
        }
        return true;
    }
}

from react-native-system-setting.

c19354837 avatar c19354837 commented on August 25, 2024 2

Thank you. It's my fault, and my codes will block any key event. The right codes can be

public class MainActivity extends ReactActivity {
    @Override
    protected String getMainComponentName() {
        return "SystemSettingExample";
    }

    // hide the system volume UI
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_LOWER, 0);
            return true;
        }
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}

@heyman333 @pppppppppppp12

from react-native-system-setting.

amsul avatar amsul commented on August 25, 2024 1

@c19354837 I mean, we should be able to see the system volume UI when the up/down volume buttons are pressed if we're only using SystemSetting.addVolumeListener

from react-native-system-setting.

c19354837 avatar c19354837 commented on August 25, 2024

since it is always turned off once you load react-native-system-setting

setVolumn(0.5, { showUI: true }) doesn't work ?

from react-native-system-setting.

amsul avatar amsul commented on August 25, 2024

@c19354837 that doesn't seem to work for me. It'd be really nice to have this as a configurable open on initialize :)

from react-native-system-setting.

c19354837 avatar c19354837 commented on August 25, 2024

How about the example?

from react-native-system-setting.

amsul avatar amsul commented on August 25, 2024

That would only be when you're changing the volume. But if you're only using the library to listen to the volume changes, then setVolume is never going to be called.

from react-native-system-setting.

c19354837 avatar c19354837 commented on August 25, 2024

Do you mean that hide the system volume UI when you press volume up/down buttons?

from react-native-system-setting.

alexfigliolia avatar alexfigliolia commented on August 25, 2024

Agreed, with a volume listener this library will hide the default UI

from react-native-system-setting.

c19354837 avatar c19354837 commented on August 25, 2024

I reproduce in iOS, while Android is OK. Have you tested it in Android @amsul @alexfigliolia ?

from react-native-system-setting.

amsul avatar amsul commented on August 25, 2024

@c19354837 nope..I only checked iOS. Is there an easy way to resolve this?

from react-native-system-setting.

amsul avatar amsul commented on August 25, 2024

@c19354837 awesome!! Thanks for the quick release 🙏

from react-native-system-setting.

pppppppppppp12 avatar pppppppppppp12 commented on August 25, 2024

For Android, when I press the physical volume button, how can i hide the system Volum UI with a volume listener ?

from react-native-system-setting.

pppppppppppp12 avatar pppppppppppp12 commented on August 25, 2024

@c19354837 thanks~

from react-native-system-setting.

alexfigliolia avatar alexfigliolia commented on August 25, 2024

@c19354837 Thank you for quick fix

from react-native-system-setting.

heyman333 avatar heyman333 commented on August 25, 2024

@c19354837 Sorry to bother you..

this code makes android hardware backButton not working properly

    // hide the system volume UI
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_LOWER, 0);
        }
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
        }
        return true;
    }

from react-native-system-setting.

heyman333 avatar heyman333 commented on August 25, 2024

I found a solution

import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
import android.view.KeyEvent;
import android.media.AudioManager;
import android.content.Context;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactInstanceManager;


public class MainActivity extends ReactActivity {
    private ReactInstanceManager mReactInstanceManager;

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */

    .....

    // hide the system volume UI
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mReactInstanceManager != null) {
                mReactInstanceManager.onBackPressed();
            } else {
                super.onBackPressed();
            }  
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_LOWER, 0);
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
        }
        return true;
    }
}

from react-native-system-setting.

heyman333 avatar heyman333 commented on August 25, 2024

@c19354837 really appriciate it 👍

from react-native-system-setting.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.