Android Bluetooth: ArrayAdapter doesnt fill . (Spinner)
This code doesnt work, It should appear all devices in spinner. I Include Manifest code , mRecieve and Oncreate.
My Manifest Code:
`<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />`
My mReceiver:
`private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
String deviceHardwareAddress = device.getAddress();
spinnerArrayAdapter.add(deviceName+ "n"+deviceHardwareAddress);
spinnerArrayAdapter.notifyDataSetChanged();
}
}`
My On Create :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
spinner_bluetooth_list = findViewById(R.id.spinner);
txt_password = findViewById(R.id.txt_password);
txt_mac_address = findViewById(R.id.txt_mac_address);
spinnerArrayAdapter = new ArrayAdapter(SettingsActivity.this, android.R.layout.simple_list_item_1);
spinner_bluetooth_list.setAdapter(spinnerArrayAdapter);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
}

add a comment |
This code doesnt work, It should appear all devices in spinner. I Include Manifest code , mRecieve and Oncreate.
My Manifest Code:
`<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />`
My mReceiver:
`private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
String deviceHardwareAddress = device.getAddress();
spinnerArrayAdapter.add(deviceName+ "n"+deviceHardwareAddress);
spinnerArrayAdapter.notifyDataSetChanged();
}
}`
My On Create :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
spinner_bluetooth_list = findViewById(R.id.spinner);
txt_password = findViewById(R.id.txt_password);
txt_mac_address = findViewById(R.id.txt_mac_address);
spinnerArrayAdapter = new ArrayAdapter(SettingsActivity.this, android.R.layout.simple_list_item_1);
spinner_bluetooth_list.setAdapter(spinnerArrayAdapter);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
}

Please share more source code.
– Mad code
Nov 20 '18 at 3:00
It would be much easier to understand what's going on if your code was properly formatted
– Andrey Busik
Nov 20 '18 at 4:35
yes i have. . and i call startdiscovery
– Sigrid Langenberg
Nov 22 '18 at 0:06
add a comment |
This code doesnt work, It should appear all devices in spinner. I Include Manifest code , mRecieve and Oncreate.
My Manifest Code:
`<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />`
My mReceiver:
`private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
String deviceHardwareAddress = device.getAddress();
spinnerArrayAdapter.add(deviceName+ "n"+deviceHardwareAddress);
spinnerArrayAdapter.notifyDataSetChanged();
}
}`
My On Create :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
spinner_bluetooth_list = findViewById(R.id.spinner);
txt_password = findViewById(R.id.txt_password);
txt_mac_address = findViewById(R.id.txt_mac_address);
spinnerArrayAdapter = new ArrayAdapter(SettingsActivity.this, android.R.layout.simple_list_item_1);
spinner_bluetooth_list.setAdapter(spinnerArrayAdapter);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
}

This code doesnt work, It should appear all devices in spinner. I Include Manifest code , mRecieve and Oncreate.
My Manifest Code:
`<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />`
My mReceiver:
`private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
String deviceHardwareAddress = device.getAddress();
spinnerArrayAdapter.add(deviceName+ "n"+deviceHardwareAddress);
spinnerArrayAdapter.notifyDataSetChanged();
}
}`
My On Create :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
spinner_bluetooth_list = findViewById(R.id.spinner);
txt_password = findViewById(R.id.txt_password);
txt_mac_address = findViewById(R.id.txt_mac_address);
spinnerArrayAdapter = new ArrayAdapter(SettingsActivity.this, android.R.layout.simple_list_item_1);
spinner_bluetooth_list.setAdapter(spinnerArrayAdapter);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
}


