Example usage for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE

List of usage examples for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE.

Prototype

String ACTION_REQUEST_ENABLE

To view the source code for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE.

Click Source Link

Document

Activity Action: Show a system activity that allows the user to turn on Bluetooth.

Usage

From source file:samples.piggate.com.piggateCompleteExample.Activity_Logged.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object
    setContentView(R.layout.activity_logged);
    getSupportActionBar().setTitle(PiggateUser.getEmail());

    startService(new Intent(getApplicationContext(), Service_Notify.class)); //Start the service

    //Initialize and set all the left navigation drawer fields
    mDrawer = new Drawer().withActivity(this).withTranslucentStatusBar(false).withHeader(R.layout.drawerheader)
            .addDrawerItems( /* Add drawer items with this method */)
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override/*www  .  jav a 2 s .  co m*/
                public void onItemClick(AdapterView<?> parent, View view, int position, long id,
                        IDrawerItem drawerItem) {
                    // Open the exchange activity for the selected item
                    Intent slideactivity = new Intent(Activity_Logged.this, Activity_Exchange.class);
                    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                    //Send the current offer information to the exchange activity
                    slideactivity.putExtra("offerName", exchangeOfferList.get(position).getName().toString());
                    slideactivity.putExtra("offerDescription",
                            exchangeOfferList.get(position).getDescription().toString());
                    slideactivity.putExtra("offerImgURL",
                            exchangeOfferList.get(position).getImgURL().toString());
                    slideactivity.putExtra("exchangeID",
                            exchangeOfferList.get(position).getExchangeID().toString());

                    Bundle bndlanimation = ActivityOptions.makeCustomAnimation(Activity_Logged.this,
                            R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                    startActivity(slideactivity, bndlanimation);
                }
            }).withSliderBackgroundColor(Color.parseColor("#FFFFFF")).withSelectedItem(-1).build();

    //Initialize recycler view
    mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(Activity_Logged.this));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    newBeaconsLayout = (LinearLayout) findViewById(R.id.newBeaconsLayout);

    //Initialize swipe layout
    mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    mSwipeLayout.setOnRefreshListener(this);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Logout error");
    errorDialog.setMessage("There is an error with the logout");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    successPaymentDialog = new AlertDialog.Builder(this).create();
    successPaymentDialog.setTitle("Successful payment");
    successPaymentDialog.setMessage("Now you can exchange your purchased product");
    successPaymentDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    errorBuyDialog = new AlertDialog.Builder(this).create();
    errorBuyDialog.setTitle("Payment failed");
    errorBuyDialog.setMessage("There is an error with your payment");
    errorBuyDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    successExchangeDialog = new AlertDialog.Builder(this).create();
    successExchangeDialog.setTitle("Offer successfully exchanged");
    successExchangeDialog.setMessage("The offer has been purchased and exchanged");
    successExchangeDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    errorExchangeDialog = new AlertDialog.Builder(this).create();
    errorExchangeDialog.setTitle("Exchange error");
    errorExchangeDialog.setMessage("There is an error with the exchange");
    errorExchangeDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    networkErrorDialog = new AlertDialog.Builder(this).create();
    networkErrorDialog.setTitle("Network error");
    networkErrorDialog.setMessage("There is an error with the network connection");
    networkErrorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    fadeIn = AnimationUtils.loadAnimation(Activity_Logged.this, R.anim.fadein);
    fadeOut = AnimationUtils.loadAnimation(Activity_Logged.this, R.anim.fadeout);

    //Check if the bluetooth is switched on
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }

    if (getIntent().hasExtra("payment")) {
        if (getIntent().getExtras().getBoolean("payment") == true) {
            successPaymentDialog.show(); //Show success payment dialog
            mDrawer.openDrawer(); //Open the left panel
        } else {
            errorBuyDialog.show(); //Show payment error dialog
        }
    } else if (getIntent().hasExtra("exchanged")) {
        if (getIntent().getExtras().getBoolean("exchanged") == true) {
            successExchangeDialog.show(); //Show exchange success dialog
        } else {
            errorExchangeDialog.show(); //Show exchange error dialog
        }
    }
}

From source file:ack.me.truconnectandroiddemo.MainActivity.java

private void startBLEEnableIntent() {
    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableBtIntent, BLE_ENABLE_REQ_CODE);
}

