Ich probiere ein Beispielprogramm aus, um eine Datei im internen Speicher zu speichern, und öffne sie unter Verwendung von Intent.ACTION_VIEW.Wie öffne ich private Dateien, die mit Intent.ACTION_VIEW im internen Speicher gespeichert wurden?
für die Datei im privaten Modus Speicherung folgte ich die Schritte here. vorgesehen
konnte ich die erstellte Datei in dem internen Speicher bei /data/data/com.storeInternal.poc/files finden. *
Aber wenn ich versuchte, Datei zu öffnen, wird es nicht geöffnet.
Hier finden Sie den Code, den ich dafür verwendet habe.
public class InternalStoragePOCActivity extends Activity {
/** Called when the activity is first created. */
String FILENAME = "hello_file.txt";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
createFile();
openFile(FILENAME);
}
public FileOutputStream getStream(String path) throws FileNotFoundException {
return openFileOutput(path, Context.MODE_PRIVATE);
}
public void createFile(){
String string = "hello world!";
FileOutputStream fout = null;
try {
//getting output stream
fout = getStream(FILENAME);
//writng data
fout.write(string.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(fout!=null){
//closing the output stream
try {
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public void openFile(String filePath) {
try {
File temp_file = new File(filePath);
Uri data = Uri.fromFile(temp_file);
String type = getMimeType(data.toString());
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(data, type);
startActivity(intent);
} catch (Exception e) {
Log.d("Internal Storage POC ", "No Supported Application found to open this file");
e.printStackTrace();
}
}
public static String getMimeType(String url) {
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
}
Wie kann ich öffnen Sie die Datei Context.MODE_PRIVATE von jeder anderen bestehenden/geeigneten App gespeichert ist. ZB: file.pdf sollte von PDF - Reader, Video für Video - Player usw. Geöffnet werden.
meine Antwort siehe hier: http://stackoverflow.com/questions/15377373/how-to-put-a-video -file-in-android-custom-content-provider – dangalg