简体   繁体   English

您如何制作没有UI的应用程序,所以当您打开它时,它将运行一些代码

[英]How do you make an app with no UI so when you open it, it runs some code

I am making a simple app that, when opened, checks what the media volume. 我正在制作一个简单的应用程序,当打开该应用程序时,它会检查媒体量。 If it is more than zero, sets it to 0 and when it is equal to zero, sets it to 100%. 如果大于零,则将其设置为0,等于零时,将其设置为100%。 (I'm gonna remap the bixby button). (我要重新映射bixby按钮)。 My problem is is that when I open the app, it opens a blank UI, like this: https://i.imgur.com/d9NkFX0.png And I don't want it to. 我的问题是,当我打开该应用程序时,它会打开一个空白UI,如下所示: https : //i.imgur.com/d9NkFX0.png而且我不希望这样做。

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
        int volume_level= am.getStreamVolume(AudioManager.STREAM_MUSIC);
        if (volume_level > 0)
        {
            am.setStreamVolume(
                    AudioManager.STREAM_MUSIC,
                    volume_level,
                    0);
        }
        else {
            am.setStreamVolume(
                    AudioManager.STREAM_MUSIC,
                    volume_level,
                    100);
        }
    }

Also it kinda doesn't work at all. 而且它一点也不起作用。

You are opening an activity. 您正在开启一个活动。 This will remain open until you exit it. 它将保持打开状态,直到您退出它。

Try adding a finish() at the end of onCreate() 尝试在onCreate()的末尾添加finish()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Cocoa UI制作Java应用程序? - How do you make a Java app with a Cocoa UI? 你是怎么做到的,当你输入一个数字时,它会在每个 integer 之间放置一个空格 - How do you make it so that when you enter a number it puts a space between each integer 当bash脚本通过Java代码运行时,如何在Linux中将用户工作设置为root用户 - How do you set user work as root in Linux, when the bash script runs via Java code 如何更改屏幕,以便在单击屏幕上的任意位置时都能从问题中找到答案? - How do you change the screen so that when you click anywhere on the screen, you go from the problem to the answer? Flutter:自定义导航栏,如何进行导航,这样当你切换你点击的按钮时? - Flutter: Custom Nav Bar, how to make navigation, so that when you switch the button that you clicked on? 如何命名 SwingWorker 线程? 对代码或最佳实践开放 - How do you name a SwingWorker thread? Open to code or best practices 没有项目时如何使用Android DeviceAdminSample.java代码 - How do you make use of the Android DeviceAdminSample.java code when there's no project 在Java中,仅在没有框架打开时如何退出应用程序? - In Java, how do you exit the application only when there is no frame open? 使用Java时如何保持命令提示符处于打开状态? - How do you keep the command prompt open when using Java? 如何在JavaFX中定期刷新代码? - How do you make code refresh itself at regular intervals in JavaFX?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM