2013-05-13 68 views
1

手动它可以通过设置菜单来完成,但是有没有一个API android公开通过一些函数调用来改变这个设置?如何以可编程方式打开和关闭辅助功能服务?

我想要实现的是在应用程序运行时禁用话语提示。更确切地说,我只是想禁用话语提示的探索功能。

所以他们都会让你做

一)禁用可访问性服务或
二)禁止话语提示或
三)禁止话语提示功能触摸浏览

+0

我觉得这个问题以前曾被问过,但是我找不到它。你为什么要禁用这项服务,你是否在自己的实现?> – 2013-05-13 12:59:01

+0

@RyanB我的应用程序利用手势,但是当“通过触摸浏览”启用时,它会从我的应用程序中窃取所有手势。 – 2013-05-14 08:45:59

+0

你是否在做一些补偿? – 2013-05-14 15:36:42

回答

0

一点点在这一个晚,但也许它会帮助某人。

在我的主类中,我使用了我的辅助功能服务类的意图。我有一个断开关上,我将通过一个布尔过我要不要来访问

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); 

} 
} 

然后在为myService类我会收到与onStartCommand意图。这似乎对我很好。

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    onOffService = intent.getBooleanExtra("onOffService", true); 
    return super.onStartCommand(intent, flags, startId); 
} 

然后,我会使用布尔内函数来确定我是否希望服务处于活动状态。 希望这有助于!

0

您可以通过简单地调用

disableSelf();

注意关闭辅助功能服务:这将设置也关闭服务。您需要重新从用户处取回。
如果您想关闭,请暂时使用Blazej Gawlik方法。

相关问题