我一直在开发基于浏览器的多人游戏一段时间,我一直在各种环境(客户办公室,公共wifi等)测试不同的端口可访问性.一切都很顺利,除了一件事:我无法弄清楚如何读取错误号.或收到onerror事件时的描述.
客户端websocket是在javascript中完成的.
例如:
// Init of websocket
websocket = new WebSocket(wsUri);
websocket.onerror = OnSocketError;
...etc...
// Handler for onerror:
function OnSocketError(ev)
{
output("Socket error: " + ev.data);
}
Run Code Online (Sandbox Code Playgroud)
'output'只是一些写入div的实用函数.
我得到的是ev.data的'undefined'.总是.我一直在谷歌搜索,但似乎没有关于这个事件有什么参数以及如何正确阅读它的规范.
任何帮助表示赞赏!
我正在使用RemoteViews
自定义创建通知,该自定义Service
以前台模式运行通知(即,只要用户可以看到通知,服务就会保持活动状态).通知设置为正在进行,因此用户无法将其滑动.
我想更改示例中显示的位图ImageView
,包含在远程视图的布局中或更改文本值TextView
.远程视图中的布局使用XML布局文件设置.
我的问题是,一旦通知被创建并且对用户可见,如果我调用任何RemoteViews
类似于setImageViewResource()
更改中Bitmap
显示的任何功能ImageView
,则更改是不可见的,除非我setImageViewResource()
之后打电话给我打电话:
NotificationManager.notify( id, notification );
Run Code Online (Sandbox Code Playgroud)
要么
Service.startForeground(id,notification);
Run Code Online (Sandbox Code Playgroud)
这对我来说听起来不对.我无法相信要RemoteViews
在已创建的通知中更新UI,我必须重新初始化通知.如果我对Button
通知有控制权,它会在触摸和释放时自行更新.所以必须有一种方法可以做到这一点,但我不知道如何.
这是我的代码,它在我的Service
实例中创建通知:
this.notiRemoteViews = new MyRemoteViews(this,this.getApplicationContext().getPackageName(),R.layout.activity_noti1);
Notification.Builder notibuilder = new Notification.Builder(this.getApplicationContext());
notibuilder.setContentTitle("Test");
notibuilder.setContentText("test");
notibuilder.setSmallIcon(R.drawable.icon2);
notibuilder.setOngoing(true);
this.manager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
this.noti = notibuilder.build();
this.noti.contentView = this.notiRemoteViews;
this.noti.bigContentView = this.notiRemoteViews;
this.startForeground(NOTIFICATION_ID, this.noti);
Run Code Online (Sandbox Code Playgroud)
并且"强制"UI更改为通知的功能:
public void updateNotiUI(){
this.startForeground(NOTIFICATION_ID, this.noti);
}
Run Code Online (Sandbox Code Playgroud)
在MyRemoteViews
课堂上,如果需要,我这样做是为了对UI进行更改:
this.setImageViewResource(R.id.iconOFF, R.drawable.icon_off2);
this.ptMyService.updateNotiUI();
Run Code Online (Sandbox Code Playgroud)
谁能告诉我更新RemoteViews
通知中UI组件的正确方法是什么?
我一直在研究如何使用创建自定义布局通知RemoteView
.
到目前为止,我能够创建一个通知,contentView
并bigContentView
指向RemoteView
一个自定义布局xml.但是,没有发生的事情是在创建它Activity
时启动(与自定义布局相关联)RemoteView
.
我已经双重检查并在我的布局xml中,它似乎有正确的Activity
类名:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context=".LLMNotificationActivity" >
..... the rest are standard layout items: images, buttons and text
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在清单文件中,在主应用程序主活动之后,还添加了通知活动:
<activity
android:name=".LLMNotificationActivity"
android:label="@string/app_name">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
我希望当通知RemoteView
用于其内容时,这RemoteView
将启动附加到其布局定义的活动.但似乎没有.
以下是我在主应用程序中创建通知的方法Activity
:
protected void startNoti() {
if( noti!=null ) return;
Context context = getApplicationContext();
RemoteViews contentView = new RemoteViews(context.getPackageName(),R.layout.activity_noti1);
Notification.Builder notibuilder = new Notification.Builder(context); …
Run Code Online (Sandbox Code Playgroud) 我在使用位置数据的应用程序上工作,它需要在中国工作.此处销售的Android设备基本上没有安装Google Play API,唯一的方法是根据手机安装它.所以我坚持使用LocationManager,它比LocationClient(Google Play API的一部分)更糟糕.
我的问题是,当从GPS_PROVIDER读取时,LocationManager经常无法连接到足够的卫星(在中国),并且修复之间偶尔会有很大的时间间隔.从NETWORK_PROVIDER读取时,我可以获得更频繁的修复,但准确度范围从30到500.在LocationClient API质量附近.
该应用程序应该经常监视您在街道上的移动,例如.每秒更新一次(电池使用率高,对我的客户来说不是问题)并在到达某些位置时执行某些操作.
如果我使用Google Play API和LocationClient,它确实运行良好.但这仅限于Nexus4或某些非中国Android设备.
我问是否有人知道一个库可以提供比直接使用LocationManager更好的结果,或者一个解决方案如何使用LocationManager来改善结果?
android geolocation locationmanager google-play-services location-client
我正在用 JS 构建一个 UI 库,它可以在不依赖任何 CSS 样式表的情况下创建 UI 组件,从代码中进行风格化。到目前为止,除了为不同的控件状态设置样式(例如 input:focus one)之外,这已经很容易了。
我用来创建输入字段的代码:
function newInput()
{
var ctr = docmuent.createElement("input");
ctr.setAttribute("type","text");
ctr.setAttribute("value", some-default-value);
ctr.style.fontFamily = "sans-serif,helvetica,verdana";
/* some font setup here, like color, bold etc... */
ctr.style.width = "256px";
ctr.style.height = "32px";
return ctr;
}
Run Code Online (Sandbox Code Playgroud)
为默认状态设置样式很容易。但是,我不确定如何为聚焦、禁用或不可编辑等状态设置样式。
如果我在项目中包含 CSS 样式表,那将很容易整理出来。但是我不能包含任何 CSS 文件,它必须是纯 JS。
有谁知道如何直接从 JS 代码中为输入字段状态(例如 input:focus)设置样式?
请不要使用 JQuery :-) 直接使用 JS。
提前致谢!
我想让我的应用程序监视器在手机锁定和解锁时,以及当它变为空白(经过较长时间不活动)后,这一切都在我的应用程序没有聚焦,但在后台运行时.
在应用专注时,我可以轻松收到锁定/解锁/空白事件:
-(void) startListeningForPhoneLockEvent
{
NSLog(@"Start listening to lock/unlock and screen-goes-black events.");
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
(void*)self,
lockStateChanged,
CFSTR("com.apple.springboard.lockstate"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
(void*)self,
hasBlankedScreen,
CFSTR("com.apple.springboard.hasBlankedScreen"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
}
Run Code Online (Sandbox Code Playgroud)
和回调函数:
static void lockStateChanged( CFNotificationCenterRef center, void*observer, CFStringRef name, const void *object, CFDictionaryRef userInfo )
{
NSLog(@"Lock event received!");
}
static void hasBlankedScreen( CFNotificationCenterRef center, void*observer, CFStringRef name, const void *object, CFDictionaryRef userInfo )
{
NSLog(@"Blanked screen event received!");
}
Run Code Online (Sandbox Code Playgroud)
我启用了后台模式:
但是,一旦应用程序进入后台,它就不会收到锁定/解锁/空白屏幕事件.
我尝试过其他背景模式,如声音播放,位置更新等,但应用程序仍然没有在后台接收锁定/解锁/空白屏幕事件.
我不确定这是否真的可行,或者我做错了什么.
我正在使用最新的XCode和iOS9 SDK在真实设备上测试它,该设备已更新到iOS9.
android ×3
javascript ×2
css ×1
events ×1
geolocation ×1
html5 ×1
ios ×1
java ×1
objective-c ×1
onfocus ×1
remoteview ×1
stylesheet ×1
websocket ×1