test for.
This commit is contained in:
parent
effa89e030
commit
27814e5a8e
@ -14,6 +14,7 @@ import android.util.Log;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
||||||
|
import com.hoho.android.usbserial.driver.UsbSerialPort;
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber;
|
import com.hoho.android.usbserial.driver.UsbSerialProber;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -25,11 +26,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public static final String TAG="carnav";
|
public static final String TAG="carnav";
|
||||||
static final String ACTION_USB_PERMISSION = "com.flywithu.carnav.USB_PERMISSION";
|
static final String ACTION_USB_PERMISSION = "com.flywithu.carnav.USB_PERMISSION";
|
||||||
private BroadcastReceiver usbReceiver = null;
|
private BroadcastReceiver usbReceiver = null;
|
||||||
|
private static UsbSerialPort sPort = null;
|
||||||
private void goService()
|
private void goService()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (RealService.serviceIntent == null) {
|
if (RealService.serviceIntent == null) {
|
||||||
|
|
||||||
serviceIntent = new Intent(this, RealService.class);
|
serviceIntent = new Intent(this, RealService.class);
|
||||||
startService(serviceIntent);
|
startService(serviceIntent);
|
||||||
|
Toast.makeText(getApplicationContext(), "new start", Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
serviceIntent = RealService.serviceIntent;//getInstance().getApplication();
|
serviceIntent = RealService.serviceIntent;//getInstance().getApplication();
|
||||||
Toast.makeText(getApplicationContext(), "already", Toast.LENGTH_LONG).show();
|
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))
|
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();
|
goService();
|
||||||
}
|
}
|
||||||
else
|
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 {
|
else {
|
||||||
|
Toast.makeText(getApplicationContext(), "Has Permission", Toast.LENGTH_LONG).show();
|
||||||
connection = manager.openDevice(driver.getDevice());
|
connection = manager.openDevice(driver.getDevice());
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
Toast.makeText(getApplicationContext(), "Unknown error", Toast.LENGTH_LONG);
|
Toast.makeText(getApplicationContext(), "Unknown error", Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} 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();
|
goService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
e.toString();
|
Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user