From source file:com.hardcopy.blechat.MainActivity.java

/**
 * Initialization / Finalization/* ww w  .  j  av a  2 s. co m*/
 */
private void initialize() {
    Logs.d(TAG, "# Activity - initialize()");

    // Use this check to determine whether BLE is supported on the device. Then
    // you can selectively disable BLE-related features.
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(this, R.string.bt_ble_not_supported, Toast.LENGTH_SHORT).show();
        finish();
    }

    mService.setupService(mActivityHandler);

    // If BT is not on, request that it be enabled.
    // RetroWatchService.setupBT() will then be called during onActivityResult
    if (!mService.isBluetoothEnabled()) {
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, Constants.REQUEST_ENABLE_BT);
    }

    // Load activity reports and display
    if (mRefreshTimer != null) {
        mRefreshTimer.cancel();
    }

    // Use below timer if you want scheduled job
    //mRefreshTimer = new Timer();
    //mRefreshTimer.schedule(new RefreshTimerTask(), 5*1000);
}

From source file:au.gov.ga.worldwind.androidremote.client.Remote.java

@Override
protected void onStart() {
    super.onStart();

    if (!bluetoothAdapter.isEnabled()) {
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
    } else if (communicator.getState() != State.CONNECTED && !devicesShowing) {
        connect();/*from   w w  w .j av  a 2  s  .  c  om*/
    }
}

From source file:com.example.android.naradaonline.DatagramFragment.java

@Override
public void onStart() {
    super.onStart();
    // If BT is not on, request that it be enabled.
    // setupChat() will then be called during onActivityResult
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
        // Otherwise, setup the chat session
    } else if (mChatService == null) {
        setupChat();/*from  w  ww.  j  ava  2  s  . c  o m*/
    }
}

From source file:com.example.administrator.myapplication2._3_HB._3_MainActivity.java

/**
 * Initialization / Finalization/*from www  .j  av a  2  s  . co  m*/
 */
private void initialize() {
    Logs.d(TAG, "# Activity - initialize()");
    mService.setupService(mActivityHandler);

    // If BT is not on, request that it be enabled.
    // RetroWatchService.setupBT() will then be called during onActivityResult
    if (!mService.isBluetoothEnabled()) {
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, Constants.REQUEST_ENABLE_BT);
    }

    // Load activity reports and display
    if (mRefreshTimer != null) {
        mRefreshTimer.cancel();
    }

    // Use below timer if you want scheduled job
    //mRefreshTimer = new Timer();
    //mRefreshTimer.schedule(new RefreshTimerTask(), 5*1000);
}

