1. 권한
<uses-permission android:name="android.permission.INJECT_EVENTS" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.intent.action.MEDIA_BUTTON" />
* 권한이 필요하지 않은것으로 보임
2. 버튼을 누르면 이벤트를 브로드케스팅!
package com.example.youbackplayer;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Instrumentation;
import android.os.Bundle;
import android.content.Intent;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
public int isPlaying = 0;
final Handler mHandler = new Handler();
Runnable mGoHome = new Runnable(){
public void run(){
Intent intent_home = new Intent(Intent.ACTION_MAIN); //태스크의 첫 액티비티로 시작
intent_home.addCategory(Intent.CATEGORY_HOME); //홈화면 표시
intent_home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //새로운 태스크를 생성하여 그 태스크안에서 액티비티 추가
startActivity(intent_home);
finish(); // 브라우저만 띄우고 종료
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// // 1. 브라우저띄우기
// String my_url = "https://youtu.be/4_QyLhP5qHs";
// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(my_url));
// intent.setPackage("com.android.chrome"); // 브라우저가 여러개 인 경우 콕 찍어서 크롬을 지정할 경우
// startActivity(intent);
//
//
// // 2. 영상플레이시키기
// Intent intent2 = new Intent("com.android.chrome");
// intent2.putExtra("command", "next");
// sendBroadcast(intent2);
//
//
// // 3. 홈화면으로 빠지기
//// mHandler.postDelayed(mGoHome, 30000);
// //mHandler.removeCallbacks(mGoHome);
//
//
// // 4. Next영상으로 이동
//// putCommand(KeyEvent.KEYCODE_MEDIA_NEXT); // 다음 곡
// new Thread(new Runnable() {
// public void run() {
// new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_NEXT);
// }
// }).start();
Button btn01 = (Button) findViewById(R.id.btn);
Button btn02 = (Button) findViewById(R.id.btn2);
Button btn03 = (Button) findViewById(R.id.btn3);
Button btn04 = (Button) findViewById(R.id.btn4);
Button btn05 = (Button) findViewById(R.id.btn5);
//볼륨업
btn01.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_UP);
}
}).start();
}
});
//볼륨다운
btn02.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_DOWN);
}
}).start();
}
});
//플레이/스탑
btn03.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
// new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
if(isPlaying == 1){
new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_PAUSE);
isPlaying = 0;
} else {
new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_PLAY);
isPlaying = 1;
}
}
}).start();
}
});
//넥스트
btn04.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_NEXT);
}
}).start();
}
});
//프리브
btn05.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_PREVIOUS);
}
}).start();
}
});
}
}
'Code Story' 카테고리의 다른 글
[꿀팁] 쉘스크립트 만들기 (0) | 2023.07.21 |
---|---|
[Python] 정규식을 이용한 날짜 포맷 확인 (0) | 2022.05.30 |
클래스 속성과 인스턴스 속성 (0) | 2022.01.26 |
Class of Python - 클래스 기본적인 사용 (0) | 2022.01.26 |
OOP(Object-Oriented Programming) of Python (1) | 2022.01.25 |