蓝牙文件或邮件传输

时间:2013-04-29 12:12:16

标签: android bluetooth

我在蓝牙文件或邮件传输过程中遇到应用程序负载问题。

我的代码如下

final ArrayList<String> todoItems = new ArrayList<String>();
    mArrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,todoItems);

    Button btnClick;

    BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
    if(bluetooth != null)
    {

        // Continue with bluetooth setup.
    }

    if (bluetooth.isEnabled()) {
        // Enabled. Work with Bluetooth.

    }
    else
    {

        // Disabled. Do something else.
    }

    String mydeviceaddress = "";
    String mydeviceaddress1 = "";
    String mydevicename = "";

    Set<BluetoothDevice> pairedDevices;
    BluetoothDevice[] pairedDevicesArray;

    String status = "";
    String FnlDeviceAdd = "";

    if (bluetooth.isEnabled()) 
    {
        try
        {
            pairedDevices = bluetooth.getBondedDevices();

               if (pairedDevices.size() > 0) {
                    // Loop through paired devices
                    for (BluetoothDevice device : pairedDevices) {
                        // Add the name and address to an array adapter to show   in a ListView
                        mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
                        FnlDeviceAdd =device.getAddress();


                        status = mydevicename + " : " + mydeviceaddress + " : " + bluetooth.getState();
                        //String filePath = Environment.getExternalStorageDirectory().toString() + "/Munnar/1.jpg"; 
                        String filePath =  Environment.getRootDirectory()+ "/devicefriendlyname.txt";

                        ContentValues values = new ContentValues();
                        values.put(BluetoothShare.URI, "hello");
                        //values.put(BluetoothShare.DESTINATION, FnlDeviceAdd);
                        values.put(BluetoothShare.URI,Uri.fromFile(new File(filePath)).toString());
                        Toast.makeText(this, "mydeviceaddress "+mydeviceaddress, Toast.LENGTH_LONG).show();

                        values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
                        Long ts = System.currentTimeMillis();
                        values.put(BluetoothShare.TIMESTAMP, ts);


                        Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values); 



                    }
                }

        }
        catch(Exception ex)
        {

        }

    }
    else
    {
        status = "Bluetooth is not Enabled.";

    }

我的日志猫详细信息如下

  04-29 17:20:26.850: E/ThrottleService(520): Could not open GPS configuration file             /etc/gps.conf
  04-29 17:20:44.930: E/ActivityManager(520): ANR in com.amazon.venezia
  04-29 17:20:44.930: E/ActivityManager(520): Reason: Broadcast of Intent {      act=android.net.conn.CONNECTIVITY_CHANGE    cmp=com.amazon.venezia/.notification.ClientBroadcastReceiver (has extras) }
  04-29 17:20:44.930: E/ActivityManager(520): Load: 5.57 / 1.87 / 0.66
  04-29 17:20:44.930: E/ActivityManager(520): CPU usage from 6290ms to 0ms ago:
  04-29 17:20:44.930: E/ActivityManager(520):   4.4% 682/com.amazon.venezia: 3.9% user + 0.4% kernel / faults: 2772 minor 23 major
  04-29 17:20:44.930: E/ActivityManager(520):   1.1% 520/system_server: 0.9% user +  0.1% kernel / faults: 273 minor
  04-29 17:20:44.930: E/ActivityManager(520):   0.6% 690/com.bluestacks.home: 0.4% user + 0.1% kernel / faults: 1551 minor 2 major
 04-29 17:20:44.930: E/ActivityManager(520):   0.4% 338/bstblock: 0% user + 0.4% kernel
 04-29 17:20:44.930: E/ActivityManager(520):   0% 412/loop1: 0% user + 0% kernel
 04-29 17:20:44.930: E/ActivityManager(520):   0.1% 490/zygote: 0% user + 0.1% kernel / faults: 8 minor
 04-29 17:20:44.930: E/ActivityManager(520):   0.1% 608/com.android.systemui: 0.1% user + 0% kernel / faults: 82 minor
 04-29 17:20:44.930: E/ActivityManager(520):   0.1% 666/com.google.process.gapps: 0.1% user + 0% kernel / faults: 110 minor
 04-29 17:20:44.930: E/ActivityManager(520):  +0% 737/zygote: 0% user + 0% kernel
 04-29 17:20:44.930: E/ActivityManager(520): 95% TOTAL: 6.5% user + 2.8% kernel + 86% iowait
 04-29 17:20:44.930: E/ActivityManager(520): CPU usage from 160ms to 670ms later:
 04-29 17:20:44.930: E/ActivityManager(520):   16% 737/com.facebook.katana: 15% user + 1.6% kernel / faults: 1142 minor 3 major
 04-29 17:20:44.930: E/ActivityManager(520):     8.4% 737/re-initialized>: 8.4% user + 0% kernel
04-29 17:20:44.930: E/ActivityManager(520):     6.7% 739/GC: 6.7% user + 0% kernel
04-29 17:20:44.930: E/ActivityManager(520):     1.6% 738/HeapWorker: 0% user + 1.6% kernel
04-29 17:20:44.930: E/ActivityManager(520):   5% 682/com.amazon.venezia: 5% user + 0% kernel / faults: 157 minor
04-29 17:20:44.930: E/ActivityManager(520):     5% 682/.amazon.venezia: 5% user + 0% kernel
04-29 17:20:44.930: E/ActivityManager(520):    +0% 744/RefQueueWorker@: 0% user + 0% kernel
04-29 17:20:44.930: E/ActivityManager(520):   3.9% 520/system_server: 0% user + 3.9% kernel / faults: 1170 minor
04-29 17:20:44.930: E/ActivityManager(520):     3.9% 525/Binder Thread #: 0% user + 3.9% kernel
04-29 17:20:44.930: E/ActivityManager(520): 82% TOTAL: 23% user + 5.8% kernel + 52% iowait

04-29 17:35:57.850: E/PGA(520): PgaSocketWriteAllHdipc: hd_ipc_send() failed
04-29 17:35:57.850: E/PGA(520): PgaSocketWriteAllHdipc: hd_ipc_send() failed
04-29 17:35:59.060: E/PGA(520): PgaSocketWriteAllHdipc: hd_ipc_send() failed
04-29 17:35:59.060: E/PGA(520): PgaSocketWriteAllHdipc: hd_ipc_send() failed
04-29 17:35:59.060: E/PGA(520): PgaSocketWriteAllHdipc: hd_ipc_send() failed
04-29 17:35:59.060: E/PGA(520): PgaSocketWriteAllHdipc: hd_ipc_send() failed
04-29 17:35:59.060: E/PGA(520): PgaSocketWriteAllHdipc: hd_ipc_send() failed
04-29 17:35:59.060: E/PGA(520): PgaSocketWriteAllHdipc: hd_ipc_send() failed

另一个蓝牙设备无法接收文件

任何人都可以帮我解决这个问题吗? 任何机构都能告诉我文件或邮件转移的错误吗?

将此代码更改为发送文件但无法成功

`ContentValues values = new ContentValues();
 values.put(BluetoothShare.URI,Uri.fromFile(new File(filePath1)).toString());
 values.put(BluetoothShare.DESTINATION, FnlDeviceAdd);
 values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
 Long ts = System.currentTimeMillis();
 values.put(BluetoothShare.TIMESTAMP, ts);
 Integer records = null;
 if (Strput.length() != 0) {
 records = Integer.parseInt(Strput.toString().trim();
 }
 if (records == null) {
  records = 1;
 }
 for (int i = 0; i < records; i++) {
 Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
 currentInsert = contentUri.getPathSegments().get(1);

`

1 个答案:

答案 0 :(得分:3)

您可以从this code获取帮助,以便在Android技术中从蓝牙转移。也是一个很好的例子Here