Saturday, 17 August 2013

How can I remove the error at "Context.USB_SERVICE" (Eclipse -> Android)

How can I remove the error at "Context.USB_SERVICE" (Eclipse -> Android)

Please keep in mind this is my first StackOverflow post, thus if there are
some details that are vague of stated in a stupid way, my apologies. Down
to business:
I am working on a project where a friend and I are using the FT232R IC to
connect an Android USB host device to a device that communicates via
serial port. I have a great code source where I am working from:
https://code.google.com/p/usb-serial-for-android/
The following source code is our own interpreted code derived from the
above to suite our own program:
package com.example.commtest;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
import com.hoho.android.usbserial.driver.*;
import com.hoho.android.usbserial.util.*;
import com.example.commtest.ReadUSBdata;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.LinkedHashMap;
import java.util.Map;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbRequest;
import android.util.Log;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbAccessory;
import com.hoho.android.usbserial.util.HexDump;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView theOutput = (TextView) findViewById(R.id.edtVertoon);
theOutput.setText("1234553242342342341243214");
// Get UsbManager from Android.
UsbManager manager = (UsbManager)
getSystemService(Context.USB_SERVICE);
// Find the first available driver.
UsbSerialDriver driver = UsbSerialProber.acquire(manager);
(The above is just the 'Top' part of the code)
The error appears on the 4th line from the bottom, and it states: "Context
cannot be resolved to a variable". This is just a test program to gain
understanding on this subject.
Before everybody lose their minds, I have Google'd this, and there are a
few posts that helped, but none that actually solved my problem.
Any advice would help, and again, thank you for your time guys.

No comments:

Post a Comment