0

hi there im downloading an image storing it and try to share it but my app creashes i relay preciate if anyone can find the error and explain why is this happend

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

firebase stuf @Override protected void onStart() { super.onStart();

    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());

Here im implementing all that it seems to have probles to locate the file

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

here is my log

    09-08 08:45:22.557 15031-15031/ar.com.puebloyreforma.pyr E/UncaughtException: android.os.FileUriExposedException: file:///storage/sdcard0/Pictures/pyr/filename.jpg exposed beyond app through ClipData.Item.getUri()
                                                                                  at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
                                                                                  at android.net.Uri.checkFileUriExposed(Uri.java:2346)
                                                                                  at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
                                                                                  at android.content.Intent.prepareToLeaveProcess(Intent.java:8909)
                                                                                  at android.content.Intent.prepareToLeaveProcess(Intent.java:8894)
                                                                                  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
                                                                                  at android.app.Activity.startActivityForResult(Activity.java:4224)
                                                                                  at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:54)
                                                                                  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
                                                                                  at android.app.Activity.startActivityForResult(Activity.java:4183)
                                                                                  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:708)
                                                                                  at android.app.Activity.startActivity(Activity.java:4507)
                                                                                  at android.app.Activity.startActivity(Activity.java:4475)
                                                                                  at ar.com.puebloyreforma.pyr.NoticiasActivity$1$1.onClick(NoticiasActivity.java:134)
                                                                                  at android.view.View.performClick(View.java:5610)
                                                                                  at android.view.View$PerformClick.run(View.java:22265)
                                                                                  at android.os.Handler.handleCallback(Handler.java:751)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                  at android.os.Looper.loop(Looper.java:154)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)


                                                                              --------- beginning of crash
09-08 08:45:22.557 15031-15031/ar.com.puebloyreforma.pyr E/AndroidRuntime: FATAL EXCEPTION: main
                                                                           Process: ar.com.puebloyreforma.pyr, PID: 15031
                                                                           android.os.FileUriExposedException: file:///storage/sdcard0/Pictures/pyr/filename.jpg exposed beyond app through ClipData.Item.getUri()
                                                                               at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
                                                                               at android.net.Uri.checkFileUriExposed(Uri.java:2346)
                                                                               at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
                                                                               at android.content.Intent.prepareToLeaveProcess(Intent.java:8909)
                                                                               at android.content.Intent.prepareToLeaveProcess(Intent.java:8894)
                                                                               at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
                                                                               at android.app.Activity.startActivityForResult(Activity.java:4224)
                                                                               at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:54)
                                                                               at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
                                                                               at android.app.Activity.startActivityForResult(Activity.java:4183)
                                                                               at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:708)
                                                                               at android.app.Activity.startActivity(Activity.java:4507)
                                                                               at android.app.Activity.startActivity(Activity.java:4475)
                                                                               at ar.com.puebloyreforma.pyr.NoticiasActivity$1$1.onClick(NoticiasActivity.java:134)
                                                                               at android.view.View.performClick(View.java:5610)
                                                                               at android.view.View$PerformClick.run(View.java:22265)
                                                                               at android.os.Handler.handleCallback(Handler.java:751)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                               at android.os.Looper.loop(Looper.java:154)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
lukini
  • 3
  • 3
  • 1
    Possible duplicate of [when take photo get - java.lang.Throwable: file:// Uri exposed through ClipData.Item.getUri()](https://stackoverflow.com/questions/32623304/when-take-photo-get-java-lang-throwable-file-uri-exposed-through-clipdata) – Abbas Sep 08 '17 at 08:57
  • Did you gave permission to access the storage? Write access? `WRITE_EXTERNAL_STORAGE` permission in `Manifest` and same is required for Marshmallow+ device at runtime. You can check solution here for runtime: https://stackoverflow.com/questions/37160465/marsmallow-changing-permissions-at-run-time-crashes-app/37160573#37160573 – Jimit Patel Sep 08 '17 at 09:00
  • Abbas i was reading that post i couldnt find the answear to my problem Jimit : yes i got the permission and i confirm the app asks for them in te main activity – lukini Sep 08 '17 at 09:08

0 Answers0