gpt4 book ai didi

java - 从手机发送ArrayList<> DataItem到穿戴设备

转载 作者:太空宇宙 更新时间:2023-11-04 12:46:41 25 4
gpt4 key购买 nike

目前我的问题是,每当我尝试访问通过 DataItem 层发送的 ArrayList<> 时,它都会告诉我该对象为空。

有人可以阐明问题出在哪里吗?

移动

public class MainActivity extends AppCompatActivity implements  GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

--variables

@Override
protected void onCreate(Bundle savedInstanceState) {

if(!PreferenceManager.getDefaultSharedPreferences(this)
.getStringSet("wristaroo", new HashSet<String>()).isEmpty()) {
tasksSet = PreferenceManager.getDefaultSharedPreferences(this)
.getStringSet("wristaroo", new HashSet<String>());
actsList = new ArrayList<>(tasksSet);
}
-----

googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Wearable.API)
.build();

googleApiClient.connect();

super.onCreate(savedInstanceState);
-----
Button btnSave = (Button) findViewById(R.id.sendButton);
btnSave.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
PutDataMapRequest dataMap = PutDataMapRequest.create("/wristaroo/customschedule");
dataMap.getDataMap().putStringArrayList("schedule", actsList);
PutDataRequest request = dataMap.asPutDataRequest();


PendingResult<DataApi.DataItemResult> result = Wearable.DataApi
.putDataItem((googleApiClient), request);
System.out.println("Request: " + request);
System.out.println("Result: " + result);

}
});
}

-----

@Override
public void onConnected(Bundle bundle) {

new DataTask (this, actsList).execute();
}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}

class DataTask extends AsyncTask<Node, Void, Void> {

private ArrayList<String> contents;
Context c;

public DataTask ( Context c, ArrayList<String> contents) {
this.c = c;
this.contents = contents;
}

@Override
protected Void doInBackground(Node... nodes) {
PutDataMapRequest dataMap = PutDataMapRequest.create("/wristaroo/customschedule").setUrgent();
dataMap.getDataMap().putStringArrayList("schedule", actsList);

PutDataRequest request = dataMap.asPutDataRequest().setUrgent();
Log.i("Data", "data");
DataApi.DataItemResult dataItemResult = Wearable.DataApi
.putDataItem((googleApiClient), request).await();
System.out.println("dataItemResult: " + dataItemResult);

return null;
}
}
}

磨损

public class MainActivity extends Activity implements DataApi.DataListener,GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

super.onCreate(savedInstanceState);

googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Wearable.API)
.build();
---------

@Override
public void onConnected(Bundle bundle) {
Wearable.DataApi.addListener(googleApiClient, this).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
Log.i("myTag", String.valueOf(status));
}
});
System.out.println("onConnected Activated!!!");
}

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
for (DataEvent event : dataEvents) {
if (event.getType() == DataEvent.TYPE_CHANGED) {
// DataItem changed
DataItem item = event.getDataItem();
if (item.getUri().getPath().compareTo("/wristaroo/customschedule") == 0) {
DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
data = dataMap.getStringArrayList("schedule");
}
} else if (event.getType() == DataEvent.TYPE_DELETED) {
// DataItem deleted
}
}
}

@Override
public void onConnectionSuspended(int i) {
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult)

list 移动

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.michaeldvinci.conedmiro.schedaroo">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".EditActivity"
android:label="@string/app_name">
</activity>
<activity
android:name=".AddActivity"
android:label="@string/app_name">
</activity>
</application>

</manifest>

明显磨损

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.michaeldvinci.conedmiro.schedaroo">

<uses-feature android:name="android.hardware.type.watch" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".byDayActivity"
android:label="@string/app_name">
</activity>
<activity
android:name=".byChoiceActivity"
android:label="@string/app_name">
</activity>
<activity
android:name=".byStageActivity"
android:label="@string/app_name">
</activity>
<activity
android:name=".byTimeActivity"
android:label="@string/app_name">
</activity>
<activity
android:name=".byStageActActivity"
android:label="@string/app_name">
</activity>
</application>

</manifest>

按下移动应用上的[发送]按钮时的输出

03-29 18:33:47.948 5246-5246/com.michaeldvinci.conedmiro.schedaroo W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=1307.8564, y[0]=2230.7813, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=473778, downTime=468682, deviceId=0, source=0x1002 }
03-29 18:33:47.948 5246-5246/com.michaeldvinci.conedmiro.schedaroo W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=1307.8564, y[0]=2230.7813, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=473778, downTime=468682, deviceId=0, source=0x1002 }
03-29 18:33:47.948 5246-5246/com.michaeldvinci.conedmiro.schedaroo W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=1307.8564, y[0]=2230.7813, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=473778, downTime=468682, deviceId=0, source=0x1002 }
03-29 18:33:47.948 5246-5246/com.michaeldvinci.conedmiro.schedaroo W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=1307.8564, y[0]=2230.7813, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=473778, downTime=468682, deviceId=0, source=0x1002 }
03-29 18:33:48.179 5246-5246/com.michaeldvinci.conedmiro.schedaroo I/System.out: Request: PutDataRequest[dataSz=108, numAssets=0, uri=wear:/wristaroo/customschedule, syncDeadline=0]
03-29 18:33:48.179 5246-5246/com.michaeldvinci.conedmiro.schedaroo I/System.out: Result: com.google.android.gms.wearable.internal.zzx$1@1ded1a8

最佳答案

这可能最终是一个不正确的答案,但我认为 setUrgent() 标志可能很重要:

请使用此代码:

    PutDataMapRequest dataMap = PutDataMapRequest.create("/wristaroo/customschedule");
dataMap.getDataMap().putStringArrayList("schedule", actsList);

PutDataRequest request = dataMap.asPutDataRequest();
request.setUrgent();
Log.i("Data", "data");
DataApi.DataItemResult dataItemResult = Wearable.DataApi
.putDataItem((googleApiClient), request).await();

关于java - 从手机发送ArrayList<> DataItem到穿戴设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36254079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com