android - How can I do the user select a picture in his gallery ? (xamarin forms) -


i try open gallery of devices in order user select photo , path...but stream returns null and, then, have exception because of that... don't know wrong can me? xamarin forms project, , testing using android.

my main activity

 [activity(label = "neofly_montana", icon = "@drawable/icon", theme = "@style/maintheme", mainlauncher = false, configurationchanges = configchanges.screensize | configchanges.orientation)] public class mainactivity : global::xamarin.forms.platform.android.formsappcompatactivity {     protected override void oncreate(bundle bundle)     {         tablayoutresource = resource.layout.tabbar;         toolbarresource = resource.layout.toolbar;          base.oncreate(bundle);          global::xamarin.forms.forms.init(this, bundle);          //inicializa imagecircle         imagecirclerenderer.init();          //inicializa o mapa         global::xamarin.formsmaps.init(this, bundle);          loadapplication(new app());     }      // field, property, , method picture picker     public static readonly int pickimageid = 1000;      public taskcompletionsource<stream> pickimagetaskcompletionsource { set; get; }      protected override void onactivityresult(int requestcode, result resultcode, intent intent)     {         base.onactivityresult(requestcode, resultcode, intent);          if (requestcode == pickimageid)         {             if ((resultcode == result.ok) && (intent != null))             {                 android.net.uri uri = intent.data;                 stream stream = contentresolver.openinputstream(uri);                  // set stream completion of task                 pickimagetaskcompletionsource.setresult(stream);             }             else             {                 pickimagetaskcompletionsource.setresult(null);             }         }     } } 

in android project have class well: (in picturepickerimplementation : ipicturepicker doesnt work, ipicturepicker not recognized...i dont know why

using system; using system.collections.generic; using system.linq;  using system.text;   using android.app;  using android.content;  using android.os;  using android.runtime;  using android.views;  using android.widget;  using system.threading.tasks;  using system.io;  using xamarin.forms;  using neofly_montana.droid;   [assembly: dependency(typeof(picturepickerimplementation))]  namespace neofly_montana.droid  { public class picturepickerimplementation : ipicturepicker {     public task<stream> getimagestreamasync()     {         // define intent getting images         intent intent = new intent();         intent.settype("image/*");         intent.setaction(intent.actiongetcontent);          // mainactivity instance         mainactivity activity = forms.context mainactivity;          // start picture-picker activity (resumes in mainactivity.cs)         activity.startactivityforresult(             intent.createchooser(intent, "select picture"),             mainactivity.pickimageid);          // save taskcompletionsource object mainactivity property         activity.pickimagetaskcompletionsource = new taskcompletionsource<stream>();          // return task object         return activity.pickimagetaskcompletionsource.task;     }  }  } 

my interface in pcl:

public interface ipicturepicker {     task<stream> getimagestreamasync(); } 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -