2
我正在構建一個包含ProgressBar的Widget。如果Widget正在計算,我將該ProgressBar的可見性設置爲VISIBLE
,如果所有計算都停止,則設置爲INVISIBILE
。應該沒有問題,因爲setVisibility
記錄爲RemotableViewMethod
。然而,HTC的一些人似乎忘記了它(即在Wildfire S上),因此致電RemoteViews.setVisibility
將導致崩潰。出於這個原因,我嘗試執行檢查,如果setVisibility
真的可以調用。我已經writen這個方法吧:確定一個方法是否是一個`RemotableViewMethod`
private boolean canShowProgress(){
LogCat.d(TAG, "canShowProgress");
Class<ProgressBar> barclz = ProgressBar.class;
try {
Method method = barclz.getMethod("setVisibility", new Class[]{int.class});
Annotation[] anot = method.getDeclaredAnnotations();
return anot.length > 0;
} catch (SecurityException e) {
LogCat.stackTrace(TAG, e);
} catch (NoSuchMethodException e) {
LogCat.stackTrace(TAG, e);
}
return false;
}
這是可行的,但真的醜陋的,因爲它會返回`True'如果任何 Annotiation存在。我看了一下,自己是怎麼做遠程視窗的查找,發現這個:
if (!method.isAnnotationPresent(RemotableViewMethod.class)) {
throw new ActionException("view: " + klass.getName()
+ " can't use method with RemoteViews: "
+ this.methodName + "(" + param.getName() + ")");
}
但我便無法做同樣的,因爲Class RemotableViewMethod
不通過SDK accsesible。如何知道它是否可訪問?
嘿!你認爲這是你可能能夠回答的問題嗎? http://stackoverflow.com/questions/36679333/android-notification-remoteview-settranslationx-for-textview – Zen