edited Nov 21 '18 at 1:51
Sigrid Langenberg
asked Nov 20 '18 at 1:36
Sigrid LangenbergSigrid Langenberg
45
45
Please share more source code.
– Mad code
Nov 20 '18 at 3:00
It would be much easier to understand what's going on if your code was properly formatted
– Andrey Busik
Nov 20 '18 at 4:35
yes i have. . and i call startdiscovery
– Sigrid Langenberg
Nov 22 '18 at 0:06
add a comment |
Please share more source code.
– Mad code
Nov 20 '18 at 3:00
It would be much easier to understand what's going on if your code was properly formatted
– Andrey Busik
Nov 20 '18 at 4:35
yes i have. . and i call startdiscovery
– Sigrid Langenberg
Nov 22 '18 at 0:06
Please share more source code.
– Mad code
Nov 20 '18 at 3:00
Please share more source code.
– Mad code
Nov 20 '18 at 3:00
It would be much easier to understand what's going on if your code was properly formatted
– Andrey Busik
Nov 20 '18 at 4:35
It would be much easier to understand what's going on if your code was properly formatted
– Andrey Busik
Nov 20 '18 at 4:35
yes i have. . and i call startdiscovery
– Sigrid Langenberg
Nov 22 '18 at 0:06
yes i have. . and i call startdiscovery
– Sigrid Langenberg
Nov 22 '18 at 0:06
add a comment |
2 Answers
2
active
oldest
votes
I did not get what you're trying to do
Firstly be sure that you sent IntentFilter to this BroadCast
if you do not this snippet will help you
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(broadcastReceiver, filter);
if the first step is done then be sure you have already started the discovery
mBluetoothAdapter.startDiscovery();
and do not forget when you finished (to not get involved in performance issues)
mBluetoothAdapter.cancelDiscovery();
Ensure declaring all permissions that required for what you want .
if the previous steps did not solve your problem please describe your problem in more details because your problem is blurred.
see updated post
– Sigrid Langenberg
Nov 21 '18 at 5:23
listen to me you did not start Discovery try using mBluetoothAdapter.startDiscovery();
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:37
do you have an facebook account ? if you want i have a group in Facebook for only android developers in java and there are a lot of professionals
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:41
yes i have facebook. and i start Discovery and it still doesnt work.
– Sigrid Langenberg
Nov 22 '18 at 0:07
Okay post the whole code of this activity. try next time to share more detailed problem.
– Moahemd Abdelkhaleq
Nov 22 '18 at 6:13
|
show 6 more comments
Shouldn't you invoke notifyDataSetChanged()
for Adapter
?
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
spinnerArrayAdapter.add(bluetoothDevice.getName() + "n"
+ bluetoothDevice.getAddress());
spinnerArrayAdapter.notifyDataSetChanged() //OVER HERE!
}
}
};
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385023%2fandroid-bluetooth-arrayadapter-doesnt-fill-spinner%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I did not get what you're trying to do
Firstly be sure that you sent IntentFilter to this BroadCast
if you do not this snippet will help you
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(broadcastReceiver, filter);
if the first step is done then be sure you have already started the discovery
mBluetoothAdapter.startDiscovery();
and do not forget when you finished (to not get involved in performance issues)
mBluetoothAdapter.cancelDiscovery();
Ensure declaring all permissions that required for what you want .
if the previous steps did not solve your problem please describe your problem in more details because your problem is blurred.
see updated post
– Sigrid Langenberg
Nov 21 '18 at 5:23
listen to me you did not start Discovery try using mBluetoothAdapter.startDiscovery();
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:37
do you have an facebook account ? if you want i have a group in Facebook for only android developers in java and there are a lot of professionals
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:41
yes i have facebook. and i start Discovery and it still doesnt work.
– Sigrid Langenberg
Nov 22 '18 at 0:07
Okay post the whole code of this activity. try next time to share more detailed problem.
– Moahemd Abdelkhaleq
Nov 22 '18 at 6:13
|
show 6 more comments
I did not get what you're trying to do
Firstly be sure that you sent IntentFilter to this BroadCast
if you do not this snippet will help you
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(broadcastReceiver, filter);
if the first step is done then be sure you have already started the discovery
mBluetoothAdapter.startDiscovery();
and do not forget when you finished (to not get involved in performance issues)
mBluetoothAdapter.cancelDiscovery();
Ensure declaring all permissions that required for what you want .
if the previous steps did not solve your problem please describe your problem in more details because your problem is blurred.
see updated post
– Sigrid Langenberg
Nov 21 '18 at 5:23
listen to me you did not start Discovery try using mBluetoothAdapter.startDiscovery();
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:37
do you have an facebook account ? if you want i have a group in Facebook for only android developers in java and there are a lot of professionals
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:41
yes i have facebook. and i start Discovery and it still doesnt work.
– Sigrid Langenberg
Nov 22 '18 at 0:07
Okay post the whole code of this activity. try next time to share more detailed problem.
– Moahemd Abdelkhaleq
Nov 22 '18 at 6:13
|
show 6 more comments
I did not get what you're trying to do
Firstly be sure that you sent IntentFilter to this BroadCast
if you do not this snippet will help you
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(broadcastReceiver, filter);
if the first step is done then be sure you have already started the discovery
mBluetoothAdapter.startDiscovery();
and do not forget when you finished (to not get involved in performance issues)
mBluetoothAdapter.cancelDiscovery();
Ensure declaring all permissions that required for what you want .
if the previous steps did not solve your problem please describe your problem in more details because your problem is blurred.
I did not get what you're trying to do
Firstly be sure that you sent IntentFilter to this BroadCast
if you do not this snippet will help you
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(broadcastReceiver, filter);
if the first step is done then be sure you have already started the discovery
mBluetoothAdapter.startDiscovery();
and do not forget when you finished (to not get involved in performance issues)
mBluetoothAdapter.cancelDiscovery();
Ensure declaring all permissions that required for what you want .
if the previous steps did not solve your problem please describe your problem in more details because your problem is blurred.
answered Nov 20 '18 at 3:08


