我一直在尝试发送HttpPost请求并检索响应,但即使我能够建立连接,我还没有得到如何获取请求 - 响应返回的字符串消息
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.myurl.com/app/page.php");
// Add your data
List < NameValuePair > nameValuePairs = new ArrayList < NameValuePair > (5);
nameValuePairs.add(new BasicNameValuePair("type", "20"));
nameValuePairs.add(new BasicNameValuePair("mob", "919895865899"));
nameValuePairs.add(new BasicNameValuePair("pack", "0"));
nameValuePairs.add(new BasicNameValuePair("exchk", "1"));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.d("myapp", "works till here. 2");
try {
HttpResponse response = httpclient.execute(httppost);
Log.d("myapp", "response " + response.getEntity());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace(); …
Run Code Online (Sandbox Code Playgroud) 我在当前项目中添加了Google Play服务作为依赖项.如果我将项目保存在C:驱动器上,则在同步项目时会出现以下错误:
Error: Execution failed for task ':app:mergeDebugResources'.
> Error: Failed to run command:
C:\Program Files (x86)\Android\android-studio\sdk\build-tools\android-4.4.2\aapt.exe s -i C:\Users\ashokp\Desktop\Studio\AndroidV2SDK_AndroidStudioFormat\Google Play
Services\SampleApplication\AndroidV2SDKSampleApp_GooglePlayServices\app\build\exploded-aar\com.google.android.gms\play-services\4.3.23\res\drawable-hdpi\common_signin_btn_text_focus_light.9.png -o
C:\Users\ashokp\Desktop\Studio\AndroidV2SDK_AndroidStudioFormat\Google Play
Services\SampleApplication\AndroidV2SDKSampleApp_GooglePlayServices\app\build\res\all\debug\drawable-hdpi\common_signin_btn_text_focus_light.9.png
Error Code:
42
Run Code Online (Sandbox Code Playgroud)
仅当项目保存在C:驱动器上时才会发生这种情况.如果我将它保存到其他驱动器,它可以正常工作.
还有其他人面临这个问题吗?是什么导致这个?我该如何解决/规避这个问题?
我正在尝试使用css更改JavaFx选项卡的默认外观.
我设法实现了以下目标.
我正在寻找的是第一个标签上不应该留下空白.
有人可以指出我如何实现它的正确方向.
以下是我想要实现的输出.
我使用了以下CSS
.tab-pane .tab-header-area .tab-header-background {
-fx-opacity: 0;
}
.tab-pane
{
-fx-tab-min-width:90px;
}
.tab{
-fx-background-insets: 0 1 0 1,0,0;
}
.tab-pane .tab
{
-fx-background-color: #e6e6e6;
}
.tab-pane .tab:selected
{
-fx-background-color: #3c3c3c;
}
.tab .tab-label {
-fx-alignment: CENTER;
-fx-text-fill: #828282;
-fx-font-size: 12px;
-fx-font-weight: bold;
}
.tab:selected .tab-label {
-fx-alignment: CENTER;
-fx-text-fill: #96b946;
}
Run Code Online (Sandbox Code Playgroud) 我可以看到Android文档中有两种不同的方法来发布数据并添加标题.
For setting Headers
public void loadUrl (String url, Map<String, String> additionalHttpHeaders)
For setting Post Data
public void postUrl (String url, byte[] postData)
Run Code Online (Sandbox Code Playgroud)
但我真正需要的是将数据与标题一起发布.(意味着我想要一个同时完成任务的单一方法?)
有人可以帮我解决这个问题.
谢谢 :)
我的应用程序中有一个用于登录身份验证的警告对话框.在发送请求时,我想显示一个进度条,如果响应是成功则想要解雇.如果有人知道,请帮助我.我使用下面的代码:
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
LinearLayout login = new LinearLayout(this);
TextView tvUserName = new TextView(this);
TextView tvPassword = new TextView(this);
TextView tvURL = new TextView(this);
final EditText etUserName = new EditText(this);
final EditText etPassword = new EditText(this);
final EditText etURL = new EditText(this);
login.setOrientation(1); // 1 is for vertical orientation
tvUserName.setText(getResources().getString(R.string.username));
tvPassword.setText(getResources().getString(R.string.password));
tvURL.setText("SiteURL");
login.addView(tvURL);
login.addView(etURL);
login.addView(tvUserName);
login.addView(etUserName);
login.addView(tvPassword);
etPassword.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
login.addView(etPassword);
alert.setView(login);
alert.setTitle(getResources().getString(R.string.login));
alert.setCancelable(true);
alert.setPositiveButton(getResources().getString(R.string.login),
new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog,
int whichButton) {
strhwdXml …
Run Code Online (Sandbox Code Playgroud) 我通过自定义适配器设置的每个ListView项目中都有一个TextView.TextView XML不在写入ListView XML的同一文件中,我希望当选择任何ListView项时,该特定项的字体颜色应该更改.我也通过定义TextView的不同状态来尝试这一点,即选择,聚焦和按下,但这不能解决我的问题.请为我推荐一些解决方案.这是片段..
一个xml文件中的一个监听视图,例如.file1.xml
<ListView
android:id="@+id/listView1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:clickable="true" />
Run Code Online (Sandbox Code Playgroud)
和一个TextView在不同的xml ..即file2.xml
<TextView
android:id="@+id/rowListTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:text="@string/app_name"
android:textColor="@color/file3"
android:textSize="10sp"
android:textStyle="bold" />
Run Code Online (Sandbox Code Playgroud)
res/color文件夹中的文本颜色属性文件,即file3.xml.
<item android:state_selected="true" android:color="@android:color/white"/>
<item android:state_focused="true" android:color="@android:color/white"/>
<item android:state_pressed="true" android:color="@android:color/white"/>
<item android:color="@android:color/black"/>
Run Code Online (Sandbox Code Playgroud)
我在Java包中跟随了Enum类
public enum UIType {
NATIVE,WEB;
}
Run Code Online (Sandbox Code Playgroud)
我已经应用了以下proguard配置来保持这个枚举类
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public enum android.ui.UIType {
public static **[] values();
public static ** valueOf(java.lang.String);
}
Run Code Online (Sandbox Code Playgroud)
但是当我取消我的jar文件时,proguard保留了UIType枚举类,但同时删除了NATIVE,WEB值.
在我混淆的jar中,我的Enum类看起来如下.
public enum UIType {
}
Run Code Online (Sandbox Code Playgroud)
如上所示NATIVE,WEB值被proguard删除:(.它在我的应用程序中引起问题,因为它没有找到这些值.
有人可以在这里指导我做错了什么.
谢谢
我已经编写了用于录制音频文件的代码,AudioRecord
并且在SD卡上写入文件时,我正在制作两个版本.
版本1 录制的文件原样保存在SD卡上.
版本2 我在录制文件上应用增益功能并保存在SD卡上.
这在索尼爱立信手机上非常棒.同时音量也在很大程度上得到提升.
但我正在努力使其适用于三星设备.
当我播放录制的文件时,它听起来像会说话的汤姆:P
最初我认为Samusung设备不喜欢我曾经创建的组合
AudioRecorder
.
所以我使用以下方法,其中我循环到可用配置并使用最佳配置来初始化AudioRecord.
public AudioRecord findAudioRecord() {
for (int rate: mSampleRates) {
for (short audioFormat: new short[] {
AudioFormat.ENCODING_PCM_8BIT, AudioFormat.ENCODING_PCM_16BIT
}) {
for (short channelConfig: new short[] {
AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO
}) {
try {
Log.i("vipul", "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: " + channelConfig);
int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
// check if we can instantiate …
Run Code Online (Sandbox Code Playgroud) 我正在尝试Google Play Services
为Android 找到更改日志.当我尝试使用最新Google Play Service SDK
的我的库项目我的应用程序崩溃,因为它符合早期版本的Google Play服务SDK.New SDK不包含某些可用的方法在以前的版本中.
我真的很感激如果有人能指出我的Google Play服务更新日志.
谢谢.
我想要实现的是通过将令牌设置为cookie来自动登录到https网站.
(它适用于Android Chrome浏览器,但不适用于应用程序webview)
基本上我在使用cookie设置将https url加载到web视图时面临两个问题
问题1
我收到了以下日志消息.
无法验证证书链,错误:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚.
我尝试重写onReceivedSslError
并调用handler.proceed();
如下.
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
Log.d(TAG, "==> " + error.toString());
handler.proceed();
}
Run Code Online (Sandbox Code Playgroud)
但我仍然看到白页(由于证书问题,我假设它正在发生.)
问题2
我有一个登录URL(例如https://www.abc.com/login.html)
我想要实现的是通过设置cookie自动登录到Web视图.
CookieSyncManager.createInstance(webView.getContext());
CookieManager cookieManager = CookieManager.getInstance();
CookieManager.getInstance().setAcceptCookie(true);
String token = PreferenceHelper.loadTokenFromPreference(this);
String sessionCookie = "staging=" + token;
cookieManager.setCookie("https://www.abc.com/aaa/",
sessionCookie);
CookieSyncManager.getInstance().sync();
SystemClock.sleep(1000);
Run Code Online (Sandbox Code Playgroud)
但我仍然无法自动登录.我看到了白页.
我现在不确定的是我犯错误的地方.
cookieManager.setCookie
需要第一个参数作为cookie需要设置的URL,我不确定我需要给哪个URL?
任何人都可以建议我正确的方法让它工作?
谢谢