Comment ouvrir privé de fichiers enregistrés sur la mémoire interne à l'aide de l'Intention.ACTION_VIEW?

Je cherche un exemple de programme pour stocker un fichier dans la mémoire interne et de l'ouvrir à l'aide de
L'intention.ACTION_VIEW.

Pour stocker le fichier en mode privé, j'ai suivi les étapes indiquées ici.

J'ai été en mesure de trouver le fichier créé dans la mémoire interne dans /data/data/com.storeInternal.poc/fichiers .*

Mais quand j'ai essayé d'ouvrir le fichier,il ne s'ouvre pas.

Veuillez trouver ci-dessous le code que j'ai utilisé pour cela.

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;
}
}

Comment puis-je ouvrir le fichier stocké à l'aide de Contexte.MODE_PRIVATE par/application appropriée. Par exemple: fichier.fichier pdf doit être ouvert que par un lecteur de PDF,de Vidéo en vidéo, les Joueurs,etc.

InformationsquelleAutor Abhinav | 2014-01-23