1

この機能を複製しようとしていますhttps://developer.android.com/training/wearables/data-layer/assets.html。時計の送信機部分は問題ありません。ハンドヘルドのonDataChanged関数では、呼び出されるWearableListenerServiceたびに例外が発生します。DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());

例外は次のとおりです。

04-30 13:02:21.003  16588-16588/com.xxx.hbips I/dalvikvm﹕ Could not find method     android.content.pm.PackageManager.getPackageInstaller, referenced from method   com.google.android.gms.common.GooglePlayServicesUtil.zzh
04-30 13:02:21.003  16588-16588/com.xxx.hbips W/dalvikvm﹕ VFY: unable to resolve virtual method 464:    Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
04-30 13:02:21.003  16588-16588/com.xxx.hbips D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000b
04-30 13:02:21.053  16588-16790/com.xxx.hbips E/DataLayerSample﹕ WEAR :: Service connected to   GoogleApiClient.
04-30 13:02:21.053  16588-16790/com.xxx.hbips W/dalvikvm﹕ threadid=19: thread exiting with uncaught     exception (group=0x417bfd58)
04-30 13:02:21.053  16588-16790/com.xxx.hbips E/AndroidRuntime﹕ FATAL EXCEPTION: WearableListenerService
    Process: com.xxx.hbips, PID: 16588
    java.lang.IllegalStateException: Cannot find DataItemAsset referenced in data at 0 for DataItemEntity   [@4287a7e0,dataSz=0, numAssets=1, uri=wear://df70fc47-0580-4750-b6ea-6e47439ed1ed/audio]
            at com.google.android.gms.wearable.DataMapItem.zza(Unknown Source)
            at com.google.android.gms.wearable.DataMapItem.<init>(Unknown Source)
            at com.google.android.gms.wearable.DataMapItem.fromDataItem(Unknown Source)
            at com.xxx.hbips.DataLayerListenerService.onDataChanged(DataLayerListenerService.java:58)
            at com.google.android.gms.wearable.WearableListenerService$zza$1.run(Unknown Source)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.os.HandlerThread.run(HandlerThread.java:61)

送信コードは次のとおりです。

class IpsTimerTask extends TimerTask {
        public void run() {
            sem.acquireUninterruptibly();
            byte[] buffer = new byte[60000];
            audioRecord.startRecording();
            audioRecord.read(buffer, 0, 60000);
            audioRecord.stop();
            sem.release();

            Asset asset = Asset.createFromBytes(buffer);
            PutDataRequest request = PutDataRequest.create("/audio");
            request.putAsset("Audio", asset);
            Wearable.DataApi.putDataItem(mGoogleApiClient, request);
            Log.d(TAG, "transmitted"+buffer.length);
        }
    }

受信コードは次のとおりです。

public void onDataChanged(DataEventBuffer dataEvents) {
        final List<DataEvent> events = FreezableUtils
                .freezeIterable(dataEvents);
        dataEvents.close();

        if (!mGoogleApiClient.isConnected()) {
            ConnectionResult connectionResult = mGoogleApiClient
                    .blockingConnect(30, TimeUnit.SECONDS);
            if (!connectionResult.isSuccess()) {
                Log.e(TAG,"WEAR :: Service failed to connect to GoogleApiClient.");
                return;
            }
        } else {
            Log.e(TAG,"WEAR :: Service connected to GoogleApiClient.");
        }

        for (DataEvent event : events) {
            if (event.getType() == DataEvent.TYPE_CHANGED &&
                    event.getDataItem().getUri().getPath().equals("/audio")) {

                DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
                Asset audioAsset = dataMapItem.getDataMap().getAsset("Audio");
                DataExchange.setBuffer(loadAudioFromAsset(audioAsset));
                Log.w(TAG, "receive");
            }
        }
    }

何かアイデアはありますか?

4

2 に答える 2

1

問題はここにあるようです:

final List<DataEvent> events = FreezableUtils
    .freezeIterable(dataEvents);
dataEvents.close();

どういう意味ですか?詳細な回答については、このコードを表示してください。

于 2015-05-05T10:46:59.153 に答える
0

これを交換することで解決しました

    PutDataRequest putDataRequest = PutDataRequest.create("/image");
    putDataRequest.putAsset("debugFile", asset);
    Wearable.DataApi.putDataItem(client, putDataRequest);

これとともに

    PutDataMapRequest dataMap = PutDataMapRequest.create("/image");
    dataMap.getDataMap().putAsset("debugFile", asset);
    PutDataRequest request = dataMap.asPutDataRequest();
    PendingResult<DataItemResult> pendingResult = Wearable.DataApi.putDataItem(client, request);
    pendingResult.setResultCallback(new ResultCallback<DataItemResult> () {
        @Override
        public void onResult(DataItemResult dataItemResult) {
            // something 
        }
    } );

今、それは私のために働く

于 2015-06-02T11:08:25.747 に答える