From source file:com.example.lilach.alsweekathon_new.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ///////////////////////////////////////////
    try {//from  w w w  .j  a  v  a 2s  .  c  o m
        String yourFilePath = Environment.getExternalStorageDirectory() + "/"
                + "spiralStairs_CalInertialAndMag.csv";
        CSVReader reader = new CSVReader(new FileReader(yourFilePath));

        String[] nextLine;
        //skip the first line - headers
        reader.readNext();
        LinkedList<Signal> signals = new LinkedList<Signal>();

        for (int i = 0; i < 3; i++) {
            nextLine = reader.readNext();
            // while ((nextLine = reader.readNext()) != null) {
            // nextLine[] is an array of values from the line
            System.out.println(nextLine[0] + nextLine[1] + "etc...");
            Signal signal = new Signal();
            signal.setTimestamp(new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date()));
            signal.setPacketId(Integer.parseInt(nextLine[PACKET_NUMBER_INDEX]));
            signal.setAccelerometer(new XYZValues(Float.parseFloat(nextLine[ACCELEROMETER_X_INDEX]),
                    Float.parseFloat(nextLine[ACCELEROMETER_Y_INDEX]),
                    Float.parseFloat(nextLine[ACCELEROMETER_Z_INDEX])));
            signal.setGyro(new XYZValues(Float.parseFloat(nextLine[GYROSCOPE_X_INDEX]),
                    Float.parseFloat(nextLine[GYROSCOPE_Y_INDEX]),
                    Float.parseFloat(nextLine[GYROSCOPE_Z_INDEX])));

            signals.add(signal);

        }

        serverRequest sr = new serverRequest();
        sr.setSignals(signals);
        sr.setUserid("user");
        sr.setTimestamp("111111");

        //send the data to the server: Json, Post
        Gson gson = new Gson();
        String json = gson.toJson(sr);
        Log.d("aa", json);
        makeRequest("http://alsvm.cloudapp.net:8080/signals/user", json);
        // HttpResponse a = makeRequest("http://alsvm.cloudapp.net:8080/signals/user", json);
        // Log.d("httpResponse", a.toString());

        //            List myEntries = reader.readAll();
        //            System.out.println("size: " +myEntries.size());
        //            System.out.println("first item: "+myEntries.get(0));

    } catch (IOException e) {
        Log.d("exception: ", e.getMessage());
    }

    //////////////////////////////////////////////

    setContentView(R.layout.main);
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    messageListView = (ListView) findViewById(R.id.listMessage);
    listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail);
    messageListView.setAdapter(listAdapter);
    messageListView.setDivider(null);
    btnConnectDisconnect = (Button) findViewById(R.id.btn_select);
    btnSend = (Button) findViewById(R.id.sendButton);
    edtMessage = (EditText) findViewById(R.id.sendText);
    /// service_init();

    // Handler Disconnect & Connect button
    btnConnectDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mBtAdapter.isEnabled()) {
                Log.i(TAG, "onClick - BT not enabled yet");
                Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
            } else {
                if (btnConnectDisconnect.getText().equals("Connect")) {

                    //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices

                    Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class);
                    startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
                } else {
                    //Disconnect button pressed
                    //                    if (mDevice!=null)
                    //                    {
                    //                       //mService.disconnect();
                    //
                    //                    }
                }
            }
        }
    });
    // Handler Send button
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = (EditText) findViewById(R.id.sendText);
            String message = editText.getText().toString();
            byte[] value;
            try {
                //send data to service
                value = message.getBytes("UTF-8");
                //mService.writeRXCharacteristic(value);
                //Update the log with time stamp
                String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                listAdapter.add("[" + currentDateTimeString + "] TX: " + message);
                messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
                edtMessage.setText("");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Set initial UI state

}

From source file:org.jonblack.bluetrack.activities.LiveTrackingFragment.java

public boolean onOptionsItemSelected(MenuItem item) {
    // TODO: Bit odd that the LiveTrackingFragment is responsible for this.
    switch (item.getItemId()) {
    case R.id.menu_toggle_tracking:
        if (mTracking) {
            stopBluetoothLogService();//from ww w . jav a2s.c om
        } else {
            // Check that bluetooth is enabled. If it isn't, ask the user to
            // enable it. If the user enables it, the BluetoothLogService will be
            // started in the callback.
            BluetoothAdapter localBtAdapter = BluetoothAdapter.getDefaultAdapter();
            assert (localBtAdapter != null);

            if (!localBtAdapter.isEnabled()) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
            } else {
                startBluetoothLogService();
            }
        }

        // Cause the action bar menu to be updated so the button text can change.    
        ((SherlockFragmentActivity) getActivity()).invalidateOptionsMenu();

        break;
    case R.id.menu_settings:
        Intent intent = new Intent(getActivity(), SettingsActivity.class);
        startActivity(intent);
        break;
    default:
        assert (false);
    }

    return true;
}

From source file:com.tribalyte.plugin.myo.MyoApi.java

private void startBluetoothConfigActivity() {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            cordova.setActivityResultCallback(MyoApi.this);
            cordova.getActivity().startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                    REQ_CODE_ENABLE_BT);
            logd("BT configuration activity started");
        }/*from w w  w.ja v  a  2  s.c o m*/
    });
}

From source file:com.guldencoin.androidwallet.nlg.ui.RequestCoinsFragment.java

private void maybeInitBluetoothListening() {
    if (!bluetoothAdapter.isEnabled()) {
        // try to enable bluetooth
        startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                REQUEST_CODE_ENABLE_BLUETOOTH);
    } else {/*from  w  w w. ja  v  a  2  s.  c om*/
        bluetoothMac = Bluetooth.compressMac(bluetoothAdapter.getAddress());

        bluetoothServiceIntent = new Intent(activity, AcceptBluetoothService.class);
        activity.startService(bluetoothServiceIntent);
    }
}