- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Google Nearby 通过超声波(不是 BLE 或 WiFi)发送消息。我不知道为什么它不起作用。我还没有找到任何其他步骤来完成这项工作。
没有错误。日志显示发布成功。但是订阅者根本没有反应
应用是否应该请求麦克风权限?应用程序应该检查其他东西吗?iOS 和 Android 之间是否有现成的超声波消息工作示例?
iOS 部分:
@implementation ViewController {
GNSMessageManager *_messageManager;
}
- (void)viewDidLoad {
[super viewDidLoad];
_messageManager = [[GNSMessageManager alloc]
initWithAPIKey:@"MY_API_KEY"
paramsBlock:^(GNSMessageManagerParams *params) {
params.microphonePermissionErrorHandler = ^(BOOL hasError) {
NSLog(@"Microphone Permission Error:%@", hasError ? @"YES" : @"NO");
};
params.bluetoothPowerErrorHandler = ^(BOOL hasError) {
NSLog(@"Bluetooth Power Error:%@", hasError ? @"YES" : @"NO");
};
params.bluetoothPermissionErrorHandler = ^(BOOL hasError) {
NSLog(@"Bluetooth Permission Error:%@", hasError ? @"YES" : @"NO");
};
}];
[GNSMessageManager setDebugLoggingEnabled:YES];
[GNSPermission setGranted:YES];
GNSPermission *nearbyPermission = [[GNSPermission alloc] initWithChangedHandler:^(BOOL granted) {
NSLog(@"Nearby Permission:%@", granted ? @"YES" : @"NO");
}];
id <GNSSubscription> subscription = [_messageManager subscriptionWithMessageFoundHandler:^(GNSMessage *message) {
NSLog(@"subscriptionWithMessageFoundHandler");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Google Nearby Message" message:[[NSString alloc] initWithData:message.content encoding:NSUTF8StringEncoding] preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
messageLostHandler:^(GNSMessage *message) {
// Remove the name from the list
}
paramsBlock:^(GNSSubscriptionParams *subscriptionParams) {
subscriptionParams.strategy = [GNSStrategy strategyWithParamsBlock:^(GNSStrategyParams *params) {
params.discoveryMediums = kGNSDiscoveryMediumsAudio;
params.discoveryMode = kGNSDiscoveryModeScan;
}];
}
];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)publishDidClick:(id)sender {
NSString *string = self.publisherField.text;
if (string == nil || string.length == 0) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Google Nearby" message:@"Please put some text into field before publishing" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
} else {
@try {
GNSMessage *gnsMessage = [GNSMessage messageWithContent:[string dataUsingEncoding:NSUTF8StringEncoding]];
id <GNSPublication> publication = [_messageManager publicationWithMessage:gnsMessage
paramsBlock:^(GNSPublicationParams *params) {
params.strategy = [GNSStrategy strategyWithParamsBlock:^(GNSStrategyParams *params) {
params.discoveryMediums = kGNSDiscoveryMediumsAudio;
}];
}];
}
@catch (NSException *exception) {
NSLog(@"Exception occurred: %@, %@", exception, [exception userInfo]);
}
}
}
iOS 日志:
2017-02-17 22:33:33.701925 GoogleNearbySample[5727:1608902] Nearby Permission:YES
2017-02-17 22:33:35.842523 GoogleNearbySample[5727:1608902] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-02-17 22:33:35.853836 GoogleNearbySample[5727:1608902] [MC] Reading from public effective user settings.
2017-02-17 22:33:40.630279 GoogleNearbySample[5727:1608902] Publish (mediums: 1, broadcast/scan: 3, beacons: 0/0/0, background: 0)
2017-02-17 22:33:40.677551 GoogleNearbySample[5727:1608902] Unpublish
2017-02-17 22:33:40.681520 GoogleNearbySample[5727:1608902] Tokens: 0 good, 0 bad, 0 broadcast
2017-02-17 22:33:40.681663 GoogleNearbySample[5727:1608902] Report RPC request: 0 token(s), 0 beacon(s), 0 directive(s)
2017-02-17 22:33:40.705243 GoogleNearbySample[5727:1608902] Report RPC request: Publish: 1
2017-02-17 22:33:40.705933 GoogleNearbySample[5727:1608902] Report RPC request: Unpublish: 1
2017-02-17 22:33:41.625510 GoogleNearbySample[5727:1608902] Report RPC response: Success
2017-02-17 22:33:41.626823 GoogleNearbySample[5727:1608902] Report RPC response: 6 directive(s), 0 token(s), 0 message(s), 1 publication results(s), 0 subscription results(s)
2017-02-17 22:33:41.641955 GoogleNearbySample[5727:1608902] Tokens: 0 good, 0 bad, 0 broadcast
2017-02-17 22:33:41.642170 GoogleNearbySample[5727:1608902] Report RPC request: 0 token(s), 0 beacon(s), 0 directive(s)
2017-02-17 22:33:41.889006 GoogleNearbySample[5727:1608902] Report RPC response: Success
2017-02-17 22:33:41.889370 GoogleNearbySample[5727:1608902] Report RPC response: 0 directive(s), 0 token(s), 0 message(s), 0 publication results(s), 0 subscription results(s)
2017-02-17 22:33:46.337377 GoogleNearbySample[5727:1608902] Publish (mediums: 1, broadcast/scan: 3, beacons: 0/0/0, background: 0)
2017-02-17 22:33:46.342647 GoogleNearbySample[5727:1608902] Unpublish
2017-02-17 22:33:46.350383 GoogleNearbySample[5727:1608902] Tokens: 0 good, 0 bad, 0 broadcast
2017-02-17 22:33:46.350746 GoogleNearbySample[5727:1608902] Report RPC request: 0 token(s), 0 beacon(s), 0 directive(s)
2017-02-17 22:33:46.351382 GoogleNearbySample[5727:1608902] Report RPC request: Publish: 1
2017-02-17 22:33:46.351675 GoogleNearbySample[5727:1608902] Report RPC request: Unpublish: 1
2017-02-17 22:33:46.937869 GoogleNearbySample[5727:1608902] Report RPC response: Success
2017-02-17 22:33:46.938223 GoogleNearbySample[5727:1608902] Report RPC response: 6 directive(s), 0 token(s), 0 message(s), 1 publication results(s), 0 subscription results(s)
2017-02-17 22:33:46.951400 GoogleNearbySample[5727:1608902] Tokens: 0 good, 0 bad, 0 broadcast
2017-02-17 22:33:46.951618 GoogleNearbySample[5727:1608902] Report RPC request: 0 token(s), 0 beacon(s), 0 directive(s)
2017-02-17 22:33:47.174414 GoogleNearbySample[5727:1608902] Report RPC response: Success
2017-02-17 22:33:47.174676 GoogleNearbySample[5727:1608902] Report RPC response: 0 directive(s), 0 token(s), 0 message(s), 0 publication results(s), 0 subscription results(s)
安卓部分:
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private static final int MY_PERMISSIONS_REQUEST_READ_CONTACTS = 12341;
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View view = findViewById(R.id.button);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PublishOptions publishOptions = new PublishOptions.Builder().setStrategy(new Strategy.Builder().setDiscoveryMode(Strategy.DISCOVERY_MODE_SCAN)
.setDistanceType(Strategy.DISTANCE_TYPE_EARSHOT).build()).build();
Nearby.Messages.publish(mGoogleApiClient, new Message("Hello Artur".getBytes()), publishOptions).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
Log.i("Nearby", status.getStatusMessage());
}
});
}
});
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Nearby.MESSAGES_API)
.addConnectionCallbacks(this)
.enableAutoManage(this, this)
.build();
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.RECORD_AUDIO},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
}
}
@Override
public void onConnected(@Nullable Bundle bundle) {
SubscribeOptions subscribeOptions = new SubscribeOptions.Builder()
.setStrategy(new Strategy.Builder().setDiscoveryMode(Strategy.DISCOVERY_MODE_SCAN)
.setDistanceType(Strategy.DISTANCE_TYPE_EARSHOT).build()).build();
Nearby.Messages.subscribe(mGoogleApiClient, new MessageListener() {
@Override
public void onFound(Message message) {
super.onFound(message);
Log.i("Nearby", "Subscribed found.");
Toast.makeText(getApplicationContext(), new String(message.getContent()), Toast.LENGTH_LONG).show();
}
}, subscribeOptions).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i("Nearby", "Subscribed successfully.");
} else {
Log.i("Nearby", "Could not subscribe.");
// Check whether consent was given;
// if not, prompt the user for consent.
handleUnsuccessfulNearbyResult(status);
}
}
});
}
private void handleUnsuccessfulNearbyResult(Status status) {
Log.i("Nearby", "Processing error, status = " + status);
}
@Override
public void onConnectionSuspended(int i) {
Log.d("onConnectionSuspended", String.valueOf(i));
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.d("onConnectionFailed", connectionResult.getErrorMessage());
}
}
Android 日志:
02-17 22:32:56.158 11325-11325/? I/Nearby: Subscribed successfully.
02-17 22:32:59.929 11325-11325/? D/NearbyMessagesClient: Emitting client lifecycle event ACTIVITY_STOPPED
02-17 22:32:59.930 11325-11325/? D/NearbyMessagesClient: Emitting client lifecycle event CLIENT_DISCONNECTED
02-17 22:33:28.890 11325-11325/? I/Nearby: Subscribed successfully.
02-17 22:33:45.867 11325-11325/? I/Nearby: SUCCESS
02-17 22:33:46.542 11325-11325/? I/Nearby: SUCCESS
02-17 22:33:47.137 11325-11325/? I/Nearby: SUCCESS
02-17 22:33:47.779 11325-11325/? I/Nearby: SUCCESS
02-17 22:33:48.422 11325-11325/? I/Nearby: SUCCESS
02-17 22:33:49.053 11325-11325/? I/Nearby: SUCCESS
02-17 22:34:18.477 11325-11325/? D/NearbyMessagesClient: Emitting client lifecycle event ACTIVITY_STOPPED
02-17 22:34:18.479 11325-11325/? D/NearbyMessagesClient: Emitting client lifecycle event CLIENT_DISCONNECTED
02-17 22:36:47.996 11325-11325/? D/NearbyMessagesClient: Failed to emit client lifecycle event ACTIVITY_STOPPED due to GmsClient being disconnected
02-17 22:36:47.997 11325-11325/? D/NearbyMessagesClient: Failed to emit client lifecycle event CLIENT_DISCONNECTED due to GmsClient being disconnected
最佳答案
Artur,您需要将发布对象存储在属性或ivar 中。只要发布对象存在,发布就处于 Activity 状态。要停止发布,请释放发布对象。订阅同上。
我在 Cocoapod documentation 中实现了 pub/sub 代码示例具有误导性。我会在下一个版本中修复它。
关于android - iOS 和 Android 之间的 Google Nearby 超声波消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42301076/
这里的这个问题对 updating Google Sheets charts linked to Google slides 有一个简洁的解决方案. function onOpen() { var
我正在尝试将 Google 表单添加到 Google 类作业中,但似乎不可能。 首先,它在这里 ( https://developers.google.com/classroom/reference/
出于某种原因,无论我做什么以及我如何尝试,这个日期格式化程序都不起作用。工具提示仍然显示错误的格式。你可以试试代码here . 在代码中我必须注释掉 formatter.format(dataTabl
我目前正在使用访问 token 和刷新 token 从 Google Analytics Reporting API (v4) 中提取数据。当我致力于自动从 Google Analytics 中提取数
我已在 Google 云端硬盘中创建了一个文件夹,例如测试一下,放入3个文件 a.jpg, b.jpg, c.jpg 我希望在同一帐户下的 Google 电子表格中访问文件,例如生成图像文件的链接,可
电子表格 A 是欢迎新移民来到我们小镇的团队的主数据源。它里面有大量非常敏感的数据,不能公开,哪怕是一点点。 (我们谈论的是 child 的姓名和出生日期以及他们在哪里上学……保证电子表格 A 的安全
有没有办法在 Google 文档中编写 Google Apps 脚本以从 Google 表格中检索仅限于非空白行的范围并将这些行显示为表格? 我正在寻找一个脚本,用于使用 Google Apps 脚本
有没有办法在 Google 文档中编写 Google Apps 脚本以从 Google 表格中检索仅限于非空白行的范围并将这些行显示为表格? 我正在寻找一个脚本,用于使用 Google Apps 脚本
尝试检索存储在 google firebase 中名为条目的节点下的表单条目,并使用谷歌工作表中的脚本编辑器附加到谷歌工作表。 我已将 FirebaseApp 库添加到谷歌表脚本编辑器。然后我的代码看
是否可以将我的 Web 应用程序的登录限制为仅限 google 组中的帐户? 我不希望每个人都可以使用他们的私有(private) gmail 登录,而只能使用我的 google 组中的用户。 最佳答
我们想使用 Google 自定义搜索实现 Google 附加链接搜索框。在谷歌 documentation , 我发现我们需要包含以下代码来启用附加链接搜索框 { "@context"
我想将特定搜索词的 Google 趋势图表添加到我的 Google Data Studio 报告中,但趋势不是数据源列表中的选项。我也找不到嵌入 JavaScript 的选项。是否可以将趋势图表添加到
是否可以将文件从 Google Drive 复制到 Google Cloud Storage?我想它会非常快,因为两者都在类似的存储系统上。 我还没有看到有关无缝执行此操作的任何方法的任何信息,而无需
之间有什么区别 ga('send', 'pageview', { 'dimension1': 'data goes here' }); 和 ga('set', 'dimension1', 'da
我正在尝试记录每个博客站点作者的点击率。 ga('send', 'pageview'); (in the header with the ga code to track each page) ga(
我设置了 Google Tag Manager 和 2 个数据层变量:一个用于跟踪用户 ID,传递给 Google Analytics 以同步用户 session ,另一个用于跟踪访问者类型。 在使用
我在我们的网站上遇到多个职位发布的问题。 我们在加拿大多个地点提供工作机会。所有职位页面都包含一个“LD+JSON ”职位发布的结构化数据,基于 Google 的职位发布文档: https://dev
公司未使用 Google 套件,使用个人(消费者)帐户(甚至是 Google 帐户)违反公司政策。 需要访问 Google Analytics - 没有 Google 帐户是否可能? 谢谢 最佳答案
我想分析人们使用哪些搜索关键字在 Play 商店中找到我的应用。 那可能吗?我怎么能这样做? 最佳答案 自 2013 年 10 月起,您可以关联您的 Google Analytics(分析)和 Goo
Google Now 和 Google Keep 中基于时间和位置的提醒与 Google Calendar 事件提醒不同。是否有公共(public) API 可以访问 Now 和 Keep 中的这些事
我是一名优秀的程序员,十分优秀!