Я не могу понять, как обмениваться внутренним txt-файлом. (! Не внешние) я заметил, что не possibile по умолчанию, но я writed моего ContetProvider классаAndroid java для записи файла внутренней памяти и совместного использования
< поставщик андроид: имя = "myProvider" андроида: власти = "com.mobilemerit.usbhost" андроид: экспортироваться = "истинный" />
public class myProvider extends ContentProvider {
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
File cacheDir = getContext().getCacheDir();
File privateFile = new File(cacheDir, "file.txt");
return ParcelFileDescriptor.open(privateFile, ParcelFileDescriptor.MODE_READ_WRITE);
}
затем
try {
InputStream is = c.getAssets().open("file.txt");
File cacheDir = c.getCacheDir();
File outFile = new File(cacheDir, "file.txt");
OutputStream os = new FileOutputStream(outFile.getAbsolutePath());
String content = "Hello Java Code Geeks";
byte[] buff = new byte[1024];
int len;
while ((len = is.read(buff)) > 0) {
os.write(buff, 0, len);
}
os.flush();
os.close();
is.close();
} catch (IOException e) {
e.printStackTrace(); // TODO: should close streams properly here
}
Uri uri = Uri.parse("content://com.mobilemerit.usbhost/file.txt");
InputStream is = null;
StringBuilder result = new StringBuilder();
try {
is = c.getContentResolver().openInputStream(uri);
BufferedReader r = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = r.readLine()) != null) {
result.append(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try { if (is != null) is.close(); } catch (IOException e) { }
}
но новое намерение совместного использования, которое я пишу, связано с файлом file.txt, который невозможно отправить. Похоже, что приложение «это неверно». Что я обижаю? Я не могу использовать внешнее запоминающее устройство
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://com.mobilemerit.usbhost/file.txt"));
startActivity(Intent.createChooser(intent, ""));
'then'. Объясните, пожалуйста, код, который будет «притворяться». – greenapps
Затем он собирался вставить еще один фрагмент кода –
. Вы можете найти интересную информацию в http://stackoverflow.com/questions/6072895/email-from-internal-storage, более подробно в последующих ответах, которые охватывают контент-провайдера чем в моем собственном размещении на причудах прямого файлового метода, который в первый раз пытался решить этот вопрос. –