有人可以帮我解决这个问题吗,欢迎大家的帮助,谢谢
点击从互联网https://code.i-harness.com/en/q/1ccc4e5上找到的代码中添加的共享按钮,我遇到了此错误 Android Studio 我正在使用android studio 3.2,如何解决此问题? 有人知道如何解决这个问题吗?
public class DetalhesProdutoActivity extends AppCompatActivity {
private CarouselView carouselView;
private TextView titulo;
private TextView descricao;
private TextView estado;
private TextView preco;
private Anuncio anuncioSelecionado;
private File imagePath;
private void shareIt() {
Uri uri = Uri.fromFile(imagePath);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("image/*");
String shareBody = "In Tweecher, My highest score with screen shot";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Tweecher score");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detalhes_produto);
Button share = (Button) findViewById(R.id.share);
share = (Button)findViewById(R.id.share);
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
shareIt();
}
});
ContextCompat.checkSelfPermission(DetalhesProdutoActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE);
ContextCompat.checkSelfPermission(DetalhesProdutoActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
//fim admob
//Configurar toolbar
getSupportActionBar().setTitle("Detalhes da postagem");
//Incializar componentes de interface
inicializarComponentes();
//Recupera anúncio para exibicao
anuncioSelecionado = (Anuncio) getIntent().getSerializableExtra("anuncioSelecionado");
if( anuncioSelecionado != null ){
titulo.setText( anuncioSelecionado.getTitulo() );
descricao.setText( anuncioSelecionado.getDescricao() );
estado.setText( anuncioSelecionado.getEstado() );
preco.setText( anuncioSelecionado.getValor());
ImageListener imageListener = new ImageListener() {
@Override
public void setImageForPosition(int position, ImageView imageView) {
String urlString = anuncioSelecionado.getFotos().get( position );
Picasso.get().load(urlString).into(imageView);
}
};
carouselView.setPageCount( anuncioSelecionado.getFotos().size() );
carouselView.setImageListener( imageListener );
}
}
public void visualizarTelefone(View view){
Intent i = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", anuncioSelecionado.getTelefone(), null ));
startActivity( i );
}
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
private void inicializarComponentes(){
carouselView = findViewById(R.id.carouselView);
titulo = findViewById(R.id.textTituloDetalhe);
descricao = findViewById(R.id.textDescricaoDetalhe);
estado = findViewById(R.id.textEstadoDetalhe);
preco = findViewById(R.id.textPrecoDetalhe);
}
} 错误
2019-01-26 23:36:36.010 7475-7475/com.xxx.xxx.xxxxxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.xxx.xxxxxx, PID: 7475
android.os.FileUriExposedException: file:///storage/emulated/0/screenshot.png exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1960)
at android.net.Uri.checkFileUriExposed(Uri.java:2348)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:942)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9854)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9860)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9839)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1610)
at android.app.Activity.startActivityForResult(Activity.java:4487)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:68)
at android.app.Activity.startActivityForResult(Activity.java:4445)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:751)
at android.app.Activity.startActivity(Activity.java:4806)
at android.app.Activity.startActivity(Activity.java:4774)
at com.xxx.xxx.xxxxxx.activity.DetalhesProdutoActivity.shareIt(DetalhesProdutoActivity.java:50)
at com.xxx.xxx.xxxxxx.activity.DetalhesProdutoActivity.access$000(DetalhesProdutoActivity.java:32)
at com.xxx.xxx.xxxxxx.activity.DetalhesProdutoActivity$1.onClick(DetalhesProdutoActivity.java:66)