Professional Documents
Culture Documents
womensecurity6
;import android.bluetooth.BluetoothAdapter
;import android.bluetooth.BluetoothDevice
;import android.bluetooth.BluetoothSocket
;import android.content.Intent
;import android.graphics.Bitmap
;import android.graphics.BitmapFactory
;import android.os.Bundle
;import android.telephony.SmsManager
;import android.util.Log
;import android.view.View
;import android.widget.Button
;import android.widget.ImageView
;import android.widget.TextView
;import com.google.firebase.auth.FirebaseAuth
;import com.google.firebase.auth.FirebaseUser
;import com.google.firebase.database.DataSnapshot
;import com.google.firebase.database.DatabaseError
;import com.google.firebase.database.DatabaseReference
;import com.google.firebase.database.FirebaseDatabase
;import com.google.firebase.database.ValueEventListener
;import com.squareup.picasso.Picasso
;import java.io.IOException
;import java.io.InputStream
;import java.io.OutputStream
;import java.util.UUID
;import androidx.annotation.NonNull
;import androidx.appcompat.app.AppCompatActivity
{ public class CommsActivity extends AppCompatActivity
public BluetoothAdapter BTAdapter =
;)(BluetoothAdapter.getDefaultAdapter
;"private static final String TAG = "CommsActivity
;BluetoothSocket mmSocket
;BluetoothDevice mmDevice
////
;FirebaseDatabase firebaseDatabase
;DatabaseReference ref1,ref2,ref3
;FirebaseUser user
;FirebaseAuth auth
;String id
;String eContact
;Double latitude,longitude
;TextView t1,t2,t3
;ImageView imageViewCAM
////
Override@
{ )protected void onCreate(Bundle savedInstanceState
;)super.onCreate(savedInstanceState
;)setContentView(R.layout.activity_comms
;)t1=(TextView)findViewById(R.id.tvContact
;)t2=(TextView)findViewById(R.id.tvLat
;)t3=(TextView)findViewById(R.id.tvLng
;)imageViewCAM = (ImageView)findViewById(R.id.imgCamera
;)(auth=FirebaseAuth.getInstance
;)(user=auth.getCurrentUser
;)(id=user.getUid
;)(firebaseDatabase=FirebaseDatabase.getInstance
ref1
)"=firebaseDatabase.getReference("Users").child(id).child("econtact
;
ref2
;)"=firebaseDatabase.getReference("Users").child(id).child("lat
ref3
;)"=firebaseDatabase.getReference("Users").child(id).child("lng
read Econtacts//
{ )(ref1.addValueEventListener(new ValueEventListener
Override@
public void onDataChange(@NonNull DataSnapshot
{ )dataSnapshot
;)eContact = dataSnapshot.getValue(String.class
;)t1.setText(eContact
}
Override@
public void onCancelled(@NonNull DatabaseError
{ )databaseError
}
;)}
read Lat//
{ )(ref2.addValueEventListener(new ValueEventListener
Override@
public void onDataChange(@NonNull DataSnapshot
{ )dataSnapshot
;)latitude = dataSnapshot.getValue(Double.class
;)""+t2.setText(latitude
}
Override@
public void onCancelled(@NonNull DatabaseError
{ )databaseError
}
;)}
read Lng//
{ )(ref3.addValueEventListener(new ValueEventListener
Override@
public void onDataChange(@NonNull DataSnapshot
{ )dataSnapshot
;)longitude = dataSnapshot.getValue(Double.class
;)""+t3.setText(longitude
}
Override@
public void onCancelled(@NonNull DatabaseError
{ )databaseError
}
;)}
BluetoothAdapter mBluetoothAdapter =
;)(BluetoothAdapter.getDefaultAdapter
;)(final Intent intent = getIntent
final String address =
;)intent.getStringExtra(BluetoothActivity.EXTRA_ADDRESS
;)Button connect = (Button) findViewById(R.id.connectBtn
{ )(connect.setOnClickListener(new View.OnClickListener
{ )public void onClick(View v
final BluetoothDevice device =
;)BTAdapter.getRemoteDevice(address
{ try
;)(new ConnectThread(device).start
{ )catch (IOException e }
;)(e.printStackTrace
}
}
;)}
{ ))(if (!mBluetoothAdapter.isEnabled
Intent enableBluetooth = new
;)Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE
;)startActivityForResult(enableBluetooth, 0
}
}
Override@
{ )(protected void onStop
;)(super.onStop
{ try
;)(mmSocket.close
{ )catch (IOException e }
;)(e.printStackTrace
}
}
connected class //
{ public class ConnectThread extends Thread
private ConnectThread(BluetoothDevice device) throws
{ IOException
;BluetoothSocket tmp = null
;mmDevice = device
{ try
UUID uuid =
;)"UUID.fromString("94f39d29-7d6d-437d-973b-fba39e49d4ee
tmp =
;)mmDevice.createRfcommSocketToServiceRecord(uuid
{ )catch (IOException e }
;)Log.e(TAG, "Socket's create() method failed", e
}
;mmSocket = tmp
;)(BTAdapter.cancelDiscovery
{ try
;)(mmSocket.connect
{ )catch (IOException connectException }
;)"!Log.v(TAG, "Connection exception
{ try
;)(mmSocket.close
{ )catch (IOException closeException }
}
}
;)(send
}
;)Picasso.get().load(readMessage).into(imageViewCAM//
} //
;)Log.d(TAG, "Received: " + readMessage
;)TextView status = (TextView) findViewById(R.id.btnState
;) status.setText("Button : "+ readMessage
;)(mmSocket.close
{ )catch (IOException e }
;)"!Log.e(TAG, "Problems occurred
;return
}
}
end of connectThread class // }