[英]Bluetooth File Transfer on Android
I have been trying to write a program for transferring a file which the user selects from a ListView that i provide to the user. 我一直在尝试编写一个程序,用于传输用户从我提供给用户的ListView中选择的文件。 Once the user selects a file which he intends to transfer ( "I achieved that using onLongClickListener " ), this particular block of code is triggered: 一旦用户选择了要传输的文件( “我使用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);
The trouble is that when I select the Bluetooth option from the list of options of applications which can handle this type of Intent [" This part is automatic "] nothing happens. 问题在于,当我从可以处理这种Intent [“ 这部分是自动的 ”]的应用程序的选项列表中选择Bluetooth选项时,什么也没发生。 This problem is only occurring when I am clicking on Bluetooth. 仅当我单击蓝牙时,才会出现此问题。 All the other options like GMail, Bump, etc are working perfectly. 所有其他选项,例如GMail,Bump等,都可以正常运行。 Any help/Guidance would be appreciated. 任何帮助/指导将不胜感激。 Thanks in Advance. 提前致谢。 Also, this is my Manifest File in case it seems that the sets of permissions is less than required. 另外,这是我的清单文件,以防权限集似乎少于所需的集。 AndroidManifest File: 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>
Try this code::Refer this 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);
Updated:: 更新::
File file = new File(Path.toString());
intent.setDataAndType(Uri.fromFile(file), mimeType);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.