我的应用程序中有此代码
Alarm1 = Settings.System.getString(getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED);
它适用于 htcs、motorolas,但不适用于 Galaxy 的手机。应用程序崩溃。以下内容会在不使应用程序服务崩溃的情况下捕获错误吗?
String Alarm1=null;
try{
Alarm1 = Settings.System.getString(getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED);
}
catch (Exception e) {
Log.i("Exception", "Exception next alarm not found = " + e);
}
if (TextUtils.isEmpty(Alarm1)) {
//if i am i here either no alarm is set or couldn't read it from the phone
//do something else
}
除非galaxy s有不同的代码,否则我能找到它。我怎样才能让它在一个可以工作的手机上抛出异常,以进行测试?谢谢。