简体   繁体   中英

Connect laptop and android via bluetooth

Hi I want to connect bluetooth and laptop

What I want to do is, send numeric value from android application to Labview program installed in Laptop.

The android program returns value which changes according to the button click.

(When I press up button, value +1).

And I want to send this value to the laptop via bluetooth!.

I was looking for google, stackoverflow and other many communities., I couldn't find any hints or solutions.

package com.u2ring.control;

import com.u2ring.control.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.webkit.*;


public class MainActivity extends Activity implements OnClickListener
{
Button Plus, Minus;
TextView Value;
TextView url;
int score = 0;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Plus = (Button) findViewById(R.id.up);
Minus = (Button) findViewById(R.id.down);

Value = (TextView) findViewById(R.id.number);

String host = getString(R.string.host);

Plus.setOnClickListener(this);
Minus.setOnClickListener(this);
Button bt1 = (Button) findViewById(R.id.button2);
bt1.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
        Intent in = new Intent(MainActivity.this,Secondpage.class);
        startActivity(in);
        }
});};




public void onClick(View v)
{
boolean showText = false;

int id = v.getId();
if (id == R.id.up) {
    score++;
    showText = true;
} else if (id == R.id.down) {
    score--;
    showText = true;
} else if (id == R.id.number) {
    showText = true;
}
if(showText)
Value.setText(String.valueOf(score));

WebView wv= (WebView) findViewById(R.id.web);
wv.loadUrl("http://10.16.27.184:8080/admin/speed/"+Integer.toString(score));
}
}

You will need to connect the laptop and the phone over bluetooth first either manually or create a service. Android provides access to your phone's Bluetooth through BluetoothAdapter . To access the BluetoothAdapter you will need to add the appropriate permission(for bluetooth) in the manifest file.
You can then manage connections through the different methods of the BluetoothAdapter .For details visit here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM