- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将文件从我的 Google Wear 发送到我的 Nexus 5。我已经阅读了一些教程并想出了以下代码,但我的手机没有收到文件。
手机:
private GoogleApiClient mGoogleApiClient;
private int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Log.d(TAG, "CONNECTING:");
mGoogleApiClient.connect();
}
@Override
protected void onResume() {
super.onStart();
}
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "CONNECTED");
Toast.makeText(getApplicationContext(), "Connected.",
Toast.LENGTH_LONG).show();
Wearable.DataApi.addListener(mGoogleApiClient, this);
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
protected void onPause() {
super.onPause();
Wearable.DataApi.removeListener(mGoogleApiClient, this);
mGoogleApiClient.disconnect();
}
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
Toast.makeText(getApplicationContext(), "Data changed.",
Toast.LENGTH_LONG).show();
for (DataEvent event : dataEvents) {
if (event.getType() == DataEvent.TYPE_CHANGED &&
event.getDataItem().getUri().getPath().equals("/txt")) {
// Get the Asset object
DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
Asset asset = dataMapItem.getDataMap().getAsset("sensordataAsset");
Log.d(TAG, "");
ConnectionResult result =
mGoogleApiClient.blockingConnect(10000, TimeUnit.MILLISECONDS);
if (!result.isSuccess()) {
return;
}
// Convert asset into a file descriptor and block until it's ready
InputStream assetInputStream = Wearable.DataApi.getFdForAsset(
mGoogleApiClient, asset).await().getInputStream();
mGoogleApiClient.disconnect();
if (assetInputStream == null) {
return;
}
// Get folder for output
File storage = getApplicationContext().getFilesDir();
Log.d(TAG, "Location:" + storage.toString());
File dir = new File(storage.getAbsolutePath() + "/Clockwork/");
if (!dir.exists()) {
dir.mkdirs();
} // Create folder if needed
Log.d(TAG, dir.getAbsolutePath());
// Read data from the Asset and write it to a file on external storage
final File file = new File(dir, "sensordata.txt");
if (!file.exists()) {
file.mkdirs();
}
Log.d(TAG, file.getPath());
try {
FileOutputStream fOut = new FileOutputStream(file);
int nRead;
byte[] data = new byte[16384];
while ((nRead = assetInputStream.read(data, 0, data.length)) != -1) {
fOut.write(data, 0, nRead);
}
fOut.flush();
fOut.close();
} catch (Exception e) {
}
// Rescan folder to make it appear
try {
String[] paths = new String[1];
paths[0] = file.getAbsolutePath();
MediaScannerConnection.scanFile(this, paths, null, null);
} catch (Exception e) {
}
}
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
穿着:
public void sendTextFile() {
readFromFile();
FileInputStream fileInputStream = null;
byte[] bFile = new byte[(int) file.length()];
try {
fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
} catch (Exception e) {
Log.e(TAG, "sendTextFile: " + e.toString());
}
connectGoogleApi();
//Create an Asset from the byte array and set it via the DataApi
Asset asset = Asset.createFromBytes(bFile);
PutDataMapRequest dataMap = PutDataMapRequest.create("/txt");
dataMap.getDataMap().putAsset("sensordataAsset", asset);
PutDataRequest request = dataMap.asPutDataRequest();
PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi
.putDataItem(mGoogleApiClient, request);
}
private void connectGoogleApi() {
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "CONNECTED");
Toast.makeText(context, "Connected.",
Toast.LENGTH_LONG).show();
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
我用上面列出的方法制作了一个记录器。有人可以告诉我我做错了什么。提前致谢。
最佳答案
在数据图中添加一个键值:map.put("时间戳", System.currentmillions())您的手机没有收到任何更改事件,因为您将相同的数据项放入数据 api 队列中,请尝试放入不同的项
关于wear-os - 将文件 Google Wear 发送到手机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28808283/
我一直在 list 中使用以下意图过滤器,一切正常: 这已被弃用,所以我尝试使用: 我可以正常接收消息,但 onPeerConnected 现在永远不会被调用。 public class
我一直在 list 中使用以下意图过滤器,一切正常: 这已被弃用,所以我尝试使用: 我可以正常接收消息,但 onPeerConnected 现在永远不会被调用。 public class
最新的Android Wear更新随附对ChannelApi的支持,可用于向可穿戴设备或手持设备发送文件或从可穿戴设备或手持设备发送文件。问题是我找不到有关如何使用此功能的单个示例。 Android示
我已经根据官方 API 更新了我的 Android Wear 表盘,总体来说进展顺利。然而,我坚持的一件事是从 Android Wear 应用程序中启动配套(手持)配置事件。我只是无法在 AW 应用程
我在 Moto 360 上启用了蓝牙调试并在我的 Nexus4 上启用了 Android Wear 应用程序。 状态显示目标:已断开 从我的电脑转发端口显示状态主机将更改为已连接,但目标状态仍保持断开
Android Wear 生态系统似乎是围绕用户将与之交互然后关闭的快速任务构建的。这对大多数应用程序都很有效,但是对于一个涵盖长时间运行的任务并且在 watch 休眠时不应自动关闭的应用程序呢? 我
我正在 Android 中开发一个应用程序以及 Android Wear 支持。在查看来自 https://developer.android.com/training/building-wearab
我打开了 USB 调试,我显示目标已连接,但我无法连接主机。 当我在我的 PC 上运行以下命令时,我得到指示该命令未完成的输出。 adb forward tcp:4444 localabstract:
据我所知,有两种方法可以为 Android Wear 中的通知设置背景图像。为了记录,两者都以: Bitmap bitmap; Notification.Builder bob = new
我正在编写一个自定义 Android Wear 应用程序,该应用程序应该向连接的主机设备(电话)发送一次性消息。通过 API 挖掘,我发现以下教程应该可以很好地工作:http://developer.
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在尝试将文件从我的 Google Wear 发送到我的 Nexus 5。我已经阅读了一些教程并想出了以下代码,但我的手机没有收到文件。 手机: private GoogleApiClient mG
我正在尝试为 Google Wear 设置我的开发环境并遵循了 Google 的 instructions但是一旦我设置了端口转发 (adb -d forward tcp:5601 tcp:5601)
在开发 Android Wear 表盘时,如何检测屏幕是否是圆形且有下巴(又名扁平轮胎带),如 Moto 360?我尝试了 onSurfaceChanged,但宽度和高度是相同的。 我在有下巴的模拟器
我正在为 Android Wear 编写应用程序,我需要在关闭应用程序时实现与 Android Wear 上的 Google map 应用程序类似的行为。 通常,“Swipe-To-Dismiss”手
我正在开发一款适用于 Android Wear 的应用程序,它可以在手机上启动一项 Activity 。一切都很好,但我不想依赖手机上不断运行的后台服务来接收这条消息。理想情况下,我会让 Wearab
我尝试通过启动语音命令启动我的穿戴应用程序。我按照文档 Adding Voice Capabilities .但是,当我尝试通过说(OK Google)“启动我的应用程序”来启动应用程序时,我会收到与
当我使用数字表冠时,我的列表没有滚动 这就是我所做的; public class MainActivity extends Activity { @Override protecte
根据指南: https://developer.android.com/design/wear/patterns.html#Continuing “在必须使用手机的情况下,一旦点击操作按钮并在手机上打
有人可以分享有关使用 Android Wear 使用手腕运动(与触摸屏上的滑动运动相反)进行手势检测的信息吗? API 中有对此的官方支持吗?如果没有,您认为可以通过自定义 ROM 启用此功能吗?考虑
我是一名优秀的程序员,十分优秀!