I share a file locate in the internal memory through an intent, using the code below:
Uri uri = Uri.parse("content://com.mypackage/" + fileName);
Intent ShareIntent = new Intent();
ShareIntent.setAction(Intent.ACTION_SEND);
ShareIntent.setDataAndType(uri,"text/plain");
ShareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(ShareIntent);
If I choose GMail from the list, the file is attached and sent perfectly, but if I choose Bluetooth, I receive a Toast with a "File not Sent" message. Do I have to give any special permission to the device I'm sending to?
The provider I'm using is here:
public class MyProvider extends ContentProvider {
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
File privateFile = new File(getContext().getFilesDir(), uri.getPath());
return ParcelFileDescriptor.open(privateFile, ParcelFileDescriptor.MODE_READ_ONLY);
}
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
return 0;
}
@Override
public String getType(Uri arg0) {
return null;
}
@Override
public Uri insert(Uri arg0, ContentValues arg1) {
return null;
}
@Override
public boolean onCreate() {
return false;
}
@Override
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3,
String arg4) {
return null;
}
@Override
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
return 0;
}
}
and in AndroidManifest:
<provider android:name=".MyProvider" android:authorities="com.mypackage" android:exported="true" />
What am I missing here?
0 comments:
Post a Comment