gpt4 book ai didi

java - 如何修复 Android 中的 'Install failed. Installation failed Rerun' 错误?

转载 作者:行者123 更新时间:2023-12-02 02:40:01 24 4
gpt4 key购买 nike

我正在尝试通过 UART 电缆将设备(血氧计)连接到 Android 智能手机。所以我需要构建一个能够从此设备读取数据的应用程序。为此,我使用 Android Things,但我无法运行此应用程序,因为我收到此错误:“安装失败。安装失败重新运行”

很确定这个标签“uses-library android:name="com.google.android.things"android:required="true"”给我带来了这个错误,没有它它会运行但崩溃。

主要 Activity :

public class MainActivity extends Activity {

String TAG = "Log";

private static final String UART_DEVICE_NAME = null;

private UartDevice mDevice;

private TextView tv;
private List<String> serial;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

tv = findViewById(R.id.serial);
serial = new ArrayList<>();

PeripheralManager manager = PeripheralManager.getInstance();
List<String> deviceList = manager.getUartDeviceList();
if (deviceList.isEmpty()) {
Log.i(TAG, "No UART port available on this device.");
} else {
Log.i(TAG, "List of available devices: " + deviceList);
}

// Attempt to access the UART device
try {
mDevice = manager.openUartDevice(deviceList.get(0));
} catch (IOException e) {
Log.w(TAG, "Unable to access UART device", e);
}
try {
setFlowControlEnabled(mDevice, false);
} catch (IOException e) {
e.printStackTrace();
}
try {
configureUartFrame(mDevice);
} catch (IOException e) {
e.printStackTrace();
}
try {
writeUartData(mDevice);
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
protected void onDestroy() {
super.onDestroy();

if (mDevice != null) {
try {
mDevice.close();
mDevice = null;
} catch (IOException e) {
Log.w(TAG, "Unable to close UART device", e);
}
}
}

public void configureUartFrame(UartDevice uart) throws IOException {
// Configure the UART port
uart.setBaudrate(57600);
uart.setDataSize(8);
uart.setParity(UartDevice.PARITY_NONE);
uart.setStopBits(1);
}

public void setFlowControlEnabled(UartDevice uart, boolean enable) throws
IOException {
uart.setHardwareFlowControl(UartDevice.HW_FLOW_CONTROL_NONE);
}

public void writeUartData(UartDevice uart) throws IOException {
byte[] raw = new byte[]{(byte) 0xA5, (byte) 0x10, (byte) 0x02, (byte)
0x1A, (byte) 0x00, (byte) 0x00};
byte cs = (byte) ((raw[1] ^ raw[2] ^ raw[3] ^ raw[4]) & 0xFF);
raw[5] = cs;
int count = uart.write(raw, raw.length);
Log.d(TAG, "Wrote " + count + " bytes to peripheral");
readUartBuffer(uart);
}

public void readUartBuffer(UartDevice uart) throws IOException {
// Maximum amount of data to read at one time
final int maxCount = 9600;
byte[] buffer = new byte[maxCount];

int count;
while ((count = uart.read(buffer, buffer.length)) > 0) {
Log.d(TAG, "Read " + count + " bytes from peripheral");
serial.add(String.valueOf(buffer[count]) + " ");
}
StringBuilder data = new StringBuilder();
for (int i = 0; i < serial.size(); i++) {
data.append(serial.get(i));
}
tv.setText(data);
}
}

AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.oximetro">

<uses-permission
android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<uses-library android:name="com.google.android.things"
android:required="true"/>
</application>

</manifest>

构建.Gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.example.oximetro"
minSdkVersion 27
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-
optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.things:androidthings:+'
}

我感谢任何帮助,甚至是完成我正在尝试做的事情的替代方案,即使用 Android 智能手机通过 UART 从血氧计读取数据。运行此代码我收到上述错误,因此该应用程序甚至无法在设备上打开。

最佳答案

您无法在手机上运行 Android Things 库。您的手机没有用于进行硬件连接的库 Hook 。手机知道它不具备运行应用程序所需的一切,因此应该拒绝安装。

关于java - 如何修复 Android 中的 'Install failed. Installation failed <a href=' rerun '>Rerun</a>' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57184530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com