@Override public void onStart() { super.onStart(); if (D) Log.d(TAG, "++ ON START ++"); if (!mBluetoothAdapter.isEnabled()) { // ask the user to enable BlueTooth Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } else { // this only works if you already bonded with this device if (D) Log.d(TAG, "BT already enabled"); final BluetoothDevice[] bondedDevices = new BluetoothDevice[mBluetoothAdapter.getBondedDevices().size()]; mBluetoothAdapter.getBondedDevices().toArray(bondedDevices); List<CharSequence> devices = new ArrayList<CharSequence>(); // update the "Select device" spinner for (BluetoothDevice btd : bondedDevices) { Log.d(TAG, "Found bonded device: " + btd.getName()); devices.add(btd.getName()); } ArrayAdapter spinnerAdapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, devices); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); Spinner selectDeviceSpinner = (Spinner) findViewById(R.id.spinner); selectDeviceSpinner.setAdapter(spinnerAdapter); selectDeviceSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if (D) Log.d(TAG, "Selected: " + bondedDevices[pos].getName()); btDevice = bondedDevices[pos]; } public void onNothingSelected(AdapterView<?> arg0) {} }); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.profile); findViews(); /*Select Category work */ final String[] categories = getIntent().getStringArrayExtra("Options"); ArrayAdapter<String> catadapt; catadapt = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories); mCatSpin.setAdapter(catadapt); mCatSpin.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { mChosenCategory = categories[pos]; } public void onNothingSelected(AdapterView<?> parent) {} }); /*Availability selection work*/ mAvail = (Button) findViewById(R.id.editavail); mAvail.setOnClickListener(this); /*Submit/Back button work*/ mSub = (Button) findViewById(R.id.submitbutton); mSub.setOnClickListener(this); mBack.setOnClickListener(this); /*Web View & Camera uploader work*/ openCam.setOnClickListener(this); openWeb.setOnClickListener(this); web.getSettings().setJavaScriptEnabled(true); web.loadUrl("http://www.monkbananas.com/uploader/index.php"); // ------Everything below this line was found on StackOverflow-------------------- web.setWebChromeClient( new WebChromeClient() { @Override public boolean shouldOverrideUrlLoading(WebView v, String url) { web.loadUrl(url); return true; } // The undocumented magic method override // Eclipse will swear at you if you try to put @Override here // For Android 3.0+ public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } // For Android 3.0+ public void openFileChooser(ValueCallback uploadMsg, String acceptType) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE); } // For Android 4.1 public void openFileChooser( ValueCallback<Uri> uploadMsg, String acceptType, String capture) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } }); }