Moahemd AbdelkhaleqMoahemd Abdelkhaleq
236
236
see updated post
– Sigrid Langenberg
Nov 21 '18 at 5:23
listen to me you did not start Discovery try using mBluetoothAdapter.startDiscovery();
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:37
do you have an facebook account ? if you want i have a group in Facebook for only android developers in java and there are a lot of professionals
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:41
yes i have facebook. and i start Discovery and it still doesnt work.
– Sigrid Langenberg
Nov 22 '18 at 0:07
Okay post the whole code of this activity. try next time to share more detailed problem.
– Moahemd Abdelkhaleq
Nov 22 '18 at 6:13
|
show 6 more comments
see updated post
– Sigrid Langenberg
Nov 21 '18 at 5:23
listen to me you did not start Discovery try using mBluetoothAdapter.startDiscovery();
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:37
do you have an facebook account ? if you want i have a group in Facebook for only android developers in java and there are a lot of professionals
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:41
yes i have facebook. and i start Discovery and it still doesnt work.
– Sigrid Langenberg
Nov 22 '18 at 0:07
Okay post the whole code of this activity. try next time to share more detailed problem.
– Moahemd Abdelkhaleq
Nov 22 '18 at 6:13
see updated post
– Sigrid Langenberg
Nov 21 '18 at 5:23
see updated post
– Sigrid Langenberg
Nov 21 '18 at 5:23
listen to me you did not start Discovery try using mBluetoothAdapter.startDiscovery();
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:37
listen to me you did not start Discovery try using mBluetoothAdapter.startDiscovery();
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:37
do you have an facebook account ? if you want i have a group in Facebook for only android developers in java and there are a lot of professionals
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:41
do you have an facebook account ? if you want i have a group in Facebook for only android developers in java and there are a lot of professionals
– Moahemd Abdelkhaleq
Nov 21 '18 at 15:41
yes i have facebook. and i start Discovery and it still doesnt work.
– Sigrid Langenberg
Nov 22 '18 at 0:07
yes i have facebook. and i start Discovery and it still doesnt work.
– Sigrid Langenberg
Nov 22 '18 at 0:07
Okay post the whole code of this activity. try next time to share more detailed problem.
– Moahemd Abdelkhaleq
Nov 22 '18 at 6:13
Okay post the whole code of this activity. try next time to share more detailed problem.
– Moahemd Abdelkhaleq
Nov 22 '18 at 6:13
|
show 6 more comments
Shouldn't you invoke notifyDataSetChanged()
for Adapter
?
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
spinnerArrayAdapter.add(bluetoothDevice.getName() + "n"
+ bluetoothDevice.getAddress());
spinnerArrayAdapter.notifyDataSetChanged() //OVER HERE!
}
}
};
add a comment |
Shouldn't you invoke notifyDataSetChanged()
for Adapter
?
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
spinnerArrayAdapter.add(bluetoothDevice.getName() + "n"
+ bluetoothDevice.getAddress());
spinnerArrayAdapter.notifyDataSetChanged() //OVER HERE!
}
}
};
add a comment |
Shouldn't you invoke notifyDataSetChanged()
for Adapter
?
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
spinnerArrayAdapter.add(bluetoothDevice.getName() + "n"
+ bluetoothDevice.getAddress());
spinnerArrayAdapter.notifyDataSetChanged() //OVER HERE!
}
}
};
Shouldn't you invoke notifyDataSetChanged()
for Adapter
?
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
spinnerArrayAdapter.add(bluetoothDevice.getName() + "n"
+ bluetoothDevice.getAddress());
spinnerArrayAdapter.notifyDataSetChanged() //OVER HERE!
}
}
};
answered Nov 20 '18 at 4:17
Andrey BusikAndrey Busik
6113
6113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385023%2fandroid-bluetooth-arrayadapter-doesnt-fill-spinner%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please share more source code.
– Mad code
Nov 20 '18 at 3:00
It would be much easier to understand what's going on if your code was properly formatted
– Andrey Busik
Nov 20 '18 at 4:35
yes i have. . and i call startdiscovery
– Sigrid Langenberg
Nov 22 '18 at 0:06