如果它看到手机没有信号/互联网连接等,我希望允许我的VoiceRecognition.java
代码启动另一项活动。这是代码(从Google采用)。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate our UI from its XML layout description.
setContentView(R.layout.voice_recognition);
// Get display items for later interaction
Button speakButton = (Button) findViewById(R.id.btn_speak);
View exitButton = findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
mList = (ListView) findViewById(R.id.list);
// Check to see if a recognition activity is present
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() != 0) {
speakButton.setOnClickListener(this);
}
else {
speakButton.setEnabled(false);
Intent b = new Intent(this, ReminderEditActivity.class);
startActivity(b);;
}
}
我尝试使用ReminderEditActivity.class
添加意图。此外,我试图翻转If语句,说if if(activitysize = 0
)然后转到ReminderEditActivity.class
。我在那里遇到了错误。