조금씩함으로써 탐색, 그러나 아마 누군가를 도울 것입니다.
내 주 수업에서는 내 접근성 서비스 클래스에 대한 의도를 사용했습니다. 나는 내가 그런는 myService 클래스에 내가 onStartCommand와 의도를받을 수있는 액세스를
public class MainActivity extends AppCompatActivity {
Switch onOffSwitch;
Intent serviceIntent;
public void onOff(View view){
if(onOffSwitch.isChecked()){
Log.i("Main Switch", "Turn on please");
serviceIntent.putExtra("onOffService", true);
}
else{
Log.i("Main Switch", "Turn off please");
serviceIntent.putExtra("onOffService", false);
}
this.startService(serviceIntent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
onOffSwitch = (Switch) findViewById(R.id.onOffSwitch);
serviceIntent= new Intent(this, myService.class);
}
}
를 원할지 여부를 통해 부울을 통과 할있는 오프 스위치에 있었다. 이것은 나를 위해 잘 작동하는 것 같았다.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
onOffService = intent.getBooleanExtra("onOffService", true);
return super.onStartCommand(intent, flags, startId);
}
나는 서비스를 활성화할지 여부를 결정하기 위해 함수 내부에서 부울을 사용합니다. 희망이 도움이됩니다!
나는이 질문이 이전에 요청 받았던 것처럼 느낀다. 그러나 나는 그것을 발견 할 수 없다. 왜 서비스를 사용하지 않겠습니까? 직접 구현하고 있습니까?> –
@RyanB 내 앱은 제스처를 사용하지만 '터치하여 탐색'을 사용하면 내 앱에서 모든 제스처를 훔칩니다. –
보상 할 일이 있습니까? –