首先,我使用三星Galaxy Tab 2进行调试。
我知道三星cam-intent
的问题。这似乎是OnActivityResult
中数据意图的常见问题。但我的似乎是另一个。
我得到NullReferenceException
我无法本地化。但是让我们来看看代码(它是它的一部分):
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
System.Console.WriteLine("---------------Reached OnActivityResult");
base.OnActivityResult(requestCode, resultCode, data);
var pic = new Picture();
if (requestCode == 0 && resultCode == Result.Ok)
{
if (requestCode == 0)
{
if (data != null)
{
Uri imageUri = null;
// Check if the result includes a thumbnail Bitmap
var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
var contentUri = Android.Net.Uri.FromFile(_file);
mediaScanIntent.SetData(contentUri);
this.SendBroadcast(mediaScanIntent);
var bitmap = MediaStore.Images.Media.GetBitmap(ContentResolver, contentUri);
var info = data.GetStringArrayExtra("PictureInfo");
pic = new Picture(info[0], int.Parse(info[2]), info[1],
Core.Helpers.ConversionHelper.GetStringFromImage(bitmap));
}
else
{
ContentResolver cr = ContentResolver;
String[] p1 = new String[] {
MediaStore.Images.ImageColumns.Id,
MediaStore.Images.ImageColumns.DateTaken
};
ICursor c1 = cr.Query(MediaStore.Images.Media.ExternalContentUri, p1, null, null, p1[1] + " DESC");
if (c1.MoveToFirst())
{
String uristringpic = "content://media/external/images/media/" + c1.GetInt(0);
Android.Net.Uri newuri = Android.Net.Uri.Parse(uristringpic);
Log.Info("TAG", "newuri " + newuri);
var bitmap = MediaStore.Images.Media.GetBitmap(ContentResolver, newuri);
pic = new Picture(_picture.DocumentNo, _picture.LineNo, _picture.ItemNo, Core.Helpers.ConversionHelper.GetStringFromImage(bitmap));
}
c1.Close();
}
}
}
运行此代码我得到System.Console
输出和Log.Info
输出。所以我知道它直到这一行Log.Info("TAG", "newuri " + newuri);
想法?我会很感激。 : - /
LogCat消息:
09-06 13:30:11.910: E/mono(17434): at Android.App.Activity.n_OnActivityResult_IILandroid_content_Intent_ (IntPtr jnienv, IntPtr native__this, Int32 requestCode, Int32 native_resultCode, IntPtr native_data) [0x00013] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.4-branch/9f7cbd60/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.App.Activity.cs:1557