我已经看到了这个Q&A LocationSettingsRequest对话框 - 跳过了onActivityResult().这不是同一个问题,因为一切都在Activity中完成.
使用的代码几乎是逐字逐句的,在Google Play服务示例中给出了.
我有一个活动,LocationActivity它连接到GoogleApiClient以获取用户的位置.连接后,我创建一个LocationSettingsRequest以确保打开位置设置.活动正在实施ResultCallback<LocationSettingsResult>.
ResultCallback<LocationSettingsResult>.onResult()被称为如果result.getStatus().getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED再status.startResolutionForResult(this, REQUEST_CHECK_SETTINGS)被称为并且所示的对话框.无论选择什么,问题onActivityResult()都不会被调用.
@Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "GoogleApiClient connected");
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(new LocationRequest().setPriority(LocationRequest.PRIORITY_LOW_POWER));
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(this);
}
Run Code Online (Sandbox Code Playgroud)
.
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
Log.d(TAG, "onResult() called with: " + "result = [" + status.getStatusMessage() + "]");
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
getLocation(); …Run Code Online (Sandbox Code Playgroud) 除了sync和async之外,他们的文档中的差异让我感到困惑.他们的github页面上的示例仍然看起来像是同步调用continuation.
continueWith()
Adds a synchronous continuation to this task, returning a new task that completes after the continuation has finished running.
continueWithTask()
Adds an asynchronous continuation to this task, returning a new task that completes after the task returned by the continuation has completed.
我正在使用自定义ResourceCursorAdapter来显示TextView和CheckBox的ListView。TextView和CheckBox从游标获取它们的状态。我一直在遇到一些问题,最近的问题是,当我滚动某些行时,其中的文本来自旧的TextViews,而某些CheckBoxes则应选中它们。我添加了一条日志行以查看发生了什么,这让我更加困惑。
@Override
public void bindView(View v, Context ctx, Cursor c) {
ViewHolder holder = (ViewHolder)v.getTag();
holder.tv.setText(holder.tvText);
holder.cb.setChecked(holder.checked);
Log.d(TAG, "in bindView, rowId:" + holder.rowId + " Scripture:" + holder.tvText);
}
Run Code Online (Sandbox Code Playgroud)
。
@Override
public View newView(Context ctx, Cursor c, ViewGroup vg){
View v = li.inflate(layout, vg, false);
ViewHolder holder;
holder = new ViewHolder();
holder.tv = (TextView)v.findViewById(to[0]);
holder.tvText = c.getString(c.getColumnIndex(from[0]));
holder.cb = (CheckBox)v.findViewById(to[1]);
holder.rowId = c.getLong(c.getColumnIndex(from[2]));
holder.checked = (c.getString(c.getColumnIndexOrThrow(from[1])).equals("n")) ?
false : true;
holder.cb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
View …Run Code Online (Sandbox Code Playgroud) 我有两个正在连接的设备。当我离开应用程序时,我会断开与设备的连接。两者都经历相同的过程,但有时其中一个设备会保持连接,直到我强制关闭应用程序。
我的设备上有指示灯,确认它仍然认为它已连接,并且应用程序的其他实例无法连接到它,直到我强行关闭第一个实例。在下面的日志中,第一个列出的设备保持连接。
//call gatt.disconnect();
BluetoothGatt: cancelOpen() - device: F0:3D:A0:04:CA:E7
BluetoothGatt: onClientConnectionState() - status=0 clientIf=7 device=F0:3D:A0:04:CA:E7
//wait for connection state change callback then call gatt.close();
BluetoothGatt: close()
BluetoothGatt: unregisterApp() - mClientIf=7
//call gatt.disconnect();
BluetoothGatt: cancelOpen() - device: FF:A9:CA:EF:08:A4
BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=FF:A9:CA:EF:08:A4
//wait for connection state change callback then call gatt.close();
BluetoothGatt: close()
BluetoothGatt: unregisterApp() - mClientIf=5
Run Code Online (Sandbox Code Playgroud)
调用 gatt.close() 后,我获取蓝牙管理器并在已连接设备列表中查找我的设备。它在列表中。
从BluetoothGattCallback
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
final String address = gatt.getDevice().getAddress(); …Run Code Online (Sandbox Code Playgroud)