Whenever I start/resume my android phone app, it will prompt me to enable my bluetooth twice, regardless what I choose on the first prompt message. What is wrong with my code?
public class MainActivity extends AppCompatActivity {
// BLE management
private static BluetoothManager btManager;
private static BluetoothAdapter btAdapter;
// Set the enable bluetooth code
private final static int REQUEST_ENABLE_BT = 0;
// String for LogCat documentation
private final static String DEBUG_TAG= "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
btAdapter = btManager.getAdapter();
if (btAdapter != null) {
if (!btAdapter.isEnabled()) {
// Request Bluetooth Adapter to be turned on
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
}
}
else
{
Log.i(DEBUG_TAG, "No bluetooth available");
}
Button launchReminderButton = (Button) findViewById(R.id.button);
launchReminderButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Launch Reminder
// Used Context's startActivity() method
// Create an intent stating which Activity you would like to
// start
Intent reminder = new Intent(MainActivity.this, Reminder.class);
// Launch the Activity using the intent
startActivity(reminder);
}
}
);
}
#Override
public void onStart() {
super.onStart();
}
#Override
public void onResume() {
super.onResume();
// check for Bluetooth enabled on each resume
if(btAdapter != null && !btAdapter.isEnabled()){
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
}
}
#Override
public void onPause() {
super.onPause();
}
#Override
public void onStop() {
super.onStop();
}
#Override
public void onRestart() {
super.onRestart();
}
#Override
public void onDestroy() {
super.onDestroy();
btAdapter = null;
}
#Override
protected void onActivityResult(int request_enable_bt, int result_enable_bt, Intent data)
{
super.onActivityResult(request_enable_bt, result_enable_bt, data);
if(result_enable_bt == RESULT_OK) {
Toast.makeText(this, "Turned On", Toast.LENGTH_SHORT).show();
}
else if (result_enable_bt == RESULT_CANCELED)
{
Toast.makeText(this, "Didn't Turn On", Toast.LENGTH_SHORT).show();
finish();
}
}
Thanks.
Pay attention to the following code,the key is finish() you used here:
#Override
protected void onActivityResult(int request_enable_bt,
int result_enable_bt, Intent data)
{
super.onActivityResult(request_enable_bt, result_enable_bt, data);
if (result_enable_bt == RESULT_OK)
{
Toast.makeText(this, "Turned On", Toast.LENGTH_SHORT).show();
}
else if (result_enable_bt == RESULT_CANCELED)
{
Toast.makeText(this, "Didn't Turn On", Toast.LENGTH_SHORT).show();
finish();
}
}
When you start your app,the system will remind you to turn on your Bluetooth,because your request Bluetooth on in onCreate method.When you deny the request, and the method onActivityResult call back,you will run the following code:
else if (result_enable_bt == RESULT_CANCELED)
{
Toast.makeText(this, "Didn't Turn On", Toast.LENGTH_SHORT).show();
finish();
}
The finish() will finish your Activity,every time when you click your app,when you click deny first time,and then you click deny second time.Every time you got this: onCreate -> onResume.So you get the request to enable your Bluetooth twice!
Related
I'm currently working on an android app to control Bluetooth devices but no available devices show up even though I can find them from the built-in settings>bluetooth menu.
I initially followed the android starter sample out of the box, but couldn't make it work. I then came across several similar posts and tried those as well, but still couldn't make it work. This is my code so far: ```
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_LOCATION_BT = 3;
private static final int REQUEST_ENABLE_BT = 2;
private BluetoothAdapter bluetoothAdapter;
private ArrayList<String> deviceList;
private ActivityMainBinding binding;
private ArrayAdapter<String> listAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
requiredSetup();
setupListView();
}
private void setupListView() {
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
deviceList = new ArrayList<>();
if (pairedDevices.size() > 0) {
// There are paired devices. Get the name and address of each paired device.
for (BluetoothDevice device : pairedDevices) {
deviceList.add(device.getName());
//String deviceHardwareAddress = device.getAddress(); // MAC address
}
}
listAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, deviceList);
binding.listView.setAdapter(listAdapter);
}
private void requiredSetup() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(getApplicationContext(),
Manifest.permission.ACCESS_BACKGROUND_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
MainActivity.this,
new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},
REQUEST_LOCATION_BT);
}
}
// checking if device supports bluetooth
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
// Device doesn't support Bluetooth
Toast.makeText(this, "Device doesnt support bluetooth", Toast.LENGTH_SHORT).show();
return;
}
// enabling bluetooth if disabled
if (!bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_ENABLE_BT && resultCode == RESULT_OK) {
Toast.makeText(this, "Bluetooth enabled", Toast.LENGTH_SHORT).show();
} else if (requestCode == REQUEST_ENABLE_BT && resultCode == RESULT_CANCELED) {
Toast.makeText(this, "App requires bluetooth to function", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String permissions[], #NonNull int[] grantResults) {
if (requestCode == REQUEST_LOCATION_BT) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted, yay! Start the Bluetooth device scan.
startScan();
} else {
// Alert the user that this application requires the location permission to perform the scan.
Toast.makeText(this, "Requires location permission to work", Toast.LENGTH_SHORT).show();
}
}
}
/**
* initializes device discovery. The list of devices are sent to the broadcast receiver
* The discovery process usually involves an inquiry scan of about 12 seconds,
* followed by a page scan of each device found to retrieve its Bluetooth name.
*/
private void startScan() {
// If we're already discovering, stop it
if (bluetoothAdapter.isDiscovering()) {
Toast.makeText(this, "stopping discovery", Toast.LENGTH_SHORT).show();
bluetoothAdapter.cancelDiscovery();
} else {
try {
// Register for broadcasts when a device is discovered
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
this.registerReceiver(mReceiver, filter);
// Request discover from BluetoothAdapter
bluetoothAdapter.startDiscovery();
binding.progressBar.setVisibility(View.VISIBLE);
} catch (IllegalArgumentException e) {
e.printStackTrace();
Toast.makeText(this, "receivers not registered", Toast.LENGTH_SHORT).show();
}
}
}
/**
* #param view the button view that is pressed and the scanning begins
*/
public void searchDevices(View view) {
// checking if location permissions enabled
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_LOCATION_BT);
} else {
startScan();
}
}
/**
* The BroadcastReceiver that listens for discovered devices and changes the title when
* discovery is finished
*/
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Toast.makeText(getApplicationContext(), "reeiver working", Toast.LENGTH_SHORT).show();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// If it's already paired, skip it, because it's been listed already
if (device != null && device.getBondState() != BluetoothDevice.BOND_BONDED) {
listAdapter.add(device.getName() + "\n" + device.getAddress());
Log.i("NEW DEVICE", device.getName());
listAdapter.notifyDataSetChanged();
}
// When discovery is finished, change the Activity title
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
//setProgressBarIndeterminateVisibility(false);
//setTitle(R.string.select_device);
binding.progressBar.setVisibility(View.INVISIBLE);
if (listAdapter.getCount() == 0) {
Toast.makeText(context, "no devices found", Toast.LENGTH_SHORT).show();
}
} else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
Toast.makeText(context, "Bluetooth state changed", Toast.LENGTH_SHORT).show();
} else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
Toast.makeText(context, "Discovery started", Toast.LENGTH_SHORT).show();
}
}
};
#Override
protected void onDestroy() {
super.onDestroy();
// Make sure we're not doing discovery anymore
if (bluetoothAdapter != null) {
bluetoothAdapter.cancelDiscovery();
}
// Unregister broadcast listeners
this.unregisterReceiver(mReceiver);
}}
This is my manifest permissions:
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
This is my repository. It would be very helpful if anyone could shed some light here.
It seems like the code was just fine. The problem was with the target SDK version. Upon changing the version from 30 to 28, it worked. Thanks to MatejC's answer.
I have an app used for Bluetooth control of an embedded system using the SPP protocol that has worked fine until Marshmallow. If Bluetooth is enabled when I start the app everything is good. I use startActivityForResult() to prompt the user to allow Bluetooth to be enabled if it's not already. It used to block until a result was given but under Marshmallow it blows through it and crashes immediately with a null pointer exception. I added a "hack" in onResume() to keep it from doing this by returning if not enabled, but am wondering if this is poor practice?
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null) {
Toast.makeText(getApplicationContext(), "No bluetooth detected", Toast.LENGTH_SHORT).show();
finish();
} else {
if (!btAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, ENABLE_BT_REQUEST_CODE);
}
}
}
#Override
public void onResume() {
super.onResume();
/* This keeps from crashing immediately if BT not enabled */
if (!btAdapter.isEnabled()) {
return;
};
if (btAdapter.isDiscovering()) {
btAdapter.cancelDiscovery();
}
// Rest of code .......
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Check Result from turnOnBT()
if (requestCode == ENABLE_BT_REQUEST_CODE) {
if (resultCode == RESULT_CANCELED) {
Toast.makeText(getApplicationContext(), "Bluetooth must be enabled to continue", Toast.LENGTH_SHORT).show();
finish();
}
}
}
I made a chatbot using online tutorial, Now apart from writing in edit text as input I am using voice recognition also. but the problem is the tts do not work when I am pressing the voice recognition button. I dont know what is the problem I used various methods. tts works fine while sending text from edit text field. here is the sample for two codes in main activity. First code is for sending text via send button and works fine. Second code is the wone I use stt to chat and tts do not work. Need help to fix the problem. Thanks in advance.
public class MainActivity extends AppCompatActivity {
private ListView mListView;
private FloatingActionButton mButtonSend;
private EditText mEditTextMessage;
private ImageView mImageView;
public Bot bot;
public static Chat chat;
private ChatMessage.ChatMessageAdapter mAdapter;
public Button buSpeak;
public TextToSpeech tts;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR){
tts.setLanguage(Locale.US);
}
}
});
mListView = (ListView) findViewById(R.id.listView);
mButtonSend = (FloatingActionButton) findViewById(R.id.btn_send);
mEditTextMessage = (EditText) findViewById(R.id.et_message);
mImageView = (ImageView) findViewById(R.id.iv_image);
mAdapter = new ChatMessage.ChatMessageAdapter(this, new ArrayList<ChatMessage>());
mListView.setAdapter(mAdapter);
buSpeak = (Button)findViewById(R.id.buSpeak);
CheckUserPermsions();
//chat button
mButtonSend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String message = mEditTextMessage.getText().toString();
//bot
String response = chat.multisentenceRespond(mEditTextMessage.getText().toString());
if (TextUtils.isEmpty(message)) {
return;
}
sendMessage(message);
mimicOtherMessage(response);
mEditTextMessage.setText("");
mListView.setSelection(mAdapter.getCount() - 1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
tts.speak(response, TextToSpeech.QUEUE_FLUSH,null,null);
}else{
tts.speak(response, TextToSpeech.QUEUE_FLUSH,null);
}
}
});
and the code for Using voice recognition, here the tts do not work
public void buSpeak(View view) {
startVoiceRecognitionActivity();
}
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//since you only want one, only request 1
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
startActivityForResult(intent, 1234);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK){
tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR){
tts.setLanguage(Locale.US);
}
}
});
//pull all of the matches
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String topResult = matches.get(0);
EditText AutoText = (EditText) findViewById(R.id.et_message);
AutoText.setText(topResult);
String message = AutoText.getText().toString();
//bot
String response = chat.multisentenceRespond(AutoText.getText().toString());
if (TextUtils.isEmpty(response)) {
return;
}
sendMessage(message);
mimicOtherMessage(response);
AutoText.setText("");
mListView.setSelection(mAdapter.getCount() - 1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
tts.speak(response, TextToSpeech.QUEUE_FLUSH,null,null);
}else{
tts.speak(response, TextToSpeech.QUEUE_FLUSH,null);
}
}
}
public void CheckUserPermsions(){
if ( Build.VERSION.SDK_INT >= 23){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED ){
requestPermissions(new String[]{
android.Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_CODE_ASK_PERMISSIONS);
return ;
}
}
}
//get acces to location permsion
final private int REQUEST_CODE_ASK_PERMISSIONS = 123;
#Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_ASK_PERMISSIONS:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
} else {
// Permission Denied
Toast.makeText( this,"denail" , Toast.LENGTH_SHORT)
.show();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
public void onPause(){
if(tts !=null){
tts.stop();
tts.shutdown();
}
super.onPause();
}
}
just call this method and pass your text in this method
public void textToSpeech(String message){
if (result==TextToSpeech.LANG_NOT_SUPPORTED ||result==TextToSpeech.LANG_MISSING_DATA){
Toast.makeText(Activity.this, "Language is Not Supported", Toast.LENGTH_SHORT).show();
}else {
String text=message;
if (text==null||text.equals("")){
text="Text is Empty";
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
textToSpeech.speak(text,TextToSpeech.QUEUE_FLUSH,null,null);
} else {
textToSpeech.speak(text,TextToSpeech.QUEUE_FLUSH,null);
}
}
}
Okay I have solved the problem, Instead of onPause just used onDestry after tts.
and added tts.stop(); in buSpeak button method to stop tts when that button is pressed.
`Code below
public void buSpeak(View view) {
tts.stop();
startVoiceRecognitionActivity();
}
//after all other steps
public void onDestroy() {
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
There is no error in the logcat just the current activity closes down and previous activity opens.
Here is the code where am puttin bluetooth enabling request:
bt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (!(bluetooth.isEnabled())) {
Log.e("blue",""+"not working");
status = "Bluetooth is not Enabled.";
Toast.makeText(AddUser.this, status, Toast.LENGTH_SHORT).show();
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, 1);
}
else
{
scand();
}
}
});
Here is onactivityresult:
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
System.out.println(resultCode);
Log.e("resultblue",""+resultCode);
if (resultCode == RESULT_CANCELED) {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(AddUser.this, "Error Enabling bluetooth", Toast.LENGTH_LONG).show();
}
});
} else {
scand();
}
}
what could be the problem?
I'm using setVisibility() to hide some UI components at onStart(), with the aim of making them reappear under certain conditions at onActivityResult().
I have set variables as global variable, and assigned to the component at onCreate().
Code to make the component invisible works correctly, such as auth_btn.setVisibility(View.INVISIBLE);
However, at onActivityResult(), auth_btn.setVisibility(View.VISIBLE); does not make the button reappear.
Code (from pastebin in the comments):
private Button auth_btn = null;
private Button newAcc_btn = null;
private EditText mEdit = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up the window layout
setContentView(R.layout.main);
//instance of database adapter
db = new DBAdapter(this);
// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// If the adapter is null, then Bluetooth is not supported
if (mBluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
finish();
return;
}
auth_btn = (Button) findViewById(R.id.btn_auth);
mEdit = (EditText)findViewById(R.id.text_username);
newAcc_btn = (Button) findViewById(R.id.btn_newAcc);
//read every entry from database
db.load();
}
#Override
public void onStart() {
super.onStart();
// If BT is not on, request that it be enabled.
if (!mBluetoothAdapter.isEnabled()) {
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
// Otherwise, setup the session
} else {
setupSession();
}
}
private void setupSession () {
//Authenticate
auth_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
out.write(AUTHENTICATE);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
authenticate();
}
});
//Create new account
newAcc_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
try{
out.write(NEWACCOUNT);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
newAccount();
}
});
//Scan QR Code
Button scan = (Button) findViewById(R.id.btn_scan);
scan.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, SCAN_QR_CODE);
}
});
auth_btn.setVisibility(View.INVISIBLE);
newAcc_btn.setVisibility(View.INVISIBLE);
mEdit.setVisibility(View.INVISIBLE);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == SCAN_QR_CODE) {
if (resultCode == RESULT_OK) {
//Successful scan
processQR(intent.getStringExtra("SCAN_RESULT"));
//String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); //format of the code
//Toast.makeText(this, contents, Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Scan failed!", Toast.LENGTH_SHORT).show();
}
}
if (requestCode == REQUEST_ENABLE_BT) {
// When the request to enable Bluetooth returns
if (resultCode == Activity.RESULT_OK) {
// Bluetooth is now enabled, so set up a chat session
setupSession();
} else {
// User did not enable Bluetooth or an error occurred
Log.d(TAG, "BT not enabled");
Toast.makeText(this, "Bluetooth cannot be enabled", Toast.LENGTH_SHORT).show();
finish();
}
}
}
public void processQR (String content) {
String[] contents = content.split(" ");
if (contents.length != 3) {
Log.e(TAG, "Not well formed QR Code");
}
else {
appKey = contents[APPKEY];
macAdd = contents[MACADR];
my_uuid = UUID.fromString(contents[UUID_STR]);
Log.d(TAG, macAdd);
String appName = db.getAppName(appKey);
Log.d(TAG, appName);
if (appName == null)
return;
Toast.makeText(this, appName, Toast.LENGTH_SHORT).show();
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(macAdd);
try {
bt = device.createInsecureRfcommSocketToServiceRecord(my_uuid);
bt.connect();
in = bt.getInputStream();
out = bt.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
Log.d(TAG, "Set new acc visible");
mEdit = (EditText)findViewById(R.id.text_username);
mEdit.setVisibility(View.VISIBLE);
newAcc_btn.setVisibility(View.VISIBLE);
if (db.appAccounts(appKey).getCount() > 0)
auth_btn.setVisibility(View.VISIBLE);
}
}
onStart() is called each time the activity is visible. After pressing the scan button, the intent is executed, then the buttons are set to VISIBLE at onActivityResult().
After which, the activity is visible again, causing onStart() to be executed, therefore making the buttons INVISIBLE again.