[text] Код блютуз чат

Viewer

copydownloadembedprintName: Код блютуз чат
  1. import android.bluetooth.BluetoothAdapter;
  2. import android.bluetooth.BluetoothDevice;
  3. import android.bluetooth.BluetoothServerSocket;
  4. import android.bluetooth.BluetoothSocket;
  5. import android.content.Intent;
  6. import android.graphics.Bitmap;
  7. import android.net.Uri;
  8. import android.provider.MediaStore;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.os.Bundle;
  11. import android.view.View;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.ImageView;
  15. import android.widget.Toast;
  16.  
  17. import java.io.IOException;
  18. import java.util.UUID;
  19.  
  20. public class MainActivity extends AppCompatActivity {
  21.  
  22.     private EditText etName;
  23.     private Button btnChangeName, btnAddPhoto, btnStartServer, btnStartClient, btnSend;
  24.     private ImageView ivProfile;
  25.  
  26.     private BluetoothAdapter bluetoothAdapter;
  27.     private BluetoothDevice device;
  28.     private BluetoothServerSocket serverSocket;
  29.     private BluetoothSocket socket;
  30.  
  31.     private static final int PICK_IMAGE = 1;
  32.     private static final int REQUEST_ENABLE_BT = 0;
  33.  
  34.     private final UUID uuid = UUID.fromString("3e14d6a3-6dde-4ee2-86d7-619e99b38345");
  35.  
  36.     @Override
  37.     protected void onCreate(Bundle savedInstanceState) {
  38.         super.onCreate(savedInstanceState);
  39.         setContentView(R.layout.activity_main);
  40.  
  41.         etName = (EditText) findViewById(R.id.etName);
  42.         btnChangeName = (Button) findViewById(R.id.btnChangeName);
  43.         btnAddPhoto = (Button) findViewById(R.id.btnAddPhoto);
  44.         ivProfile = (ImageView) findViewById(R.id.ivProfile);
  45.         btnStartServer = (Button) findViewById(R.id.btnStartServer);
  46.         btnStartClient = (Button) findViewById(R.id.btnStartClient);
  47.         btnSend = (Button) findViewById(R.id.btnSend);
  48.  
  49.         bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  50.         if (bluetoothAdapter == null) {
  51.             Toast.makeText(this, "Bluetooth not supported", Toast.LENGTH_SHORT).show();
  52.         }
  53.  
  54.         btnChangeName.setOnClickListener(new View.OnClickListener() {
  55.             @Override
  56.             public void onClick(View v) {
  57.                 String name = etName.getText().toString();
  58.                 if (name.isEmpty()) {
  59.                     Toast.makeText(MainActivity.this, "Enter a valid name", Toast.LENGTH_SHORT).show();
  60.                 } else {
  61.                     // Change the name of the user
  62.                 }
  63.             }
  64.         });
  65.  
  66.         btnAddPhoto.setOnClickListener(new View.OnClickListener() {
  67.             @Override
  68.             public void onClick(View v) {
  69.                
  70.  

Editor

You can edit this paste and save as new:


File Description
  • Код блютуз чат
  • Paste Code
  • 03 Feb-2023
  • 2.56 Kb
You can Share it: