2015-11-17 11 views
1

藍牙文件傳輸我在android系統中創建文件的傳輸應用程序從藍牙,但不幸的是我的應用程序崩潰, 以下是我主要的源代碼和error.I的日誌有一個文件名爲「hi.txt」在我的SD卡。 請引導我出錯的地方。錯誤在執行中的Android

public class MainActivity extends AppCompatActivity 
     {  
     ListView listViewPaired; 
     ListView listViewDetected; 
     ArrayList<String> arrayListpaired; 
     Button buttonSearch, buttonOn, buttonDesc, buttonOff; 
     ArrayAdapter<String> adapter, detectedAdapter, mNewDevicesArrayAdapter; 
     static HandleSeacrh handleSeacrh; 

     BluetoothDevice bdDevice; 
     BluetoothClass bdClass; 
     ArrayList<BluetoothDevice> arrayListPairedBluetoothDevices; 
     private ButtonClicked clicked; 
     ListItemClickedonPaired listItemClickedonPaired; 
     BluetoothAdapter bluetoothAdapter = null; 
     ArrayList<BluetoothDevice> arrayListBluetoothDevices = null; 
     ListItemClicked listItemClicked; 
     UUID applicationUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); 

     @Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 

      listViewDetected = (ListView) findViewById(R.id.listViewDetected); 
      listViewPaired = (ListView) findViewById(R.id.listViewPaired); 
      buttonSearch = (Button) findViewById(R.id.buttonSearch); 
      buttonOn = (Button) findViewById(R.id.buttonOn); 
      buttonDesc = (Button) findViewById(R.id.buttonDesc); 
      buttonOff = (Button) findViewById(R.id.buttonOff); 
      arrayListpaired = new ArrayList<String>(); 
      bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
      clicked = new ButtonClicked(); 
      handleSeacrh = new HandleSeacrh(); 
      arrayListPairedBluetoothDevices = new ArrayList<BluetoothDevice>(); 
      /* 
      * the above declaration is just for getting the paired bluetooth devices; 
      * this helps in the removing the bond between paired devices. 
      */ 
      listItemClickedonPaired = new ListItemClickedonPaired(); 
      arrayListBluetoothDevices = new ArrayList<BluetoothDevice>(); 
      adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, arrayListpaired); 
      detectedAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_single_choice); 
      mNewDevicesArrayAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_single_choice); 
      listViewDetected.setAdapter(detectedAdapter); 
      listItemClicked = new ListItemClicked(); 
      detectedAdapter.notifyDataSetChanged(); 
      listViewPaired.setAdapter(adapter); 
     } 

     @Override 
     protected void onStart() 
     { 
      // TODO Auto-generated method stub 
      super.onStart(); 
      getPairedDevices(); 
      buttonOn.setOnClickListener(clicked); 
      buttonSearch.setOnClickListener(clicked); 
      buttonDesc.setOnClickListener(clicked); 
      buttonOff.setOnClickListener(clicked); 
      listViewDetected.setOnItemClickListener(listItemClicked); 
      listViewPaired.setOnItemClickListener(listItemClickedonPaired); 
     } 

     private void getPairedDevices() 
     { 
      Set<BluetoothDevice> pairedDevice = bluetoothAdapter.getBondedDevices(); 
      if (pairedDevice.size() > 0) 
       { 
       for (BluetoothDevice device : pairedDevice) 
       { 
        arrayListpaired.add(device.getName() + "\n" + device.getAddress()); 
        arrayListPairedBluetoothDevices.add(device); 
       } 
      } 
      adapter.notifyDataSetChanged(); 
     } 

     class ListItemClicked implements AdapterView.OnItemClickListener 
     { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       // TODO Auto-generated method stub 
       bdDevice = arrayListBluetoothDevices.get(position); 

       Log.i("Log", "The dvice : " + bdDevice.toString()); 

       Boolean isBonded = false; 
       try { 
        isBonded = createBond(bdDevice); 
        if (isBonded) { 

         Log.i("Log", "Paired"); 
        } 
       } catch (Exception e) 
       { 
        e.printStackTrace(); 
       } 
       Log.i("Log", "The bond is created: " + isBonded);   
      } 
     } 

     public void btSend() 
     { 
      String path = Environment.getExternalStorageDirectory()+"/hi.txt"; 

      File file = new File(path); 

      BluetoothSocket socket= null; 
      try 
       { 
       socket = bdDevice.createRfcommSocketToServiceRecord(applicationUUID); 
       socket.connect(); 
      } 
      catch (IOException e) 
      { 
       e.printStackTrace(); 
      } 

      ContentValues values = new ContentValues(); 
      values.put(BluetoothShare.URI, path); 
      values.put(BluetoothShare.DESTINATION,bdDevice.getAddress()); 
      values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND); 
      Long ts = System.currentTimeMillis(); 
      values.put(BluetoothShare.TIMESTAMP, ts); 
      getContentResolver().insert(BluetoothShare.CONTENT_URI,values); 
     } 



     class ListItemClickedonPaired implements AdapterView.OnItemClickListener 
     { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       bdDevice = arrayListPairedBluetoothDevices.get(position); 
       try { 
        Boolean removeBond = removeBond(bdDevice); 
        if (removeBond) { 
         arrayListpaired.remove(position); 
         adapter.notifyDataSetChanged(); 
        } 
        Log.i("Log", "Removed" + removeBond); 
       } catch (Exception e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
     } 

     private Boolean connect(BluetoothDevice bdDevice) 
     { 
      Boolean bool = false; 
      try { 
       Log.i("Log", "service method is called "); 
       Class cl = Class.forName("android.bluetooth.BluetoothDevice"); 
       Class[] par = {}; 
       Method method = cl.getMethod("createBond", par); 
       Object[] args = {}; 
       bool = (Boolean) method.invoke(bdDevice);//, args); 
      } catch (Exception e) 
       { 
       Log.i("Log", "Inside catch of serviceFromDevice Method"); 
       e.printStackTrace(); 
      } 
      return bool.booleanValue(); 
     }; 


     public boolean removeBond(BluetoothDevice btDevice) throws Exception 
     { 
      Class btClass = Class.forName("android.bluetooth.BluetoothDevice"); 
      Method removeBond = btClass.getMethod("removeBond"); 
      Boolean returnValue = (Boolean)removeBond.invoke(btDevice); 
      return returnValue.booleanValue(); 
     } 


     public boolean createBond(BluetoothDevice btDevice) 
       throws Exception 
     { 
      Class class1 = Class.forName("android.bluetooth.BluetoothDevice"); 
      Method createBondMethod = class1.getMethod("createBond"); 
      Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice); 
      return returnValue.booleanValue(); 
     } 


     class ButtonClicked implements View.OnClickListener 
     { 
      @Override 
      public void onClick(View view) { 
       switch (view.getId()) { 
        case R.id.buttonOn: 
         onBluetooth(); 
         break; 
        case R.id.buttonSearch: 
         arrayListBluetoothDevices.clear(); 
         startSearching(); 
         break; 
        case R.id.buttonDesc: 
         makeDiscoverable(); 
         break; 
        case R.id.buttonOff: 
         offBluetooth(); 
         break; 
        default: 
         break; 
       } 
      } 
     } 

     private BroadcastReceiver myReceiver = new BroadcastReceiver() 
     { 
      @Override 
      public void onReceive(Context context, Intent intent) { 
       Message msg = Message.obtain(); 
       String action = intent.getAction(); 

       if (BluetoothDevice.ACTION_FOUND.equals(action)) { 
        Toast.makeText(context, "ACTION_FOUND", Toast.LENGTH_SHORT).show(); 
        Toast.makeText(getApplicationContext(), "Searching for devices", Toast.LENGTH_LONG).show(); 
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
        try { 
         //device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true); 
         //device.getClass().getMethod("cancelPairingUserInput", boolean.class).invoke(device); 
        } catch (Exception e) { 
         Log.i("Log", "Inside the exception: "); 
         e.printStackTrace(); 
        } 

        if (arrayListBluetoothDevices.size() < 1) // this checks if the size of bluetooth device is 0,then add the 
        {           // device to the arraylist. 
         detectedAdapter.add(device.getName() + "\n" + device.getAddress()); 
         arrayListBluetoothDevices.add(device); 
         detectedAdapter.notifyDataSetChanged(); 
        } else { 
         boolean flag = true; // flag to indicate that particular device is already in the arlist or not 
         for (int i = 0; i < arrayListBluetoothDevices.size(); i++) { 
          if (device.getAddress().equals(arrayListBluetoothDevices.get(i).getAddress())) { 
           flag = false; 
          } 
         } 
         if (flag == true) { 
          detectedAdapter.add(device.getName() + "\n" + device.getAddress()); 
          arrayListBluetoothDevices.add(device); 
          detectedAdapter.notifyDataSetChanged(); 
         } 
        } 
        if (device.getBondState() != BluetoothDevice.BOND_BONDED) { 
         mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); 
         arrayListBluetoothDevices.add(device); 
        } 
       } 
      } 
     }; 

     private void startSearching() 
     { 
      Log.i("Log", "in the start searching method"); 
      IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
      MainActivity.this.registerReceiver(myReceiver, intentFilter); 
      bluetoothAdapter.startDiscovery(); 
     } 

     private void onBluetooth() 
     { 
      if (!bluetoothAdapter.isEnabled()) { 
       bluetoothAdapter.enable(); 
       Log.i("Log", "Bluetooth is Enabled"); 
       Toast.makeText(getApplicationContext(), "Turned on", Toast.LENGTH_LONG).show(); 
      } else { 
       Toast.makeText(getApplicationContext(), "Already on", Toast.LENGTH_LONG).show(); 
      } 
     } 

     private void offBluetooth() 
      { 
      if (bluetoothAdapter.isEnabled()) 
      { 
       bluetoothAdapter.disable(); 
       Toast.makeText(getApplicationContext(), "Turned off", Toast.LENGTH_LONG).show(); 
      } 
     } 

    private void makeDiscoverable() 
      { 
      Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); 
      discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); 
      startActivity(discoverableIntent); 
      Log.i("Log", "Discoverable "); 
     } 

     class HandleSeacrh extends Handler 
     { 
      @Override 
      public void handleMessage(Message msg) { 
       switch (msg.what) 
       { 
        case 111: 

         break; 

        default: 
         break; 
       } 
      } 
     } 
    } 

