마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

화면 끄거나 켜면 효과음 내기 하고 싶은데요

0 추천

제가 하고싶은 거 딱 저거 뿐이에요. 화면 잠금 효과음을 제가 좋아하는 효과음으로 하고 싶어서...

안드로이드 처음(강조) 해봐서 진짜 뭐가 뭔지 하나도 모르겠는데 열심히 찾아봐서 일단, 브로드캐스트에서 soundPool로 소리 나라고 했더니 안 나와서, 브로드캐스트에서 서비스 부르고 서비스에서 소리 나라고 했습니다.

그래서 오늘 하루종일 한 결과는 이겁니다.

메인에는 아무것도 없고요

브로드캐스트 리시버

public class ScreenOnnReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        Log.d("asdfzxcv","receive onn");
        context.startService( new Intent(context,MyService.class) );
    }
}

서비스

public class MyService extends Service {
    SoundPool soundPool;
    private int sound0;
    public MyService() {

    }

    public void onCreate() {
        super.onCreate();
        Log.d("asdfzxcv","service Create");
        soundPool= new SoundPool(1, AudioManager.STREAM_ALARM, 0);
        sound0 = soundPool.load(this,R.raw.open,1);
    }

    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d("asdfzxcv","service Start");
        soundPool.play(sound0,1,1,0,0,1);
        return super.onStartCommand(intent, flags, startId);
    }

    public void onDestroy() {
        Log.d("asdfzxcv","service Destroy");
        super.onDestroy();
    }
    public IBinder onBind(Intent intent) {return null;}
}

manifest에 브캐랑 서비스 있는 거랑

<receiver android:name=".ScreenOnnReceiver">
    <intent-filter>
        <action android:name="android.intent.action.SCREEN_ON" />
    </intent-filter>
</receiver>

<service
    android:name=".MyService"></service>

그리고 raw에 효과음 파일 넣은 거.

깔끔하게 프로젝트 새로 하나 만들어서 다시 쓴 거니까 이거 말고는 뭐 한거 없다는 거 확실해요.

그런데 브로드캐스트 리시버로 비행기모드를 받아보라고 해도 되고, 충전기를 꽂아보라고 해도 멀쩡하게 소리가 나오는데 이어폰 꽂는 거랑 화면 끄고 켤 때는 왜 안 될까요? 

AIRPLANE_MODE를 SCREEN_ON/OFF로 바꾼 것 뿐인데 뭐 특별한 차이가 있는지.. 답변 부탁드립니다~

제목없음 님이 2018년 11월 1일 질문

1개의 답변

0 추천
익명사용자 님이 2018년 11월 1일 답변
...