1

我试图通过以下sendListCountWithContent()方法更新 SmartWatch 2 Control 上的 ListView 项目内容(带有一个 TextView):

public class SmartWatch2Control extends ControlExtension {

    private List<String> accs;

    @Override
    public void onResume() {
        accs = Utils.getAllAccounts();
        showLayout(R.layout.smartwatch2, null);
        sendListCountWithContent(R.id.smartwatch2_list, accs.size(),
            bundlesForList(accs));
        sendListPosition(R.id.smartwatch2_list, 0);
    }

    private Bundle[] bundlesForList(List<String> list) {
        Bundle[] result = new Bundle[list.size()];

        for (int i = 0; i < list.size(); i++) {
            Bundle nameBundle = new Bundle();
            nameBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE,
                R.id.acc_name);
            nameBundle.putString(Control.Intents.EXTRA_TEXT, list.get(i));
            Bundle[] views = new Bundle[] { nameBundle };

            Bundle b = new Bundle();
            b.putInt(Control.Intents.EXTRA_DATA_XML_LAYOUT,
                R.layout.smartwatch2_item);
            b.putInt(Control.Intents.EXTRA_LIST_ITEM_ID, i);
            b.putInt(Control.Intents.EXTRA_LIST_ITEM_POSITION, i);
            b.putParcelableArray(Control.Intents.EXTRA_LAYOUT_DATA, views);

            result[i] = b;
        }

        return result;
    }
}

当我尝试在 SmartWatch 2 模拟器上启动应用程序时,出现异常:

10-19 14:49:17.823: ERROR/AndroidRuntime(8841): FATAL EXCEPTION: main
        java.lang.ClassCastException: android.os.Parcelable[] cannot be cast to android.os.Bundle[]
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.CostanzaListAdapter.<init>(CostanzaListAdapter.java:40)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.renderListView(ControlActivity.java:632)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.access$10(ControlActivity.java:624)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity$8.run(ControlActivity.java:447)
        at android.app.Activity.runOnUiThread(Activity.java:4170)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.onListCount(ControlActivity.java:441)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.ControlActivity.handleEvent(ControlActivity.java:264)
        at com.sonyericsson.extras.liveware.emulator.accessory.costanza.ui.CostanzaActivity$ServiceMessageHandler.handleMessage(CostanzaActivity.java:240)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4575)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
        at dalvik.system.NativeStart.main(Native Method)

链接到测试项目

索尼不提供关于 api 方法的 web javadocs(仅意图),所以我在这里摘录:

package com.sonyericsson.extras.liveware.extension.util.control;

public abstract class ControlExtension {

<..>

    protected void sendListCountWithContent(int layoutReference, int listCount, Bundle[] bundles) {
        Intent intent = new Intent(Control.Intents.CONTROL_LIST_COUNT_INTENT);
        intent.putExtra(Control.Intents.EXTRA_LAYOUT_REFERENCE, layoutReference);
        intent.putExtra(Control.Intents.EXTRA_LIST_COUNT, listCount);
        intent.putExtra(Control.Intents.EXTRA_LIST_CONTENT, bundles);
        sendToHostApp(intent);
    }

<..>

}

当我调用sendListCountWithContent方法应用程序将CONTROL_LIST_COUNT_INTENT意图发送到主机应用程序 (SmartConnect) 时,主机应用程序将意图重新发送到模拟器(或连接的 SmartWatch2),该模拟器基于意图额外内容构建布局。这里抛出了一个 ClassCastException。

我不确定,但它看起来像模拟器中的错误。

4

1 回答 1

0

我们知道此错误并已实施修复,该修复将在下一版本的 Sony Add-on SDK 中提供。

于 2013-10-23T17:03:04.120 回答