嗨我下载存储它的图像并试图分享它但我的应用程序刷新我转发预先准备,如果有人能找到错误并解释为什么会发生这种情况
\b[\d]+[.,][\d]+\b
firebase stuf @覆盖 protected void onStart(){ super.onStart();
public class NoticiasActivity extends AppCompatActivity {
private RecyclerView mBlogList;
FirebaseDatabase database;
DatabaseReference myRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_noticias);
//Recycler View
mBlogList = (RecyclerView)findViewById(R.id.blog_list);
mBlogList.setHasFixedSize(true);
mBlogList.setLayoutManager(new LinearLayoutManager(this));
// Send a Query to the database
database = FirebaseDatabase.getInstance();
myRef = database.getReference("Data");
}
在这里我实现所有它似乎有问题找到文件
FirebaseRecyclerAdapter<ModelClass, BlogViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<ModelClass, BlogViewHolder>(
ModelClass.class,
R.layout.design_row,
BlogViewHolder.class,
myRef) {
@Override
protected void populateViewHolder(BlogViewHolder viewHolder, ModelClass model, final int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setImage(getApplicationContext(), model.getImage());
这是我的日志
viewHolder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String filename = "filename.jpg";
String downloadUrlOfImage = "https://firebasestorage.googleapis.com/v0/b/pueblo-y-reforma.appspot.com/o/reformauniversitaria2017_1128%5B1%5D.jpeg?alt=media&token=a10c6ca2-2681-4bbe-8914-3692174bec09";
File direct =
new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
.getAbsolutePath() + "/" + "/Pyr" + "/");
if (!direct.exists()) {
direct.mkdir();
Log.d("pyr", "dir created for first time");
}
DownloadManager dm = (DownloadManager)getBaseContext().getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(downloadUrlOfImage);
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle(filename)
.setMimeType("image/jpeg")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES,
File.separator + "pyr" + File.separator + filename);
dm.enqueue(request);
String image_path = "/storage/sdcard0/Pictures/pyr/filename.jpg";
File file = new File(image_path);
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent .setType("image/*");
intent .putExtra(Intent.EXTRA_STREAM, uri);
view.getContext().startActivity(intent );
}
});
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
//View Holder For Recycler View
public static class BlogViewHolder extends RecyclerView.ViewHolder {
View mView;
Button button ;
public BlogViewHolder(View itemView) {
super(itemView);
mView= itemView;
button = (Button)mView.findViewById(R.id.share);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// click en la imagen hace algo
//añadir luego
Toast.makeText(v.getContext(), ("hola"+ getPosition()), Toast.LENGTH_SHORT).show();
}
});
}
public void setTitle(String title){
TextView post_title = (TextView)mView.findViewById(R.id.titleText);
post_title.setText(title);
}
public void setImage(Context ctx , String image){
ImageView post_image = (ImageView)mView.findViewById(R.id.imageViewy);
// We Need TO pass Context
Picasso.with(ctx).load(image).into(post_image);
} }}