Вот мой исходный код (на самом деле копирование из старых книг)
Код: Выделить всё
public class MainActivity extends AppCompatActivity
{
private Button mBtnBrowseWWW, mBtnPlayMP3, mBtnViewImg;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBtnPlayMP3 = (Button)findViewById(R.id.btnPlayMP3);
mBtnViewImg = (Button)findViewById(R.id.btnViewImg);
mBtnPlayMP3.setOnClickListener(btnPlayMP3OnClick);
mBtnViewImg.setOnClickListener(btnViewImgOnClick);
}
private View.OnClickListener btnPlayMP3OnClick = new View.OnClickListener()
{
public void onClick(View v)
{
Intent it = new Intent(Intent.ACTION_VIEW);
String sMp3File = Environment.getExternalStorageDirectory().getPath() +
File.separator + "song.mp3";
File file = new File(sMp3File);
boolean b = file.exists();
it.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(it);
}
};
private View.OnClickListener btnViewImgOnClick = new View.OnClickListener()
{
public void onClick(View v)
{
Intent it = new Intent(Intent.ACTION_VIEW);
String sImgFile = Environment.getExternalStorageDirectory().getPath() +
File.separator + "image.png";
File file = new File(sImgFile);
it.setDataAndType(Uri.fromFile(file), "image/*");
startActivity(it);
}
};
}
Код: Выделить всё
android.os.FileUriExposedException: file:///storage/emulated/0/image.png exposed beyond app through Intent.getData()
Код: Выделить всё
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/790 ... oid-studio
Мобильная версия