Я пытаюсь отправить ArrayList на свое устройство Android Wear с мобильного устройства.
К сожалению, я не могу пройти мимо mGoogleApiClient.connect() в соответствии с моими заявлениями.
Что я сделал, так это настроил элемент DataLayer и использовал onDataChanged() для мониторинга кода и отправляемого с ним DataItem, но, к сожалению, похоже, что ничего не происходит.
Вывод консоли находится внизу поста, если это поможет что-то определить.
ОСНОВНАЯ ДЕЯТЕЛЬНОСТЬ — МОБИЛЬНЫЕ УСТРОЙСТВА
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
Set<String> tasksSet;
ArrayList<String> actsList;
ArrayAdapter adapter;
ListView list;
GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Wearable.API)
.build();
mGoogleApiClient.connect();
if(!PreferenceManager.getDefaultSharedPreferences(this)
.getStringSet("wristaroo", new HashSet<String>()).isEmpty()) {
tasksSet = PreferenceManager.getDefaultSharedPreferences(this)
.getStringSet("wristaroo", new HashSet<String>());
actsList = new ArrayList<String>(tasksSet);
}
else {
actsList = new ArrayList<>();
Set<String> tasksSet = new HashSet<>(actsList);
PreferenceManager.getDefaultSharedPreferences(this)
.edit()
.putStringSet("wristaroo", tasksSet)
.commit();
}
xxxxxxx
other populating code
xxxxxxx
Button btnSend = (Button) findViewById(R.id.sendButton);
btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendCustomSchedule(actsList);
System.out.println("Button Pressed: Send");
}
});
}
private void populateListView() {
list = (ListView) findViewById(R.id.listViewAdd);
list.setAdapter(adapter);
}
public MainActivity getActivity() {
return this;
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
public void sendCustomSchedule(ArrayList<String> customSchedule) {
PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/customSched");
putDataMapRequest.getDataMap().putStringArrayList("customSched", customSchedule);
PutDataRequest request = putDataMapRequest.asPutDataRequest().setUrgent();
Wearable.DataApi.putDataItem(mGoogleApiClient, request)
.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
@Override
public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
if(!dataItemResult.getStatus().isSuccess()) {
System.out.println("Apparent Failure!");
} else {
System.out.println("Apparent Success!");
}
}
});
System.out.println("When in doubt...");
}
}
ОСНОВНОЕ ЗАНЯТИЕ – ОДЕЖДА
public class byTimeActivity extends Activity implements DataApi.DataListener,GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
ArrayList<String> choicesList;
ArrayAdapter adapter;
ListView list;
ArrayList<String> data;
String dayExtra;
String howExtra;
String schedExtra;
GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Wearable.API)
.build();
mGoogleApiClient.connect();
setContentView(R.layout.activity_main);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
dayExtra = getIntent().getExtras().getString("dayExtra");
schedExtra = getIntent().getExtras().getString("schedExtra");
howExtra = getIntent().getExtras().getString("howExtra");
System.out.println("dayExtra: " + dayExtra);
System.out.println("schedExtra: " + schedExtra);
System.out.println("howExtra: " + howExtra);
switch(dayExtra) {
case "Thursday":
if(schedExtra.equals("Full Schedule")) {
setStage(thTime);
}
if(schedExtra.equals("Custom Schedule")) {
adapter = new ArrayAdapter<>(this, R.layout.da_item, data);
}
break;
case "Friday":
setStage(frTime);
break;
case "Saturday":
setStage(saTime);
break;
case "Sunday":
setStage(suTime);
break;
}
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
list = (ListView) findViewById(R.id.mainChoiceList);
list.setAdapter(adapter);
}
});
}
private void setStage(String[] dayStage) {
choicesList = new ArrayList<>(Arrays.asList(dayStage));
adapter = new ArrayAdapter<>(this, R.layout.da_item, choicesList);
adapter.notifyDataSetChanged();
}
@Override
protected void onResume() {
super.onResume();
mGoogleApiClient.connect();
}
@Override
public void onConnected(@Nullable Bundle bundle) {
Wearable.DataApi.addListener(mGoogleApiClient, this);
}
@Override
protected void onPause() {
super.onPause();
Wearable.DataApi.removeListener(mGoogleApiClient, this);
mGoogleApiClient.disconnect();
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
for (DataEvent event : dataEvents) {
if (event.getType() == DataEvent.TYPE_CHANGED) {
DataItem item = event.getDataItem();
if (item.getUri().getPath().compareTo("/customSched") == 0) {
DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
data = dataMap.getStringArrayList("customSched");
System.out.println("Data: " + data);
}
} else if (event.getType() == DataEvent.TYPE_DELETED) {
//dataItem Deleted
}
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
}
ВЫВОД КОНСОЛИ — МОБИЛЬНЫЕ
W/System: ClassLoader referenced unknown path: /data/app/com.michaeldvinci.conedmiro.schedaroo-2/lib/arm
I/GMPM: App measurement is starting up, version: 8487
I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services. Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
E/GMPM: Scheduler not set. Not logging error/warn.
E/GMPM: Uploading is not possible. App measurement disabled
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
I/Adreno200-EGL: <qeglDrvAPI_eglInitialize:265>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_2.5.5.04.02.02.092.059_msm8960_JB_2.5.5_CL3896081_release_AU (CL3896081)
Build Date: 06/25/13 Tue
Local Branch:
Remote Branch: quic/jb_2.5.5
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_JB_2.5.5.04.02.02.092.059 + NOTHING
I/OpenGLRenderer: Initialized EGL, version 1.4
W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
I/System.out: When in doubt...
I/System.out: Button Pressed: Send
I/System.out: Apparent Success!
ВЫВОД КОНСОЛИ — ИЗНОС
W/art: Suspending all threads took: 17.121ms
I/art: Background sticky concurrent mark sweep GC freed 1601(90KB) AllocSpace objects, 0(0B) LOS objects, 23% free, 508KB/663KB, paused 20.603ms total 53.990ms
W/art: Suspending all threads took: 5.855ms
I/art: Background partial concurrent mark sweep GC freed 168(48KB) AllocSpace objects, 0(0B) LOS objects, 45% free, 611KB/1123KB, paused 8.179ms total 61.166ms
I/System.out: mGoogleApiClient connected!
W/GooglePlayServicesUtil: Google Play services out of date. Requires 8487000 but found 8299574
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[ 04-03 23:16:13.428 15148:15148 D/ ]
HostConnection::get() New Host Connection established 0xb3edca60, tid 15148
D/Atlas: Validating map...
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Enabling debug mode 0
W/EGL_emulation: eglSurfaceAttrib not implemented
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3f625e0, error=EGL_SUCCESS
I/System.out: mGoogleApiClient disconnected! //dis/connecting in MainActivity, before switching activities
W/EGL_emulation: eglSurfaceAttrib not implemented
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3f628a0, error=EGL_SUCCESS
W/EGL_emulation: eglSurfaceAttrib not implemented
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3f62700, error=EGL_SUCCESS
I/System.out: schedExtra: Custom Schedule
I/System.out: dayExtra: Thursday
I/System.out: howExtra: By Time
I/System.out: dayExtra: Thursday
I/System.out: schedExtra: Custom Schedule
I/System.out: howExtra: By Time
I/System.out: mGoogleApiClient connected!
D/AndroidRuntime: Shutting down VM
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.michaeldvinci.conedmiro.schedaroo, PID: 15148
java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
W/GooglePlayServicesUtil: Google Play services out of date. Requires 8487000 but found 8299574