2011-11-18 13 views

答えて

2

ようですが、Androidは明示的なOBEX APIを持っていないことを奇妙な2つの権限を追加する必要がマニフェストファイルに設定されたタイプの方法

にMIMEタイプを変更する必要があり、ファイルの種類を送信するために 。とにかく、このプロジェクトを見てみましょう:

  • Android OBEX - ファイル共有のためにあなたがthisソリューション

    BluetoothDevice device; 
    String filePath = Environment.getExternalStorageDirectory().toString() + "/file.jpg"; 
    
    ContentValues values = new ContentValues(); 
    values.put(BluetoothShare.URI, Uri.fromFile(new File(filePath)).toString()); 
    values.put(BluetoothShare.DESTINATION, device.getAddress()); 
    values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND); 
    Long ts = System.currentTimeMillis(); 
    values.put(BluetoothShare.TIMESTAMP, ts); 
    Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values); 
    

    を使用することができますOBEX


または代わりを使用して(それはthis classを必要とします)

+0

[APIリンク](http://developer.android.com/reference/android/net/Uri.html#fromFile(java.io.File))を意味しますか? – Reno

+0

@ Reno..私は私のアプリで上記のスニペットを試みましたが、宛先のデバイスにファイルを送信しません。私たちが以下のような意図で始める必要があるかどうか。ファイル形式がBluetoothで共有するためにサポートできるものは何ですか? –

+0

@レノ私はあなたの解決策を本当に驚くほど読んで、私はすでに有用であると思ったが、私はいくつかの提案が必要で、実際には私のアプリでは、画像を印刷するペアリングされたBluetoothデバイスに接続する必要があります...私は、それを行うには..? – Sun

4

これはデフォルトのデバイスのBluetooth機能を使用して別のデバイスにファイルを送信します

/** 
    * Method to share data via bluetooth 
    * */ 
    public void bluetoothFunctionality() { 
     String path = Environment.getExternalStorageDirectory() + "/" 
       + Config.FILENAME; 

     File file = new File(path); 

     Intent intent = new Intent(); 
     intent.setAction(Intent.ACTION_SEND); 
     intent.setType("text/plain"); 
     intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); 
     startActivity(intent); 
    } 

このメソッドを使用することができます小さな関数です。 これを行う前に、最初にペアリングする必要がありますが、これは制限されています。あなたはちょうどあなたが

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 
    <uses-permission android:name="android.permission.BLUETOOTH" /> 
+3

もし間違っていなければ、それらの権限は必要ありません。 – xmen

関連する問題