我正在使用蓝牙连接这个应用程序,我在手机上成功运行了这个应用程序几次,在MainActivity.java中做了一些更改,然后在手机上运行它。 Android Studio挂了,我强行关闭它。然后尝试通过Eclipse IDE运行另一个代码,它说它无法访问SDK(虽然它在我下载Android Studio之前工作得很好)。现在我尝试重新启动手机,杀死并重新启动ADB,重新启动PC,重启Android Studio但没有任何工作,并且logcat没有检测到任何可调试的应用程序。当我现在尝试运行应用程序时,它会安装在我的手机中,但是打开按钮是否已禁用?
MainActivity.java
package com.brr.uet.myapplication;
import com.google.devtools.simple.runtime.components.Component;
import com.google.devtools.simple.runtime.components.HandlesEventDispatching;
import com.google.devtools.simple.runtime.components.android.BluetoothClient;
import com.google.devtools.simple.runtime.components.android.Button;
import com.google.devtools.simple.runtime.components.android.CheckBox;
import com.google.devtools.simple.runtime.components.android.Clock;
import com.google.devtools.simple.runtime.components.android.Form;
import com.google.devtools.simple.runtime.components.android.HorizontalArrangement;
import com.google.devtools.simple.runtime.components.android.Label;
import com.google.devtools.simple.runtime.components.android.ListPicker;
import com.google.devtools.simple.runtime.components.android.TableArrangement;
import com.google.devtools.simple.runtime.components.util.YailList;
import com.google.devtools.simple.runtime.events.EventDispatcher;
public class MainActivity extends Form implements HandlesEventDispatching {
private ListPicker list_dev;
private Button up, down, left, right, stop, fast, medium, slow, deg0, deg90, deg180;
private Clock clock;
private BluetoothClient bt;
private Label status;
private CheckBox checkbox;
private HorizontalArrangement hz1, hz2, hz3, hz4;
private TableArrangement tb;
void $define() {
this.ScreenOrientation("portrait");
this.Title("Bluetooth Control");
this.BackgroundColor(COLOR_GRAY);
this.Scrollable(true);
hz1 = new HorizontalArrangement(this);
hz1.Visible(true);
status = new Label(this);
status.Text("Status: Not Connected");
status.BackgroundColor(COLOR_RED);
status.FontBold(true);
status.FontSize(20);
status.TextColor(COLOR_WHITE);
status.FontTypeface(TYPEFACE_DEFAULT);
status.TextAlignment(Component.ALIGNMENT_CENTER);
status.Height(Component.LENGTH_FILL_PARENT);
status.Width(Component.LENGTH_FILL_PARENT);
status.Visible(true);
list_dev = new ListPicker(hz1);
list_dev.Text("Connect to Robot");
list_dev.BackgroundColor(COLOR_BLUE);
list_dev.Enabled(true);
list_dev.FontSize(25);
list_dev.FontTypeface(TYPEFACE_DEFAULT);
list_dev.Height(Component.LENGTH_FILL_PARENT);
list_dev.Width(Component.LENGTH_FILL_PARENT);
list_dev.Visible(true);
hz2 = new HorizontalArrangement(this);
hz2.Visible(true);
checkbox = new CheckBox(hz2);
checkbox.Text("Enable Camera Rotation");
checkbox.Height(Component.LENGTH_FILL_PARENT);
checkbox.Width(Component.LENGTH_FILL_PARENT);
checkbox.BackgroundColor(COLOR_NONE);
checkbox.Enabled(false);
checkbox.TextColor(COLOR_BLACK);
checkbox.Visible(true);
hz3 = new HorizontalArrangement(this);
hz3.Visible(true);
fast = new Button(hz3);
fast.Enabled(false);
fast.Text("Fast");
fast.Height(Component.LENGTH_FILL_PARENT);
fast.Width(Component.LENGTH_FILL_PARENT);
fast.BackgroundColor(COLOR_DEFAULT);
fast.TextColor(COLOR_BLACK);
fast.FontSize(16);
fast.Visible(true);
medium = new Button(hz3);
medium.Enabled(false);
medium.Text("Medium");
medium.Height(Component.LENGTH_FILL_PARENT);
medium.Width(Component.LENGTH_FILL_PARENT);
medium.BackgroundColor(COLOR_DEFAULT);
medium.TextColor(COLOR_BLACK);
medium.FontSize(16);
medium.Visible(true);
slow = new Button(hz3);
slow.Enabled(false);
slow.Text("Slow");
slow.Height(Component.LENGTH_FILL_PARENT);
slow.Width(Component.LENGTH_FILL_PARENT);
slow.BackgroundColor(COLOR_DEFAULT);
slow.TextColor(COLOR_BLACK);
slow.FontSize(16);
slow.Visible(true);
tb = new TableArrangement(this);
tb.Visible(true);
stop = new Button(tb);
stop.Enabled(false);
stop.Image("stop.png");
stop.Height((int) (0.3333 * (LENGTH_FILL_PARENT)));
stop.Width((int) (0.3333 * (LENGTH_FILL_PARENT)));
stop.Visible(true);
tb.$add(stop);
down = new Button(tb);
down.Enabled(false);
down.Image("down.png");
down.Height((int) (0.3333 * (LENGTH_FILL_PARENT)));
down.Width((int) (0.3333 * (LENGTH_FILL_PARENT)));
down.Visible(true);
left = new Button(tb);
left.Enabled(false);
left.Image("left.png");
left.Height((int) (0.3333 * (LENGTH_FILL_PARENT)));
left.Width((int) (0.3333 * (LENGTH_FILL_PARENT)));
left.Visible(true);
up = new Button(tb);
up.Enabled(false);
up.Height((int) (0.3333 * (LENGTH_FILL_PARENT)));
up.Width((int) (0.3333 * (LENGTH_FILL_PARENT)));
up.Image("up.png");
up.Visible(true);
right = new Button(tb);
right.Enabled(false);
right.Image("right.png");
right.Height((int) (0.3333 * (LENGTH_FILL_PARENT)));
right.Width((int) (0.3333 * (LENGTH_FILL_PARENT)));
right.Visible(true);
hz4 = new HorizontalArrangement(this);
hz4.Visible(true);
deg0 = new Button(hz4);
deg0.Enabled(false);
deg0.Text("Rotate 0°");
deg0.Height(LENGTH_FILL_PARENT);
deg0.Width(LENGTH_FILL_PARENT);
deg0.BackgroundColor(COLOR_DEFAULT);
deg0.TextColor(COLOR_BLACK);
deg0.FontSize(16);
deg0.Visible(true);
deg90 = new Button(hz4);
deg90.Enabled(false);
deg90.Text("Rotate 90°");
deg90.Height(LENGTH_FILL_PARENT);
deg90.Width(LENGTH_FILL_PARENT);
deg90.BackgroundColor(COLOR_DEFAULT);
deg90.TextColor(COLOR_BLACK);
deg90.FontSize(16);
deg90.Visible(true);
deg180 = new Button(hz4);
deg180.Enabled(false);
deg180.Text("Rotate 180°");
deg180.Height(LENGTH_FILL_PARENT);
deg180.Width(LENGTH_FILL_PARENT);
deg180.BackgroundColor(COLOR_DEFAULT);
deg180.TextColor(COLOR_BLACK);
deg180.FontSize(16);
deg180.Visible(true);
bt = new BluetoothClient(this);
bt.CharacterEncoding("UTF-8");
bt.DelimiterByte(0);
clock = new Clock(this);
clock.TimerAlwaysFires(true);
clock.TimerEnabled(false);
clock.TimerInterval(1000);
EventDispatcher.registerEventForDelegation(this, "ClickEvent", "Click");
EventDispatcher.registerEventForDelegation(this,"Timer","Timer");
EventDispatcher.registerEventForDelegation(this,"Checkbox","Changed");
EventDispatcher.registerEventForDelegation(this,"List_dev","BeforePicking");
EventDispatcher.registerEventForDelegation(this,"List_dev","AfterPicking");
}
@Override
public boolean dispatchEvent(Component component, String compname, String eventname, Object[] args) {
if (component.equals(up) && eventname.equals("Click")) {
bt.Send1ByteNumber("1");
return true;
}
else if (component.equals(down) && eventname.equals("Click")) {
bt.Send1ByteNumber("2");
return true;
}
else if (component.equals(left) && eventname.equals("Click")) {
bt.Send1ByteNumber("3");
return true;
}
else if (component.equals(right) && eventname.equals("Click")) {
bt.Send1ByteNumber("4");
return true;
}
else if (component.equals(stop) && eventname.equals("Click")) {
bt.Send1ByteNumber("5");
return true;
}
else if (component.equals(fast) && eventname.equals("Click")) {
bt.Send1ByteNumber("9");
return true;
}
else if (component.equals(medium) && eventname.equals("Click")) {
bt.Send1ByteNumber("10");
return true;
}
else if (component.equals(slow) && eventname.equals("Click")) {
bt.Send1ByteNumber("11");
return true;
}
else if (component.equals(deg0) && eventname.equals("Click")) {
bt.Send1ByteNumber("6");
return true;
}
else if (component.equals(deg90) && eventname.equals("Click")) {
bt.Send1ByteNumber("7");
return true;
}
else if (component.equals(deg180) && eventname.equals("Click")) {
bt.Send1ByteNumber("8");
return true;
}
else if (component.equals(list_dev) && eventname.equals("BeforePicking")) {
// list_dev.BeforePicking();
list_dev.Elements(YailList.makeList(bt.AddressesAndNames()));
return true;
}
else if(component.equals(list_dev) && eventname.equals("AfterPicking")) {
// list_dev.AfterPicking();
bt.Connect(list_dev.Selection());
if (bt.IsConnected()) {
up.Enabled(true);
down.Enabled(true);
left.Enabled(true);
right.Enabled(true);
stop.Enabled(true);
fast.Enabled(true);
medium.Enabled(true);
slow.Enabled(true);
list_dev.Enabled(false);
status.BackgroundColor(COLOR_WHITE);
status.Text("Status: Connected");
clock.TimerInterval(5000);
clock.TimerEnabled(true);
checkbox.Enabled(true);
return true;
} else {
status.BackgroundColor(COLOR_BLACK);
status.TextColor(Component.COLOR_RED);
status.Text("Cannot Connect");
return true;
}
}
else if(component.equals(clock) && eventname.equals("Timer")) {
if (bt.IsConnected()) {
clock.TimerInterval(5000);
clock.TimerEnabled(true);
return true;
} else {
up.Enabled(false);
down.Enabled(false);
left.Enabled(false);
right.Enabled(false);
stop.Enabled(false);
fast.Enabled(false);
medium.Enabled(false);
slow.Enabled(false);
list_dev.Enabled(true);
status.BackgroundColor(COLOR_RED);
status.Text("Status: Connection Error");
clock.TimerEnabled(false);
checkbox.Enabled(false);
deg0.Enabled(false);
deg90.Enabled(false);
deg180.Enabled(false);
list_dev.Text("Connect to Robot");
list_dev.BackgroundColor(COLOR_BLUE);
return true;
}
}
else if(component.equals(checkbox) && eventname.equals("Changed")) {
up.Enabled(false);
down.Enabled(false);
left.Enabled(false);
right.Enabled(false);
stop.Enabled(false);
fast.Enabled(false);
medium.Enabled(false);
slow.Enabled(false);
deg0.Enabled(true);
deg90.Enabled(true);
deg180.Enabled(true);
return true;
}
return false;
}
}
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.brr.uet.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
</manifest>
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.brr.uet.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
}
logcat的
02-27 23:08:09.547 11720-11726/? E/jdwp: Failed sending reply to debugger: Success
02-27 23:08:09.716 11720-11726/? E/jdwp: Failed sending reply to debugger: Success
02-27 23:08:09.809 1078-1609/com.google.android.gms.persistent E/CellLocation: create GsmCellLocation
02-27 23:08:09.830 1078-1609/com.google.android.gms.persistent E/CellLocation: create GsmCellLocation
02-27 23:08:22.841 115-340/? E/Cryptfs: not running with encryption, aborting