.NET MAUI app + MediaPicker is crashing with Android.Content.Res.Resources+NotFoundException - xamarin

In my .NET MAUI app, I use the built-in MediaPicker to access user's photos. The app works fine until I tap the icon to access the photos. It then crashes with the following error message:
Android.Content.Res.Resources+NotFoundException Message=Drawable
com.mycompany.myapp:mipmap/appicon with resource ID #0x7f0d0000
I did replace the app icon recently and I also noticed that the app is not using it when I run the app on an actual device. I simply put a new svg file in the Resources/AppIcon folder with the same name as the original i.e. appicon.svg.
In the properties for this file, I set it as MAUIICON.
This is what's in the project file:
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" />
In case, it's helpful, this is how I'm using the MediaPicker:
try
{
var result = await MediaPicker.PickPhotoAsync(new MediaPickerOptions
{
Title = "Pick Image"
});
if (result == null)
return;
}
catch(Exception e)
{
// Log error
}
I never hit the catch block. It just crashes with the error message I mentioned above.
Any idea how to address this issue?

The issue is definitely the AppIcon. Looks like .NET MAUI is not generating correct size icons from the svg that I had under Resources\AppIcon.
The workaround is to manually create the necessary icons -- in my case, I only created one 72x72 -- and placed them in Platforms\Android\Resources\mipmap folder. In my case, the Resources folder was there under Platforms\Android so I just had to create the mipmap folder.
I then had to go into AndroidManifest.xml file and correctly link them:
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:roundIcon="#mipmap/ic_launcher_round" android:supportsRtl="true"></application>
So, in my case the file name for the app icon I manually generated is ic_launcher.png. I did have to have a second image named ic_launcher_round.png.
Looks like .NET MAUI is supposed to do this work but it's not doing it.
The second bonus -- which it shouldn't be -- is that when I now install the app on a device, I see the correct app icon for my app.
Here's a link to the issue I reported. Anyone experiencing this issue should up vote it so that it'll get the team's attention.
https://developercommunity.visualstudio.com/t/Changing-app-icon-of-NET-MAUI-app-then/10090581

Related

No embedded Image appear in xamarinForm

Iam newbie to XamarinForms and I use visual Studio 2017.
I want to add embeddedImage to my app so to the "imagepage.xaml" file I added:
embeddedImg.Source = ImageSource.FromResource("XFDemo.Images.baby.jpg");
and in "imagepage.xaml.cs" I added:
<Image x:Name="embeddedImg" Aspect="AspectFill" />
but no image appear in the app. just a blank page I can see.
please note that the image exist in PCL project inside "Images" folder and I set the "Action Build" of the image to "Embedded resource".
finally I found the solution ...
thats happened because Iam using xamarin live player and there is some limitations with xamarin live player one of these limitations is embedded resources.
check the following link to see those limitations:
enter link description here

Unable To Share Text On Xamarin Form

Hello Everyone I want to share the Text on Xamarin Form using Library plugin.share. I have successfully implemented the library and on android i can able to share the text but in iOS it returns me nothing. i have done the share code on button click event so when i click on button in iOS its doesn't returns me anything.i tried the Below code but doesn't got succeed
CrossShare.Current.Share("Hii alll", "Share");
please help me to get out of this,thanks in advance
You want to take a look at UIActivityViewController, you can find the documentation here https://developer.xamarin.com/api/type/MonoTouch.UIKit.UIActivityViewController/
And Xamarin.Forms specific example http://devcenter.wintellect.com/jwood/implementing-sharing-in-xamarin-forms
This is a bit old, but I was having a similar issue and was able to resolve it.
First of all, you need to add the plugin Plugin.Share to ALL Xamarin.Forms projects (Portable, iOS, Android, UWP).
In the class that references the share code, add...
using Plugin.Share;
using Plugin.Share.Abstractions;
CrossShare.Share() doesn't work with strings, directly. You need to new up a ShareMessage.
var title = "Title For The Share";
var message = "Text to share.";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title });
I can't say specifically to iOS, as I don't have a Mac and can't test that project, but Android and Windows 10 is working.

