Example usage for android.bluetooth BluetoothAdapter ACTION_REQUEST_DISCOVERABLE

List of usage examples for android.bluetooth BluetoothAdapter ACTION_REQUEST_DISCOVERABLE

Introduction

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

Prototype

String ACTION_REQUEST_DISCOVERABLE

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

Click Source Link

Document

Activity Action: Show a system activity that requests discoverable mode.

Usage

From source file:spring16.cs442.com.obtchat_10.BluetoothChatFragment.java

/**
 * Makes this device discoverable./*from w  w w.  ja v  a  2  s  . c  o  m*/
 */
private void ensureDiscoverable() {
    if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 2000);
        startActivity(discoverableIntent);
    }
}

From source file:com.molidt.easyandroid.bluetooth.BluetoothFragmentV4.java

public void setDiscoverable(int discoveralbeTime) {
    Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, discoveralbeTime);
    startActivity(discoverableIntent);/*from   w w w .  ja  v  a2  s . com*/
}

From source file:com.example.bluetooth_faster_connection.MainActivity.java

private void ensureDiscoverable() {
    if (D)//from w  ww.j  ava2  s  .  c o m
        Log.d(TAG, "ensure discoverable");
    if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
        startActivity(discoverableIntent);
    }
}

From source file:org.imdea.panel.MainActivity.java

public void enableBt() {

    BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();

    if (!mAdapter.isEnabled())
        mAdapter.enable(); //Turn On Bluetooth without Permission

    /*if (!mAdapter.isEnabled())
    startActivity(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE));*/

    while (!mAdapter.isEnabled()) {
    }/* www.  j a  va2 s .com*/

    String restoredMAC = SP.getString("MAC", null);
    if (restoredMAC != null) {
        Global.DEVICE_ADDRESS = restoredMAC;
        if (restoredMAC.equals("00:00:00:00:00:00")) {
            Global.DEVICE_ADDRESS = mAdapter.getAddress();
            SharedPreferences.Editor editor = SP.edit();
            editor.putString("MAC", Global.DEVICE_ADDRESS);
            editor.apply();
        }
    } else {
        Global.DEVICE_ADDRESS = mAdapter.getAddress();
        SharedPreferences.Editor editor = SP.edit();
        editor.putString("MAC", Global.DEVICE_ADDRESS);
        editor.apply();
    }

    Log.w("MAC", Global.DEVICE_ADDRESS);

    if (mAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
        startActivity(discoverableIntent);
    }

}

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

/**
 * Ensure this device is discoverable by others
 *//*  w w  w . j  ava 2 s  .c  o  m*/
private void ensureDiscoverable() {
    if (mService.getBluetoothScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
        startActivity(intent);
    }
}

From source file:com.jtechme.apphub.FDroid.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.action_update_repo:
        UpdateService.updateNow(this);
        return true;

    case R.id.action_manage_repos:
        startActivity(new Intent(this, ManageReposActivity.class));
        return true;

    case R.id.action_settings:
        Intent prefs = new Intent(getBaseContext(), PreferencesActivity.class);
        startActivityForResult(prefs, REQUEST_PREFS);
        return true;

    case R.id.action_swap:
        startActivity(new Intent(this, SwapWorkflowActivity.class));
        return true;

    case R.id.action_bluetooth_apk:
        /*/*  ww  w . j  a va 2s . c om*/
         * If Bluetooth has not been enabled/turned on, then enabling
         * device discoverability will automatically enable Bluetooth
         */
        Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121);
        startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH);
        // if this is successful, the Bluetooth transfer is started
        return true;

    case R.id.action_about:
        View view = LayoutInflater.from(this).inflate(R.layout.about, null);

        String versionName = Utils.getVersionName(this);
        if (versionName != null) {
            ((TextView) view.findViewById(R.id.version)).setText(versionName);
        }

        AlertDialog alrt = new AlertDialog.Builder(this).setView(view).create();
        alrt.setTitle(R.string.about_title);
        alrt.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
        alrt.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

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

/**
 * Makes this device discoverable./*from ww w.  j a v a2  s.co m*/
 */
private void ensureDiscoverable() {
    if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
        startActivity(discoverableIntent);
    }
}

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

protected void ensureDiscoverable() {
    if (bluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        startActivity(discoverableIntent);
    }//  www . jav a2 s.co m
}

From source file:bluetoothchat.BluetoothChatFragment.java

/**
 * Makes this device discoverable./*from w w w .  j  a v  a 2  s  . c o m*/
 */
public void ensureDiscoverable() {
    if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
        startActivity(discoverableIntent);
    }
}

From source file:flex.android.magiccube.activity.ActivityBattleMode.java

private void ensureDiscoverable() {
    if (mBluetoothAdapter == null) {
        return;/*from  ww  w .  j a v a2 s.  c  o m*/
    }
    if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
        startActivityForResult(discoverableIntent, REQUEST_DISCOVERABLE);
    }
}