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:Main.java

public static void enableDiscoverable(Context context) {
    Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
    context.startActivity(discoverableIntent);
}

From source file:Main.java

public static void makeVisible(Context context, int durationSeconds) {
    Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, durationSeconds);
    context.startActivity(discoverableIntent);
}

From source file:Main.java

/**
 * Enable the bluetooth adapter.//from www  .java2  s .c o  m
 */
public static void bluetoothEnable(Activity activity, boolean discoverable, int reqCode) {
    if (discoverable) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
        activity.startActivityForResult(discoverableIntent, reqCode);
    } else {
        Intent bluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        activity.startActivityForResult(bluetoothIntent, reqCode);
    }
}

From source file:Main.java

public static void enableDiscovery(Context context) {
    Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, DISCOVERABLE_SECONDS);
    context.startActivity(discoverableIntent);
}

From source file:scmu.nutweet.bluetooth.BluetoothChat.java

private void ensureDiscoverable() {
    if (D)// w  ww.jav a 2s  .com
        Log.d(TAG, "ensure discoverable");
    if (Const.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:com.example.bluetooth_faster_connection.MainActivity.java

@Override
public void onStart() {
    super.onStart();
    if (D)//from  w  w w.j a v  a 2  s  . c  om
        Log.e(TAG, "++ ON START ++");

    // If BT is not on, request that it be enabled.
    // setupMessage() will then be called during onActivityResult
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableDiscoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        enableDiscoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
        startActivity(enableDiscoverableIntent);
        // startActivityForResult(enableDiscoverableIntent,
        // REQUEST_ENABLE_BT);
        // Otherwise, setup the Message session
    } else {
        if (mMessageService == null)
            setupMessage();
    }

}

From source file:com.example.android.bluetoothchat.LobbyActivity.java

private void ensureDiscoverable() {
    if (mBtAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
        startActivity(discoverableIntent);
    }//from  ww w  . j  av a 2  s .  com
}

From source file:app.park.com.bluetooth.BluetoothFragment.java

/**
 * Makes this device discoverable.// w ww  . j  a  v  a2 s  . c o m
 */
public void ensureDiscoverable() {
    if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
        Toast.makeText(getActivity(), "Role : BT Controller ", Toast.LENGTH_SHORT).show();
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
        startActivity(discoverableIntent);
    }
}

From source file:id.ridon.keude.Keude.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.action_update_repo:
        updateRepos();/*from   ww  w  .  j  a  va2 s.  c  o  m*/
        return true;

    case R.id.action_manage_repos:
        Intent i = new Intent(this, ManageReposActivity.class);
        startActivityForResult(i, REQUEST_MANAGEREPOS);
        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, SwapActivity.class));
        return true;

    case R.id.action_search:
        onSearchRequested();
        return true;

    case R.id.action_bluetooth_apk:
        /*
         * 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 = null;
        if (Build.VERSION.SDK_INT >= 11) {
            LayoutInflater li = LayoutInflater.from(this);
            view = li.inflate(R.layout.about, null);
        } else {
            view = View.inflate(new ContextThemeWrapper(this, R.style.AboutDialogLight), R.layout.about, null);
        }

        // Fill in the version...
        try {
            PackageInfo pi = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), 0);
            ((TextView) view.findViewById(R.id.version)).setText(pi.versionName);
        } catch (Exception e) {
        }

        Builder p = null;
        if (Build.VERSION.SDK_INT >= 11) {
            p = new AlertDialog.Builder(this).setView(view);
        } else {
            p = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AboutDialogLight)).setView(view);
        }
        final AlertDialog alrt = p.create();
        alrt.setIcon(R.drawable.ic_launcher);
        alrt.setTitle(getString(R.string.about_title));
        alrt.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.about_website),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Uri uri = Uri.parse("https://f-droid.org");
                        startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    }
                });
        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:net.cherryzhang.sekuhara.BluetoothButtonAndChat.BluetoothChat.BluetoothChat.java

public void ensureDiscoverable() {
    if (D)/*from   w  w  w.  ja v  a  2  s  . co  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, 300);
        startActivity(discoverableIntent);
    }
}