Я пытаюсь открыть файл jpg из папки res/raw с помощью кнопки в действии. Однако при запуске и тестировании приложения, я получаю сообщение об ошибке сказав:Как открыть ресурс jpg с помощью кнопки в действии
11-09 10:20:51.654: E/AndroidRuntime(3247): android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///android.resource:/com.image.imagetest/2131034112 typ=application/jpg flg=0x4000000 }`
Это мой код:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_image, container, false);
Button button = (Button) rootView.findViewById(R.id.Image1);
button.setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
File jpgFile = new File("android.resource://com.image.imagetest/" + R.raw.mainimage);
Uri path = Uri.fromFile(jpgFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, "application/jpg");
startActivity(intent);
}
});
return rootView;
}
Я пропускаю что-то здесь :-)?
EDIT
я сейчас сделал это, но теперь при запуске приложения для проверки я получаю сообщение о том, «не удалось найти пункт» от нажатия кнопки. Вот мой код:
public void onClick(final View v) {
File jpgFile = new File("android.resource://com.image.imagetest/" + R.raw.mainimage);
Uri path = Uri.fromFile(jpgFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, "image/jpeg");
startActivity(intent);
}
http://stackoverflow.com/questions/12585747/how-to- open-a-file-in-android-to-intent – sider