test for.

This commit is contained in:
SeungheeOh 2019-09-13 01:23:41 +09:00
parent effa89e030
commit 27814e5a8e

View File

@ -14,6 +14,7 @@ import android.util.Log;
import android.widget.Toast;
import com.hoho.android.usbserial.driver.UsbSerialDriver;
import com.hoho.android.usbserial.driver.UsbSerialPort;
import com.hoho.android.usbserial.driver.UsbSerialProber;
import java.util.List;
@ -25,11 +26,17 @@ public class MainActivity extends AppCompatActivity {
public static final String TAG="carnav";
static final String ACTION_USB_PERMISSION = "com.flywithu.carnav.USB_PERMISSION";
private BroadcastReceiver usbReceiver = null;
private static UsbSerialPort sPort = null;
private void goService()
{
if (RealService.serviceIntent == null) {
serviceIntent = new Intent(this, RealService.class);
startService(serviceIntent);
Toast.makeText(getApplicationContext(), "new start", Toast.LENGTH_LONG).show();
} else {
serviceIntent = RealService.serviceIntent;//getInstance().getApplication();
Toast.makeText(getApplicationContext(), "already", Toast.LENGTH_LONG).show();
@ -74,12 +81,12 @@ public class MainActivity extends AppCompatActivity {
if(intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,true))
{
Toast.makeText(getApplicationContext(), "Pemission Granted", Toast.LENGTH_LONG);
Toast.makeText(getApplicationContext(), "Pemission Granted", Toast.LENGTH_LONG).show();
goService();
}
else
{
Toast.makeText(getApplicationContext(), "Pemission Denied", Toast.LENGTH_LONG);
Toast.makeText(getApplicationContext(), "Pemission Denied", Toast.LENGTH_LONG).show();
}
}
@ -96,18 +103,26 @@ public class MainActivity extends AppCompatActivity {
}
else {
Toast.makeText(getApplicationContext(), "Has Permission", Toast.LENGTH_LONG).show();
connection = manager.openDevice(driver.getDevice());
if (connection == null) {
Toast.makeText(getApplicationContext(), "Unknown error", Toast.LENGTH_LONG);
Toast.makeText(getApplicationContext(), "Unknown error", Toast.LENGTH_LONG).show();
} else {
sPort = driver.getPorts().get(0);
sPort.open(connection);
sPort.close();
sPort = null;
Toast.makeText(getApplicationContext(),"Serial Count:"+String.valueOf(driver.getPorts().size()),Toast.LENGTH_LONG).show();
goService();
}
}
}
catch(Exception e)
{
e.toString();
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
}