【问题标题】:Bluetooth File Transfer on AndroidAndroid 上的蓝牙文件传输
【发布时间】:2014-03-31 20:26:13
【问题描述】:

我一直在尝试编写一个程序来传输用户从我提供给用户的 ListView 中选择的文件。一旦用户选择了他打算传输的文件(“我使用 onLongClickListener 实现了这一点),就会触发这个特定的代码块:

    String mimeType = fileAction.getMimeType(rowHolder.get(position).getLabel());
            Intent playFile = new Intent();
            playFile.setAction(android.content.Intent.ACTION_SEND);
            Uri pathUri = Uri.parse("file://" + currentPath +     rowHolder.get(position).getLabel());
        playFile.setDataAndType(pathUri, mimeType);
        startActivity(playFile);

问题在于,当我从可以处理此类 Intent 的应用程序选项列表中选择蓝牙选项时 ["这部分是自动的"] 没有任何反应。仅当我单击蓝牙时才会出现此问题。 GMail、Bump 等所有其他选项都运行良好。任何帮助/指导将不胜感激。提前致谢。此外,这是我的清单文件,以防权限集似乎少于要求。 AndroidManifest 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="org.sample.test"
  android:versionCode="2"
  android:versionName="1.1">

<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

<application 
    android:icon="@drawable/app_icon" 
    android:label="@string/app_name" 
    android:debuggable="false"
    android:theme="@android:style/Theme.NoTitleBar" >
    <activity android:name=".Main"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity 
        android:name=".Preferences"
        android:label="@string/preferences" >
    </activity>
    <activity 
        android:name=".SearchFileSystem"
        android:label="@string/search" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data 
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
    </activity>

</application>
</manifest> 

【问题讨论】:

    标签: android bluetooth share file-transfer


    【解决方案1】:

    试试这个代码::参考这个LINK

    String mimeType = fileAction.getMimeType(rowHolder.get(position).getLabel());
    Intent intent = new Intent();  
    intent.setAction(android.content.Intent.ACTION_SEND);  
    intent.setType(mimeType);
    Uri pathUri = Uri.parse("file://" + currentPath + rowHolder.get(position).getLabel());
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pathUri ) );  
    startActivity(intent);
    

    更新::

    File file = new File(Path.toString());  
    intent.setDataAndType(Uri.fromFile(file), mimeType);
    

    【讨论】:

    • 它要求将“pathUri”的类型更改为文件
    • 不用担心。谢谢。 :-)。我被困在这个问题上很长一段时间了。
    猜你喜欢
    • 1970-01-01
    • 2012-02-07
    • 2011-06-02
    • 2011-11-14
    • 2013-04-23
    • 2011-08-13
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多