Android教程第1部分使用带有kotlin的java websocket

本教程将指导你如何在Android应用中结合Kotlin使用Java-WebSocket库,从Coinbase Pro获取实时比特币价格。首先介绍先决条件,包括对Kotlin和Android开发的熟悉。接着,通过创建新项目、添加Gradle依赖以及连接到Coinbase Pro Websocket Feed,逐步展示如何获取和显示实时价格。此外,还涉及了数据模型的创建和布局设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In this tutorial, I will show how to use Java-Websocket Library together with Kotlin. It will be a simple app. The app opens a connection to the Coinbase Pro Websocket Feed by using Java-Websocket. When the connection is open the app will get the realtime Bitcoin price in Euro from Coinbase Pro. This is a step by step tutorial.

在本教程中,我将展示如何与Kotlin一起使用Java-Websocket库。 这将是一个简单的应用程序。 该应用程序使用Java-Websocket打开与Coinbase Pro Websocket Feed的连接。 打开连接后,应用程序将从Coinbase Pro获取欧元的实时比特币价格。 这是一个循序渐进的教程。

先决条件 (Prerequisites)

You should already be familiar with Kotlin and Android development. I am using Android Studio 4.0.1. You should also know that a connection to a web socket is bidirectional. Once the connection is open the communication can happen to both sides from server to client or client to server. In case you are more interested in the differences between HTTP and web sockets, I recommend watching this YouTube video.

您应该已经熟悉KotlinAndroid开发。 我正在使用Android Studio 4.0.1。 您还应该知道与Web套接字的连接是双向的。 连接打开后,服务器与客户端之间或客户端与服务器之间的通信就会发生。 如果您对HTTP和网络套接字之间的差异更感兴趣,建议您观看此YouTube视频

为什么写这篇文章? (Why this article?)

I recently had a coding challenge for a company where I had to use web sockets to get realtime stock prices. Because of the outdated resources and hard to use libraries. I thought there is a simple tutorial needed so every Android developer can easily use web sockets in 2020.

最近,对于一家不得不使用Web套接字获取实时股价的公司,我遇到了编码挑战。 由于资源过时且难以使用的库。 我认为需要一个简单的教程,以便每个Android开发人员都可以在2020年轻松使用Web套接字。

该应用程序将是什么样 (What the app will look like)

The app will only contain a TextView on the main screen which shows the current Bitcoin price on Coinbase Pro in Euro.

该应用程序将仅在主屏幕上包含一个TextView,该文本视图显示欧元在Coinbase Pro上的当前比特币价格。

Image for post
finished app in portrait mode
以纵向模式完成的应用
Image for post
finished app in landscape mode
在横向模式下完成的应用

开始新项目(Start new project)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值