Example usage for android.bluetooth.le AdvertiseSettings ADVERTISE_TX_POWER_HIGH

List of usage examples for android.bluetooth.le AdvertiseSettings ADVERTISE_TX_POWER_HIGH

Introduction

In this page you can find the example usage for android.bluetooth.le AdvertiseSettings ADVERTISE_TX_POWER_HIGH.

Prototype

int ADVERTISE_TX_POWER_HIGH

To view the source code for android.bluetooth.le AdvertiseSettings ADVERTISE_TX_POWER_HIGH.

Click Source Link

Document

Advertise using high TX power level.

Usage

From source file:Main.java

public static AdvertiseSettings createAdvSettings(boolean connectable, int timeoutMillis) {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    builder.setConnectable(connectable);
    builder.setTimeout(timeoutMillis);//w  ww .jav  a  2  s.  c om
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
    return builder.build();
}

From source file:com.elitise.appv2.Peripheral.java

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

    Intent I = getIntent();/*  ww w.  j  a  v  a2s .  c  om*/
    name = I.getStringExtra("mBname");
    batteryIdx = I.getIntExtra("idx", -1);
    if (!sNExist()) {
        String mSN = I.getStringExtra("mSN");
        saveSN(mSN);
    }
    isTablet = isTabletDevice();

    //    FirebaseStorage storage = FirebaseStorage.getInstance();
    //    StorageReference storageRef = storage.getReference();
    //    FirebaseOptions opts = FirebaseApp.getInstance().getOptions();
    //    Log.e(TAG, "Bucket = " + opts.getStorageBucket()+"\n URL"+opts.getApplicationId());
    //mDetetor = new GestureDetectorCompat(this, new MyGestureListener());

    setContentView(R.layout.activity_peripherals);
    TextView demoText = (TextView) findViewById(R.id.demoText);
    if (mUser.getBatteriesList().get(batteryIdx).isDemo) {
        demoText.setVisibility(View.VISIBLE);
        demoText.bringToFront();
    } else {
        demoText.setVisibility(View.INVISIBLE);
    }
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    mBluetoothDevices = new HashSet<>();
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = mBluetoothManager.getAdapter();
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    statusBar = (TextView) findViewById(R.id.statusBar);
    //    boolean enableDiag = sharedPrefs.getBoolean(getString(R.string.pref_mode_key), false);
    //

    //    if (!enableDiag)
    //      mCurrentServiceFragment = new BatteryServiceFragment();
    //    else
    //      mCurrentServiceFragment = new BatteryServiceDiagFragment();
    if (savedInstanceState != null) {
        phoneFragment = (PhoneLayoutFragement) getSupportFragmentManager().findFragmentByTag("PHONE");
        normalFragment = (BatteryServiceFragment) getSupportFragmentManager().findFragmentByTag("NORMAL");
        diagFragment = (BatteryServiceDiagFragment) getSupportFragmentManager().findFragmentByTag("DIAG");
        if (isTablet) {
            mCurrentServiceFragment = normalFragment;
        } else {
            mCurrentServiceFragment = phoneFragment;
        }

    } else {
        diagFragment = new BatteryServiceDiagFragment();
        normalFragment = new BatteryServiceFragment();
        phoneFragment = new PhoneLayoutFragement();
        //mCurrentServiceFragment = normalFragment;

        Bundle bd = new Bundle();
        bd.putString("mBname", name);
        bd.putInt("bIndex", batteryIdx);
        diagFragment.setArguments(bd);
        normalFragment.setArguments(bd);
        phoneFragment.setArguments(bd);
        if (isTablet) {
            mCurrentServiceFragment = normalFragment;
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.normal_fragment_container, normalFragment, "NORMAL")
                    .add(R.id.diag_fragment_container, diagFragment, "DIAG").hide(diagFragment)
                    .show(normalFragment).commit();
        } else {
            mCurrentServiceFragment = phoneFragment;
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.phone_fragment_container, phoneFragment, "PHONE")
                    .add(R.id.normal_fragment_container, normalFragment, "NORMAL")
                    .add(R.id.diag_fragment_container, diagFragment, "DIAG").hide(diagFragment)
                    .hide(normalFragment).show(phoneFragment).commit();
        }
        mCurrentServiceFragment.setArguments(bd);
    }

    if (!mUser.getBatteriesList().get(batteryIdx).isBonded) {
        mBluetoothGattService = mCurrentServiceFragment.getBluetoothGattService();
    } else {
        mBluetoothGattService = mCurrentServiceFragment.getBluetoothGattServiceCustom();
    }

    mAdvSettings = new AdvertiseSettings.Builder().setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH).setConnectable(true).setTimeout(0)
            .build();

    mAdvData = new AdvertiseData.Builder().setIncludeDeviceName(false).setIncludeTxPowerLevel(false)
            .addServiceUuid(
                    mCurrentServiceFragment.getServiceUUID(mUser.getBatteriesList().get(batteryIdx).isBonded))
            .build();

    mScanResponse = new AdvertiseData.Builder().setIncludeDeviceName(true).setIncludeTxPowerLevel(true).build();

    //
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar2);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);

    getSupportActionBar().setDisplayShowTitleEnabled(false);

    logoView = (Logo_pathsView) findViewById(R.id.logoBar);

    Context context = getApplicationContext(); // or activity.getApplicationContext()
    PackageManager packageManager = context.getPackageManager();
    String packageName = context.getPackageName();

    String myVersionName = "1.0.0"; // initialize String

    try {
        myVersionName = packageManager.getPackageInfo(packageName, 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    logoView.setVersion(myVersionName);

    if (!mBluetoothAdapter.isMultipleAdvertisementSupported()) {
        new MaterialDialog.Builder(this).title("BLE ERROR")
                .content("Sorry, this device not support BLE peripheral mode").positiveText("CONFIRM")
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        finish();
                    }
                });
    }

}