日誌文件:

13170-13170/com.example.toshiba.bluetoothdemo D/ActivityThread: handleBindApplication:com.example.toshiba.bluetoothdemo 
    11-16 18:01:45.587 13170-13170/com.example.toshiba.bluetoothdemo D/ActivityThread: setTargetHeapUtilization:0.75 
    11-16 18:01:45.587 13170-13170/com.example.toshiba.bluetoothdemo D/ActivityThread: setTargetHeapMinFree:2097152 
    11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;) 
    11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested 
    11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to resolve interface method 17915: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z 
    11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 
    11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode 
    11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to resolve interface method 17919: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; 
    11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 
    11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getTotalMemory()J 
    11-16 18:01:45.647 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getFreeMemory()J 
    11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 
    11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to resolve virtual method 439: Landroid/content/res/TypedArray;.getChangingConfigurations()I 
    11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 
    11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 
    11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to resolve virtual method 461: Landroid/content/res/TypedArray;.getType (I)I 
    11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 
    11-16 18:01:45.787 13170-13170/com.example.toshiba.bluetoothdemo D/BluetoothAdapter: 1112941536: getState() : mService = null. Returning STATE_OFF 
    11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: () 
    11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: OpenGL ES Shader Compiler Version: E031.24.02.07 
    11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Build Date: 03/30/15 Mon 
    11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Local Branch: 
    11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Remote Branch: 
    11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Local Patches: 
    11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Reconstruct Branch: 
    11-16 18:01:45.897 13170-13170/com.example.toshiba.bluetoothdemo D/OpenGLRenderer: Enabling debug mode 0 
    11-16 18:01:46.037 13170-13170/com.example.toshiba.bluetoothdemo I/Timeline: Timeline: Activity_idle id: [email protected] time:8721552 
    11-16 18:01:48.687 13170-13170/com.example.toshiba.bluetoothdemo I/Log: Bluetooth is Enabled 
    11-16 18:01:48.717 13170-13170/com.example.toshiba.bluetoothdemo W/Toast: From com.example.toshiba.bluetoothdemo, go ahead. 
    11-16 18:01:50.267 13170-13170/com.example.toshiba.bluetoothdemo I/Timeline: Timeline: Activity_launch_request time:8725789 
    11-16 18:01:50.297 13170-13170/com.example.toshiba.bluetoothdemo I/Log: Discoverable 
    11-16 18:01:52.337 13170-13170/com.example.toshiba.bluetoothdemo I/Timeline: Timeline: Activity_idle id: [email protected] time:8727857 
    11-16 18:01:53.227 13170-13170/com.example.toshiba.bluetoothdemo I/Log: in the start searching method 
    11-16 18:01:54.717 13170-13170/com.example.toshiba.bluetoothdemo W/Toast: From com.example.toshiba.bluetoothdemo, go ahead. 
    11-16 18:01:54.727 13170-13170/com.example.toshiba.bluetoothdemo W/Toast: From com.example.toshiba.bluetoothdemo, go ahead. 
    11-16 18:01:57.917 13170-13170/com.example.toshiba.bluetoothdemo I/Log: The dvice : 24:EC:99:5C:FA:8C 
    11-16 18:01:57.947 13170-13170/com.example.toshiba.bluetoothdemo I/Log: The bond is created: false 
    11-16 18:01:57.957 13170-13170/com.example.toshiba.bluetoothdemo W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback 
    11-16 18:01:57.967 13170-13170/com.example.toshiba.bluetoothdemo D/BluetoothSocket: connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[67]} 
    11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] gammamode=2, cemode=10 
    11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] temp_gammavalue=2, temp_cevalue=10 
    11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] Don't setGamma! 
    11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] Don't setCe! 
    11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] Set temp_prefer temp_ce! 
    11-16 18:02:02.277 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:574) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:585) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:326) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at com.example.toshiba.bluetoothdemo.MainActivity.btSend(MainActivity.java:163) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at com.example.toshiba.bluetoothdemo.MainActivity$ListItemClicked.onItemClick(MainActivity.java:146) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.widget.AdapterView.performItemClick(AdapterView.java:299) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.widget.AbsListView.performItemClick(AbsListView.java:1115) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2928) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.widget.AbsListView$3.run(AbsListView.java:3691) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.os.Handler.handleCallback(Handler.java:733) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.os.Handler.dispatchMessage(Handler.java:95) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.os.Looper.loop(Looper.java:136) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at android.app.ActivityThread.main(ActivityThread.java:5113) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at java.lang.reflect.Method.invokeNative(Native Method) 
    11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at java.lang.reflect.Method.invoke(Method.java:515) 
    11-16 18:02:02.297 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
    11-16 18:02:02.297 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
    11-16 18:02:02.297 13170-13170/com.example.toshiba.bluetoothdemo W/System.err:  at dalvik.system.NativeStart.main(Native Method) 
    11-16 18:02:02.307 13170-13170/com.example.toshiba.bluetoothdemo D/AndroidRuntime: Shutting down VM 
    11-16 18:02:02.307 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x416d9d58) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: FATAL EXCEPTION: main 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: Process: com.example.toshiba.bluetoothdemo, PID: 13170 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: java.lang.SecurityException: Permission Denial: writing com.android.bluetooth.opp.BluetoothOppProvider uri content://com.android.bluetooth.opp/btopp from pid=13170, uid=10137 requires android.permission.ACCESS_BLUETOOTH_SHARE, or grantUriPermission() 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.os.Parcel.readException(Parcel.java:1472) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.content.ContentProviderProxy.insert(ContentProviderNative.java:468) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.content.ContentResolver.insert(ContentResolver.java:1190) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at com.example.toshiba.bluetoothdemo.MainActivity.btSend(MainActivity.java:178) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at com.example.toshiba.bluetoothdemo.MainActivity$ListItemClicked.onItemClick(MainActivity.java:146) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.widget.AdapterView.performItemClick(AdapterView.java:299) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.widget.AbsListView.performItemClick(AbsListView.java:1115) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2928) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.widget.AbsListView$3.run(AbsListView.java:3691) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.os.Handler.handleCallback(Handler.java:733) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:95) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:136) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:5113) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at java.lang.reflect.Method.invokeNative(Native Method) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:515) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
    11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime:  at dalvik.system.NativeStart.main(Native Method) 
    ' 
+0

顯示錯誤的logcat –

+0

已經存在。 – Aishwarya

回答

0

閱讀logcat的這條線

java.lang.SecurityException: Permission Denial: writing com.android.bluetooth.opp.BluetoothOppProvider uri content://com.android.bluetooth.opp/btopp from pid=13170, uid=10137 requires android.permission.ACCESS_BLUETOOTH_SHARE, or grantUriPermission() 

這是你的問題,添加android.permission.ACCESS_BLUETOOTH_SHARE權限您的清單

我應該補充說這可能不是你的LY錯誤,但它是一個造成這種特定崩潰下面的代碼

+0

我已經加入androidManifest所需的權限file..still它給了同樣的錯誤 – Aishwarya

+0

看看這個鏈接http://stackoverflow.com/questions/12388503/android-bluetooth-print-stopped-working-on-4 -1 – Zach

+0

我更換內容值代碼與下面的代碼,但我仍,同時從應用程序發送的文件指出「請求不能正確處理」得到一個錯誤: – Aishwarya