Launching app within another app

So I'm looking for the best way to open an app within another app on Xamarin forms when the app is install.. Currently I have an external link to the playstore (which loads up the app on play store) but, when the app is installed I'd like to link directly to this..
How would i go about doing this with Xamarin forms? Cheers
Here's how I went about fixing this issue :
Setting up app linking in Xamarin
This is possible but we need to change the code to the app we are linking to.
"App from" (in our case) changes :
To link to another app the change made to the main app is minimal:
1) Create a new URI. E.g. (URI AppLink = new Uri("http://appto/load");)
2) Set up the link with Device.OpenURI(AppLink);
"App to" (in our case) changes :
Android:
In main activity we need to add an intent filter, here is an example of what this looks like:
[IntentFilter(new [] {Android.Content.Intent.ActionView },
DataScheme="appto",
DataHost="load",
Categories=new [] { Android.Content.Intent.CategoryDefault })]
The DataScheme and DataHost correspond to the uri link above.
iOS:
Within the info.plist file in the advanced tab we need to create a new "url type"
I added an identifier of “com.appto.test” and URL scheme of “appto” (corresponds with uri link)
After these changes are done, the app should link. Atleast with the example it worked.

Windows Phone 7 Development - Image Source Issue

While developing a project for Windows Phone 7, I'm adding an image control onto the Grid and using the following code in C# to set the image source:-
Uri nUri = new Uri("/TestImage.png", UriKind.Relative);
BitmapImage nBitmapImage = new BitmapImage(nUri);
FacebookImage.Source = nBitmapImage;
The problem is that whenever I use custom images, they do not show up when I build and run the app on the emulator. Whereas, if I change the image file name in the above code to one of the images that are included in the project by default (ApplicationIcon.png), the image shows up upon running. I would like to know if this is a problem with the code or with the custom image files I'm using. I'm ensuring that the images I'm creating are proper and have the same attributes as the images included by default.
Could someone please help me out with this.
Thanks.
Click on your custom picture in Visual Studio's Solution Explorer. Then, look at the property window (press F4 if it's closed), and at the "Build Action" line. It basically tells the compiler how to embed your file in the application. The build action of ApplicationIcon.png should be "Content", just set the same one for your custom pictures.

Phonegap on WP7 does not load images

I'm starting my first PhoneGap project and am developing using Visual Studio and Windows Phone 7, although I intend on ultimately deploying to iOS and Symbian as well.
However, I'm stuck at Step 1. I have added an image to the www/images folder, and put the following code:
<img src="images/login-btn.png" width="103" height="42" style="margin-left:90px;" />
And I get:
It works fine when I preview it in IE9, but I don't have a Mac to test it on iOS yet.
It's worth noting that the JS files and CSS have loaded fine, it's just any image (whether referenced in CSS or an <img> tag) always comes up broken.
My guess would be the Build Action of your image file is incorrect.
According to http://wiki.phonegap.com/w/page/48672055/Getting%20Started%20with%20PhoneGap%20Windows%20Phone%207#4Reviewtheprojectstructure section 4. You should be setting the Build Action of your images etc to Content which simply copies them into the output project when it is built. They are probably currently set to Resource or None.
To change the Build Action right click a file and choose properties to go to the properties window if you do not already have it open. It is probably then the first property. Just click and choose the correct one.
I'm posting this to questions that I found while trying to find my answer to the same problem. The JS framework I use adds a url query to each image when in a debugging mode (in order to force browsers to reload image, instead of using cached). So, my image "image/background.jpg" would be accessed as "image/background.jpg?d=34342233". But, when running on PhoneGAP for Windows Phone, it won't recognize the image, and thus it shows up as broken. So, I had to turn off debugging for the framework I use, and suddenly the images showed up (still, don't forget to set the Build Action to "Content" as mentioned earlier).

Resources