简体   繁体   中英

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.

I have checked that this is possible and I have found and installed an APK that manages to make the link. 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. 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.

Being a novice in Android development, the task of managing the BLE is very complex for me. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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