我试图通过WiFi从Android设备访问本地Web服务器,我可以通过浏览器从我的笔记本电脑访问,或使用curl.我也可以在Android设备浏览器上访问服务器.
我用来访问服务器的代码产生"连接被拒绝"异常.
这是代码:
public void getController1() {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://192.168.1.169:8000");
HttpResponse response = null;
System.out.println(httpget.toString());
try {
response= httpclient.execute(httpget);
txtViewStatus.setText("Controller 1 - OK"+response);
} catch(Exception e) {
e.printStackTrace();
txtViewStatus.setText("Controller 1 - Error"+e);
}
}
Run Code Online (Sandbox Code Playgroud) 我的Android应用程序使用的Web服务只能从办公室网络访问.我想在家调试.我可以通过MAC上的ssh或Windows中的putty将VPN连接到我的办公室网络.Android模拟器是否会"自动"访问VPN下的办公网络,还是需要特定的设置?
我已经测试的软件,我移植到2.3在Android 2.3模拟器,该应用程序包括在WebView中显示希伯来语串需要解决三个问题:
告诉webview从右到左显示字符串,我通过添加解决了这个问题
<p dir="rtl">
Run Code Online (Sandbox Code Playgroud)最后一个问题是,网页视图反映了文字:换句话说,应该是右边的第一个字是左边的最后一个字,也即单词的字母翻转,这应该是右边的第一个字母是左边的第一个字母.
顺便说一下,如果在TextView中,2.3 emactor正确显示字符串.
关于如何修复#3的任何想法?
我的选项卡式应用不会通过方向更改重新显示视图.
我补充道
android:configChanges="keyboardHidden|orientation"
Run Code Online (Sandbox Code Playgroud)
到主标签活动和清单中的每个活动.
我在每个活动中添加了这个方法:
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.active_alt);
mColorLegendBtn = (Button) findViewById(R.id.colorbtn);
mStatusView = (TextView) findViewById(R.id.celltitle1);
TextView mStatusView1 = (TextView) findViewById(R.id.celltitle2);
mStatusView1.setText(mStatusView1.getText()+"testcase1");
mStatusView.setText(mStatusView.getText()+"testcase");
initUI();
}
public void initUI() {
l1 = (ListView) findViewById(R.id.ListView01);
EfficientAdapter efficientAdapter = new EfficientAdapter(mContext);
l1.setAdapter(null);
l1.setAdapter(efficientAdapter);
}
Run Code Online (Sandbox Code Playgroud)
启动时,正确显示选项卡,列表,按钮和文本视图.当我在模拟器中更改方向时,只显示选项卡,而不显示其他任何小部件,屏幕为黑色.
我错过了什么?
我在Android AsyncTak中设置了progressdialog并且它可以工作.
我的问题是可以在AsyncTask的onProgressUpdate方法中更新ProgressDialog显示的字符串.我想用publishProgress调用更新字符串以显示任务的进度.
我可以更新字符串if而不是progressDialog我有自己的textview.progressDialog看起来更好,并有旋转轮.
我的Android应用程序有一个嵌入视频和音频的WebView.当应用在Android 2.3.x上运行时,视频流和音频播放.
我修改了应用程序以在三星Tab 10.1平板电脑上运行HoneyComb(3.1),视频不流式传输,音频无法播放.在Tab浏览器中输入URL时的视频流.
这是java代码:
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient());
mWebView.getSettings().setAllowFileAccess(true)
mFileName = fileName_items[item_position];
mFullPath = "file:///android_asset/"+mFileName+".html";
mWebView.loadUrl(mFullPath);
Run Code Online (Sandbox Code Playgroud)
在HTML中,我尝试了embed标记和视频标记.嵌入标签不显示任何内容,而视频标签显示控件,我可以切换播放/暂停,但不显示视频.
<video controls="controls" style="align:center;" height="300" width="300">
<source src="http://www.at.com/videos/an1.mp4" type="video/mp4">
</video>
<embed type="video/mp4" src="http://www.at.com/videos/an1.mp4" width="340" height="140" />
Run Code Online (Sandbox Code Playgroud) 一个Python Web服务器开始于
python -m SimpleHTTPServer
将在控制台上打印已接受的请求.我可以让它打印返回连接拒绝客户端的请求吗?
我试图调试为什么它拒绝来自Android客户端的一些请求.
我的Android应用程序中的一个活动具有两个图像视图的相对布局,这两个图像视图在xml布局文件中设置.如何以编程方式获取imageviews的x,y位置
这些坐标会根据屏幕尺寸和密度而有所不同吗?
我想要做的是让用户触摸image1,然后将其动画化以移动到image2的位置.
显然,由于我将这些图像放在xml中,我知道它们的x,y坐标,但我担心这些坐标会根据屏幕尺寸和密度而变化.
我试图改组一个数组,但我得到一个"没有可见的@interface for'NSArray'在最后一个语句中声明选择器'exchangeObjectAtIndex:withObjectAtIndex:'.
如何宣布bArray?
NSArray *bArray;
Run Code Online (Sandbox Code Playgroud)
并在
- (void)viewDidLoad
[self shuffleb];
Run Code Online (Sandbox Code Playgroud)
然后
-(void) shufflb
{
bArray = [NSArray arrayWithObjects:
@"ca",
@"do",
@"ba",
@"tr",
@"bu",
@"bl",
@"bo",
@"pu",
nil];
NSInteger count = [bArray count];
for (NSUInteger i = 0; i < count; ++i) {
// Select a random element between i and end of array to swap with.
NSInteger nElements = count - i;
n = (arc4random() % nElements) + i;
[bArray exchangeObjectAtIndex:i withObjectAtIndex:n];
}
Run Code Online (Sandbox Code Playgroud) 在一个arrays.xml文件中,在res文件夹中,定义了几个数组:
<string-array name="all">
<item> a1 </item>
<item> a2 </item>
</string-array>
<string-array name="a1">
<item> x </item>
<item> y </item>
</string-array>
<string-array name="a2">
<item> z </item>
<item> t </item>
</string-array>
Run Code Online (Sandbox Code Playgroud)
我想将"all"数组和序列读入依赖于"all"中的选择的a1或a2数组,而不必构建switch/case语句(真正的数组更复杂).代码看起来像这样,但Java/Android抱怨第二行.它希望R.array像R.array.a1或R.array.a2一样是常数而不是变量.
是否可以执行以下操作(第2行),
String[] temp_items = getResources().getStringArray(R.array.all1);
String[] items = getResources().getStringArray(R.array.temp_items[0]);
Run Code Online (Sandbox Code Playgroud)
我也可以通过将数组放在java中的实用程序类中并绕过arrays.xml文件来解决这个问题.
这可能吗?a1 a2
<string-array name="a1">
<item> x </item>
<item> y </item>
</string-array>
<string-array name="a2">
<item> z </item>
<item> t </item>
</string-array>
Run Code Online (Sandbox Code Playgroud) 我的应用程序有多个视图以编程方式添加按钮,而不是在每个控制器中使用以下实例方法,我想将该方法放在一个公共类中,将其用作类方法.
+ (void) addLeftImageButton:(UIButton *)leftButton:(float)x:(float)y:(NSString *)name:(int) tag
{
leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[leftButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[leftButton setTag: tag];
[leftButton setBackgroundImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
leftButton.frame = CGRectMake(x, y, 345.0, 345.0);
[self.view addSubview:leftButton];
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何引用self.view调用视图.如self.view没有在普通类公知的.