简体   繁体   English

API 19 和蓝牙低功耗

[英]API 19 and Bluetooth Low Energy

I am currently working on a project to connect a Google Glass Explorer Edition (Android Kitkat and therefore API 19) to an Arduino board emitting data in BLE.我目前正在开展一个项目,将 Google Glass Explorer Edition(Android Kitkat 和 API 19)连接到 Arduino 板,在 BLE 中发射数据。

I have checked that this is possible and I have found and installed an APK that manages to make the link.我已经检查过这是可能的,并且我已经找到并安装了一个可以建立链接的 APK。 However, I want to make a slightly different application.但是,我想做一个稍微不同的应用程序。

The application I want to make has a splash screen and a main activity displaying the different values on TextView.我要制作的应用程序有一个启动屏幕和一个在 TextView 上显示不同值的主要活动。 This part is already working.这部分已经开始工作了。

Splash Screen:启动画面:

package com.example.flyin_glass;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;

public class SplashScreenActivity extends AppCompatActivity {
/* JADX INFO: Access modifiers changed from: protected */
@Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);
    Runnable runnable = new Runnable() { // from class: com.example.myapplication.SplashScreenActivity.1
        @Override // java.lang.Runnable
        public void run() {
            Intent intent = new Intent(SplashScreenActivity.this.getApplicationContext(), MainActivity.class);
            SplashScreenActivity.this.startActivity(intent);
            SplashScreenActivity.this.finish();
        }
    };
    new Handler().postDelayed(runnable, 3000L);
}
}

Main activity :主要活动 :

package com.example.flyin_glass;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.*;
import android.bluetooth.le.*;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.content.Context;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity
{


@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

}

My goal would be to code (in main activity) the management of the BLE, ie the automatic connection to my Arduino (which has a specific UUID) as well as the data retrieval and display in TextView.我的目标是编码(在主要活动中)BLE 的管理,即自动连接到我的 Arduino(具有特定的 UUID)以及数据检索和 TextView 中的显示。

Being a novice in Android development, the task of managing the BLE is very complex for me.作为 Android 开发的新手,管理 BLE 的任务对我来说非常复杂。 Do you have any advice?你有什么建议吗?

Thank you in advance.先感谢您。

Guillaume纪尧姆

As Michael Kotzjan mentioned, there are many Android BLE tutorials which can you help you with this task.正如 Michael Kotzjan 所提到的,有许多 Android BLE 教程可以帮助您完成这项任务。 Below are some of my faviourites:-以下是我最喜欢的一些:-

However, your main issue is that you are using API 19, which is a very dated Android API (I believe BLE functionality was introduced in API 18) and the BLE API has changed since then.但是,您的主要问题是您使用的是 API 19,这是一个非常过时的 Android API(我相信 BLE 功能是在 API 18 中引入的),此后 BLE API 发生了变化。 As such I would see the link below on recommendation on how to overcome this issue and also keep a lookout for the API discrepencies throughout your development.因此,我会看到下面有关如何克服此问题的建议的链接,并在整个开发过程中留意 API 差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM