小编Ren*_*ith的帖子

使用 Retrofit 从服务器读取纯文本响应

我正在开发一个使用 Retrofit 进行网络操作的应用程序。就目前而言,一切都可以很好地GsonConverterFactory处理序列化。这是我如何设置Retrofit

Retrofit.Builder()
        .baseUrl("<base url>") 
        .client(client)
        .addConverterFactory(GsonConverterFactory.create(gson))
        .build()
Run Code Online (Sandbox Code Playgroud)

现在我需要连接到以text/plain; charset=utf-8格式返回内容的旧服务。这是改造界面

@GET("https://<domain>/<endpoint>?Type=Query")
suspend fun callStatus(@Query("userId") id: Int): Response<String>
Run Code Online (Sandbox Code Playgroud)

这将为有效用户返回呼叫状态。例如,如果用户有效并且有状态,它会以纯文本形式返回“Active”。如果没有有效用户,则返回错误代码#1005

我可以像这样添加自定义转换器工厂(在网上找到)

final class StringConverterFactory implements Converter.Factory {
    private StringConverterFactory() {}

    public static StringConverterFactory create() {
        return new StringConverterFactory();
    }

    @Override
    public Converter<String> get(Type type) {
        Class<?> cls = (Class<?>) type;
        if (String.class.isAssignableFrom(cls)) {
            return new StringConverter();
        }
        return null;
    }

    private static class StringConverter implements Converter<String> {
        private static final MediaType PLAIN_TEXT = MediaType.parse("text/plain; charset=UTF-8");

        @Override …
Run Code Online (Sandbox Code Playgroud)

android kotlin retrofit okhttp retrofit2

4
推荐指数
3
解决办法
2065
查看次数

无法在WebView中打开PDF文档

我正在使用WebView打开一个实际上是pdf文档的URL.这是代码片段.

WebView webView = (WebView) context.findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.loadUrl("http://www.stagecoachbus.com/PdfUploads/Timetable_28768_5.pdf");
Run Code Online (Sandbox Code Playgroud)

并且获得的错误是:

EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up
Run Code Online (Sandbox Code Playgroud)

我能够打开正常的网页.但是,打开pdf文件会导致异常.

有什么想法吗?

提前致谢!

android android-layout android-webview

3
推荐指数
1
解决办法
8027
查看次数

任何可用于office/pdf文档的Java API

我在我的应用程序(android)中操作以下文件.

  1. Microsoft office文件(doc,docx,xl​​s,xlsx,ppt和pptx)
  2. PDF文件和
  3. XPS文件

我需要这些类型文件的页码.我可以找到MS-Excel文件的jexcel API和PDF的iText.

你能否为上述文件格式推荐Java API?

提前致谢!

java android java-api

1
推荐指数
1
解决办法
2274
查看次数

如何将私有签名信息转换为 Kotlin DSL?

我正在迁移到 Kotlin DSL。我已经关注了大多数流行的博客来进行最初的设置。现在是时候重构build.gradle文件了。我有私人签名信息逻辑,如下所示。

if (project.hasProperty('propertyfile') && project.hasProperty('key.store')) {

  def keystorePropertiesFile = rootProject.file(project.getProperty('propertyfile'))
  def keystoreProperties = new Properties()
  keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

  signingConfigs {
    release {
        keyAlias keystoreProperties['key.alias']
        keyPassword keystoreProperties['key.alias.password']
        storeFile file(project.getProperty('key.store'))
        storePassword keystoreProperties['key.store.password']
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我不确定如何将这部分转换为与 Kotlin DSL 等效的部分。浏览了有关该主题的相关帖子和博客,但找不到任何相关内容。有人可以帮我分享一些关于如何做到这一点的想法吗?

android build.gradle android-gradle-plugin gradle-kotlin-dsl

1
推荐指数
1
解决办法
5388
查看次数

在HTTP POST中设置参数

我正在尝试使用HttpClient API对服务器进行JSON调用.代码sinppet如下所示.

HttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpPost(URLString);
HttpResponse response = httpClient.execute(httpPost);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  
nameValuePairs.add(new BasicNameValuePair("method", "completeUserLogin")); 
String[] params = new String[]{"100408"};
response = httpClient.execute(httpPost);
Run Code Online (Sandbox Code Playgroud)

我想将params添加到nameValuePairs.BasicNameValuePair类不允许您添加数组.有什么想法吗?

提前致谢!

java android http

0
推荐指数
1
解决办法
8174
查看次数