List of usage examples for android.bluetooth BluetoothManager getAdapter
public BluetoothAdapter getAdapter()
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
private void checkBleSupportAndInitialize() { // Use this check to determine whether BLE is supported on the device. if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(getActivity(), R.string.device_ble_not_supported, Toast.LENGTH_SHORT).show(); getActivity().finish();/* w w w. j a v a 2 s .c om*/ } // Initializes a Blue tooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { // Device does not support Blue tooth Toast.makeText(getActivity(), R.string.device_bluetooth_not_supported, Toast.LENGTH_SHORT).show(); getActivity().finish(); } }
From source file:com.nbplus.iotapp.service.IoTService.java
/** * ?? ? , enable ? ? ?? .//from ww w . ja v a2 s . c om */ public IoTResultCodes checkBluetoothEnabled() { // 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)) { return IoTResultCodes.BLE_NOT_SUPPORTED; } // Initializes a Bluetooth adapter. For API level 18 and above, get a reference to // BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); // Checks if Bluetooth is supported on the device. if (bluetoothAdapter == null) { return IoTResultCodes.BLUETOOTH_NOT_SUPPORTED; } // Ensures Bluetooth is enabled on the device. If Bluetooth is not currently enabled, // fire an intent to display a dialog asking the user to grant permission to enable it. if (!bluetoothAdapter.isEnabled()) { return IoTResultCodes.BLUETOOTH_NOT_ENABLED; } mLastConnectionStatus = true; return IoTResultCodes.SUCCESS; }
From source file:com.unarin.cordova.beacon.LocationManager.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private void initBluetoothAdapter() { Activity activity = cordova.getActivity(); BluetoothManager bluetoothManager = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }
From source file:com.paywith.ibeacon.service.IBeaconService.java
@TargetApi(18) private BluetoothAdapter getBluetoothAdapter() { if (android.os.Build.VERSION.SDK_INT < 18) { Log.w(TAG, "Not supported prior to API 18."); return null; }/* w ww . j av a 2 s. com*/ if (bluetoothAdapter == null) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) this.getApplicationContext() .getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); } return bluetoothAdapter; }
From source file:com.commontime.plugin.LocationManager.java
private void initBluetoothAdapter() { Activity activity = cordova.getActivity(); BluetoothManager bluetoothManager = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }
From source file:com.lef.ibeacon.service.UpdateService.java
/** * Initializes a reference to the local Bluetooth adapter. *///from ww w .j av a 2s .c o m private void initialize() { errorSign = false; final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); mAdapter = bluetoothManager.getAdapter(); }
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuService.java
/** * Initializes bluetooth adapter//from w w w .j av a2s.c om * * @return <code>true</code> if initialization was successful */ private boolean initialize() { // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (bluetoothManager == null) { loge("Unable to initialize BluetoothManager."); return false; } mBluetoothAdapter = bluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { loge("Unable to obtain a BluetoothAdapter."); return false; } return true; }
From source file:io.puzzlebox.bloom.ui.MakerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_maker, container, false); // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title); progressBarRange = (ProgressBar) v.findViewById(R.id.progressBarRange); //// ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null)); // ShapeDrawable progressBarRangeDrawable = new ShapeDrawable(); //// String progressBarRangeColor = "#FF00FF"; // String progressBarRangeColor = "#990099"; // progressBarRangeDrawable.getPaint().setColor(Color.parseColor(progressBarRangeColor)); // ClipDrawable progressRange = new ClipDrawable(progressBarRangeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); // progressBarRange.setProgressDrawable(progressRange); // progressBarRange.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); // progressBarRange.setMax(128 + 127); progressBarRange.setMax(bloomRangeMax); // imageViewStatus = (ImageView) v.findViewById(R.id.imageViewStatus); servoSeekBar = (SeekBar) v.findViewById(R.id.ServoSeekBar); servoSeekBar.setEnabled(false);//from www. j av a 2s . c om // servoSeekBar.setMax(180); servoSeekBar.setMax(100); servoSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { byte[] buf = new byte[] { (byte) 0x03, (byte) 0x00, (byte) 0x00 }; buf[1] = (byte) servoSeekBar.getProgress(); BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); // rssiValue = (TextView) v.findViewById(R.id.rssiValue); connectBloom = (Button) v.findViewById(R.id.connectBloom); connectBloom.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { if (!BloomSingleton.getInstance().scanFlag) { scanLeDevice(); Timer mTimer = new Timer(); mTimer.schedule(new TimerTask() { @Override public void run() { if ((BloomSingleton.getInstance().mDevice != null) && (BloomSingleton.getInstance().mDevice.getAddress() != null) && (BloomSingleton.getInstance().mBluetoothLeService != null)) { BloomSingleton .getInstance().mDeviceAddress = BloomSingleton.getInstance().mDevice .getAddress(); if (BloomSingleton.getInstance().mDeviceAddress != null) BloomSingleton.getInstance().mBluetoothLeService .connect(BloomSingleton.getInstance().mDeviceAddress); else { Toast toast = Toast.makeText(getActivity(), "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } BloomSingleton.getInstance().scanFlag = true; } else { getActivity().runOnUiThread(new Runnable() { public void run() { Toast toast = Toast.makeText(getActivity(), "Error connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } }); } } }, BloomSingleton.getInstance().SCAN_PERIOD); } } catch (Exception e) { Log.e(TAG, "Exception connecting to Bloom: " + e); Toast toast = Toast.makeText(getActivity(), "Exception connecting to Puzzlebox Bloom", Toast.LENGTH_SHORT); toast.setGravity(0, 0, Gravity.CENTER | Gravity.BOTTOM); toast.show(); } System.out.println(BloomSingleton.getInstance().connState); // Log.e(TAG, connState); // if (connState == false) { if (!BloomSingleton.getInstance().connState && BloomSingleton.getInstance().mDeviceAddress != null) { BloomSingleton.getInstance().mBluetoothLeService .connect(BloomSingleton.getInstance().mDeviceAddress); } else { if (BloomSingleton.getInstance().mBluetoothLeService != null) { setBloomRGBOff(); BloomSingleton.getInstance().mBluetoothLeService.disconnect(); BloomSingleton.getInstance().mBluetoothLeService.close(); setButtonDisable(); } } } }); redSeekBar = (SeekBar) v.findViewById(R.id.seekBarRed); redSeekBar.setEnabled(false); redSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { bloomColorRed = redSeekBar.getProgress(); byte[] buf = new byte[] { (byte) 0x0A, (byte) 0x00, (byte) bloomColorRed }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); greenSeekBar = (SeekBar) v.findViewById(R.id.seekBarGreen); greenSeekBar.setEnabled(false); greenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { bloomColorGreen = greenSeekBar.getProgress(); byte[] buf = new byte[] { (byte) 0x0A, (byte) 0x01, (byte) bloomColorGreen }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); blueSeekBar = (SeekBar) v.findViewById(R.id.seekBarBlue); blueSeekBar.setEnabled(false); blueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { bloomColorBlue = blueSeekBar.getProgress(); byte[] buf = new byte[] { (byte) 0x0A, (byte) 0x02, (byte) bloomColorBlue }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonOpen = (Button) v.findViewById(R.id.buttonOpen); buttonOpen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonClose = (Button) v.findViewById(R.id.buttonClose); buttonClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonCycleServo = (Button) v.findViewById(R.id.buttonDemoServo); buttonCycleServo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x03, (byte) 0x00, (byte) 0x00 }; // Cycle // byte[] buf = new byte[] { (byte) 0x04, (byte) 0x00, (byte) 0x00 }; // CycleSlow BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); buttonCycleRGB = (Button) v.findViewById(R.id.buttonDemoRGB); buttonCycleRGB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x06, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); updateBloomRGB(); } }); buttonDemo = (Button) v.findViewById(R.id.buttonDemo); buttonDemo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] buf = new byte[] { (byte) 0x05, (byte) 0x00, (byte) 0x00 }; BloomSingleton.getInstance().characteristicTx.setValue(buf); BloomSingleton.getInstance().mBluetoothLeService .writeCharacteristic(BloomSingleton.getInstance().characteristicTx); } }); // buttonDemo = (Button) v.findViewById(R.id.buttonDemo); // buttonDemo.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // byte[] buf; //// if (! BloomSingleton.getInstance().demoActive) { // BloomSingleton.getInstance().demoActive = true; // // // bloomOpen() //// buf = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x00}; //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // loopRGB() // buf = new byte[]{(byte) 0x06, (byte) 0x00, (byte) 0x00}; // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // Set Red to 0 // buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0 // BloomSingleton.getInstance().characteristicTx.setValue(buf); // BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // // bloomClose() //// buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00}; //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); // // //// } else { //// BloomSingleton.getInstance().demoActive = false; ////// buf = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00}; ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); //// buf = new byte[]{(byte) 0x0A, (byte) 0x00, (byte) 0x00}; // R = 0 //// BloomSingleton.getInstance().characteristicTx.setValue(buf); //// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); ////// buf = new byte[]{(byte) 0x0A, (byte) 0x01, (byte) 0x00}; // G = 0 ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); ////// buf = new byte[]{(byte) 0x0A, (byte) 0x02, (byte) 0x00}; // B = 0 ////// BloomSingleton.getInstance().characteristicTx.setValue(buf); ////// BloomSingleton.getInstance().mBluetoothLeService.writeCharacteristic(BloomSingleton.getInstance().characteristicTx); //// } // } // }); if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show(); getActivity().finish(); } final BluetoothManager mBluetoothManager = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); BloomSingleton.getInstance().mBluetoothAdapter = mBluetoothManager.getAdapter(); if (BloomSingleton.getInstance().mBluetoothAdapter == null) { Toast.makeText(getActivity(), "Bluetooth LE not supported", Toast.LENGTH_SHORT).show(); getActivity().finish(); return v; } Intent gattServiceIntent = new Intent(getActivity(), RBLService.class); // bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); getActivity().bindService(gattServiceIntent, mServiceConnection, getActivity().BIND_AUTO_CREATE); /** * Update settings according to default UI */ updateScreenLayout(); // updatePowerThresholds(); // updatePower(); if (BloomSingleton.getInstance().connState) { setButtonEnable(); updateBloomRGB(); } return v; }
From source file:br.liveo.ndrawer.ui.activity.MainActivity.java
License:asdf
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @Override//from ww w. j a v a2s . c om public void onInt(Bundle savedInstanceState) { // User Information this.userName.setText("DoubleS"); this.userEmail.setText("onlyboys@kaist.ac.kr"); this.userPhoto.setImageResource(R.drawable.ic_rudsonlive); this.userBackground.setImageResource(R.drawable.ic_user_background_first); // Creating items navigation mHelpLiveo = new HelpLiveo(); mHelpLiveo.add("", R.drawable.tracking); // mHelpLiveo.add("", R.drawable.recommend); mHelpLiveo.add("?", R.drawable.steal); mHelpLiveo.add("?", R.drawable.enroll); mHelpLiveo.add("", R.drawable.setting); with(this).startingPosition(startingPosition) //Starting position in the list .addAllHelpItem(mHelpLiveo.getHelp()) .colorItemSelected(R.color.nliveo_blue_colorPrimary) .colorNameSubHeader(R.color.nliveo_blue_colorPrimary) .setOnClickUser(onClickPhoto).setOnPrepareOptionsMenu(onPrepare).build(); int position = this.getCurrentPosition(); this.setElevationToolBar(position != 2 ? 15 : 0); //-- shobeat_add 20/Oct/15 // BLE BluetoothManager LEManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = LEManager.getAdapter(); // BLE Callback method /* mLeScanCallback = new BluetoothAdapter.LeScanCallback(){ public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord){ //String msg = "NAME=" + device.getName() + "ADDRESS=" + device.getAddress() + "\nRSSI=" + rssi; //Log.d("BLE", msg); // TODO: local? arraylist ? for(int i = 0; i < mDeviceList.size(); i++){ if(device.getAddress().equals(mDeviceList.get(i).getBdAddr())) { mDeviceList.get(i).setRssi(rssi); mDeviceList.get(i).setTxPower((int)scanRecord[29]); return; } } // TODO: ? ? ? rssi ?? BeaconDevice newDevice = new BeaconDevice(device.getAddress(), device.getName(), rssi, (int)scanRecord[29]); mDeviceList.add(newDevice); } }; startTimerTask();*/ //-- shobeat_end }
From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java
protected void onCreate(Bundle savedInstanceState) { setLayout(R.layout.debugger_activity); super.onCreate(savedInstanceState); //setup frames mDisplayFrame = (FrameLayout) findViewById(R.id.display_frame); mWaitingFrame = (FrameLayout) findViewById(R.id.waiting_frame); mNothingToShowTv = (TextView) findViewById(R.id.nothing_to_show); // Setup drawer view setupDrawerContent(nvDrawer);/* w ww . j av a2s . c o m*/ filters = new Filters(this, "", "", "", "", ""); filters.setPacketType(prefs.getString(Constants.PREFERENCES_PACKET_TYPE_FILTER, "")); filters.setEventType(prefs.getString(Constants.PREFERENCES_EVENT_TYPE_FILTER, "")); filters.setOgf(prefs.getString(Constants.PREFERENCES_OGF_FILTER, "")); filters.setSubEventType(prefs.getString(Constants.PREFERENCES_SUBEVENT_FILTERS, "")); filters.setAddress(prefs.getString(Constants.PREFERENCES_ADVERTISING_ADDR, "")); mMaxPacketCount = prefs.getInt(Constants.PREFERENCES_MAX_PACKET_COUNT, Constants.DEFAULT_LAST_PACKET_COUNT); mScanType = ScanType.getScanType(prefs.getString(Constants.PREFERENCES_SCAN_TYPE, "")); mBtSnoopFilePath = prefs.getString(Constants.PREFERENCES_BTSNOOP_FILEPATH, getHciLogFilePath()); // init Bluetooth adapter final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); //init recycler view packetListView = (CustomRecyclerView) findViewById(R.id.packet_list); packetList = new ArrayList<>(); packetAdapter = new PacketAdapter(packetList, this, new IViewHolderClickListener() { @Override public void onClick(View view) { int index = packetListView.getChildAdapterPosition(view); //launch packet description activity Intent intent = new Intent(HciDebuggerActivity.this, DescriptionActivity.class); if (packetFilteredList.size() != 0) { intent.putExtra(Constants.INTENT_HCI_PACKET, packetFilteredList.get(index).getJsonFormattedHciPacket()); intent.putExtra(Constants.INTENT_SNOOP_PACKET, packetFilteredList.get(index).getJsonFormattedSnoopPacket()); intent.putExtra(Constants.INTENT_PACKET_NUMBER, packetFilteredList.get(index).getNum()); intent.putExtra(Constants.INTENT_PACKET_TS, timestampFormat.format(packetFilteredList.get(index).getTimestamp().getTime())); intent.putExtra(Constants.INTENT_PACKET_TYPE, packetFilteredList.get(index).getDisplayedType()); intent.putExtra(Constants.INTENT_PACKET_DEST, packetFilteredList.get(index).getDest().toString()); } else { intent.putExtra(Constants.INTENT_HCI_PACKET, packetList.get(index).getJsonFormattedHciPacket()); intent.putExtra(Constants.INTENT_SNOOP_PACKET, packetList.get(index).getJsonFormattedSnoopPacket()); intent.putExtra(Constants.INTENT_PACKET_NUMBER, packetList.get(index).getNum()); intent.putExtra(Constants.INTENT_PACKET_TS, timestampFormat.format(packetList.get(index).getTimestamp().getTime())); intent.putExtra(Constants.INTENT_PACKET_TYPE, packetList.get(index).getDisplayedType()); intent.putExtra(Constants.INTENT_PACKET_DEST, packetList.get(index).getDest().toString()); } startActivity(intent); } }); //set layout manager packetListView.setLayoutManager(new GridLayoutManager(this, 1, LinearLayoutManager.VERTICAL, false)); //set line decoration packetListView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext())); packetListView.setAdapter(packetAdapter); //setup swipe refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(); } }); //setup floating button final FloatingActionButton upFloatingBtn = (FloatingActionButton) findViewById(R.id.updown_btn); upFloatingBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Click action if (floatBtnDown) { packetListView.scrollToPosition(packetListView.getAdapter().getItemCount() - 1); floatBtnDown = false; upFloatingBtn.setImageResource(R.drawable.ic_arrow_upward); } else { packetListView.scrollToPosition(0); floatBtnDown = true; upFloatingBtn.setImageResource(R.drawable.ic_arrow_downward); } } }); if (Build.VERSION.SDK_INT >= 23) { if (checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_PERMISSION_READ_EXTERNAL); } else { bindService(); } } else { bindService(); } }