1. Are you ready for the Galaxy S20? Here is everything we know so far!

Android Studio

Discussion in 'Android Development' started by VaggelisKout, Mar 30, 2021.

  1. VaggelisKout

    VaggelisKout Lurker
    Thread Starter

    Hello, I am new here. I hope someone knows anything on Android Studio and Java. I want to create an application for controlling a LED strip with Arduino. I want to make several buttons. but i cant figure out how to write it! If anyone knows please contact me!
     



    1. Download the Forums for Android™ app!


      Download

       
  2. VaggelisKout

    VaggelisKout Lurker
    Thread Starter

    Hello, i am new here and also new in android studio. i have some knowledge in java, c++ but it has some time since that. so i am trying to make an application in order to control a led strip via android. i found a project at instructables that it is very close to what i want to make. the problem is that this project is from 2015. i am trying to troubleshoot the code but i am not so good at it. now it shows me an error here:

    Code (Text):
    1. error: illegal start of type
    2.  
    3.     if (myBluetooth == null){
    4.  
    5.     ^
    6.  
    any thoughts???? Thank you very much!




    Code (Text):
    1.  
    2. package com.example.devicelist;
    3.  
    4.  
    5.  
    6. import androidx.appcompat.app.AppCompatActivity;
    7.  
    8. import android.os.Bundle;
    9.  
    10. import android.view.View;
    11.  
    12. import android.widget.Button;
    13.  
    14. import android.widget.ListView;
    15.  
    16.  
    17.  
    18. import java.io_OutputStream;
    19.  
    20. import java.util.Set;
    21.  
    22. import java.util.ArrayList;
    23.  
    24.  
    25.  
    26. import android.widget.Toast;
    27.  
    28. import android.widget.ArrayAdapter;
    29.  
    30. import android.widget.AdapterView;
    31.  
    32. import android.view.View.OnClickListener;
    33.  
    34. import android.widget.TextView;
    35.  
    36. import android.content.Intent;
    37.  
    38. import android.bluetooth.BluetoothAdapter;
    39.  
    40. import android.bluetooth.BluetoothDevice;
    41.  
    42.  
    43.  
    44.  
    45.  
    46.  
    47.  
    48. public class DeviceList extends AppCompatActivity implements OnClickListener {
    49.  
    50.     //widgets
    51.  
    52.     private Button btnPaired;
    53.  
    54.     private ListView devicelist;
    55.  
    56.     //bluetooth
    57.  
    58.     private BluetoothAdapter myBluetooth = null;
    59.  
    60.     private Set<BluetoothDevice> pairedDevices;
    61.  
    62.     private OutputStream outStream = null;
    63.  
    64.     public static String EXTRA_ADDRESS = "device_address";
    65.  
    66.  
    67.  
    68.     //if the device has bluetooth
    69.  
    70.     BluetoothAdapter myBluetooth = BluetoothAdapter.getDefaultAdapter();
    71.  
    72.  
    73.  
    74.     if (myBluetooth == null){
    75.  
    76.         //Show a mensag. that the device has no bluetooth adapter
    77.  
    78.         Toast.makeText(getApplicationContext(), "Bluetooth Device not Available", Toast.LENGTH_LONG).show();
    79.  
    80.         //finish apk
    81.  
    82.         finish();
    83.  
    84.     }
    85.  
    86.     else if (!myBluetooth.isEnabled()){
    87.  
    88.         //Ask the user to turn on the bluetooth
    89.  
    90.         Intent turnBTon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    91.  
    92.         startActivityForResult(turnBTon, 1);
    93.  
    94.     }
     
    #2 VaggelisKout, Mar 30, 2021
    Last edited by a moderator: Mar 30, 2021
  3. codesplice

    codesplice Elite Recognized Moderator
    Moderator

    I'm afraid I won't be able to help with your coding question but I wanted to let you know that I added some [code]...[/code] tags to your post to make the content a bit easier to parse.
     
Loading...
Similar Threads - Android Studio
  1. IvanMathias2021
    Replies:
    1
    Views:
    228
  2. willy macharia
    Replies:
    0
    Views:
    207
  3. Lukas Petrikas
    Replies:
    2
    Views:
    510
  4. cipango
    Replies:
    0
    Views:
    278
  5. Kaplah
    Replies:
    1
    Views:
    406
  6. Ginjitzu
    Replies:
    0
    Views:
    338
  7. ofis berr
    Replies:
    0
    Views:
    191
  8. Anand Suthar
    Replies:
    1
    Views:
    441
  9. Leoard
    Replies:
    0
    Views:
    386
  10. Dmit84
    Replies:
    1
    Views:
    503

Share This Page

Loading...