TL;DR:
Need to use class Intent
for different things. Found examples online where using Android.Content
is used. This doesn't apply to Xamarin.Forms (I think). What NuGet package is needed for it to work?
Nah.. I got time:
Intro (unnecessary read)
I'm starting out with mobile app development so I'm pretty much clueless about anything. Hoping to get a concise answer here.
My app is primarily WebView
container with some other minor functionalities. I'm using Visual Studio 2019 and Xamarin.Forms, but at the moment I am compiling to Android alone. iOS and UWP are my goal once, at least one app is fully finished for Android.
Problem 1 and where I am
Now I need to add two things. One is "Rate us" and the other is "Share" link, both in the main menu (swipe from left or click the hamburger icon to open it). I already have three list items in the menu, where each of them open a page in the app.
I figured out how to add another item to the menu, but I currently link this list item to market://details?id=com.mycompany.myapp
url of my app on PlayStore. It opens nicely in PlayStore, but after pressing the back button it goes to home screen instead of back to the app.
Current code where I added "Rate Us"
MainPage.xaml.cs
using MyApp.Models;
using Plugin.Geolocator;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace MyApp.Views {
...
public partial class MainPage : MasterDetailPage {
...
public async Task NavigateFromMenu(int id) {
if (!MenuPages.ContainsKey(id) {
switch(id) {
...
case (int)MenuItemType.RateUs:
await Browser.OpenAsync("market://details?id=com.mycompany.myapp", BrowserLaunchMode.SystemPreferred);
// startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.mycompany.myapp")));
break;
...
}
}
...
}
}
}
MenuPage.xaml.cs
using MyApp.Models;
using System.Collections.Generic;
using System.ComponentModel;
using Xamarin.Forms;
namespace MyApp.Views {
...
public partial class MenuPage : ContentPage {
...
public MenuPage() {
InitializeComponent();
menuItems = new List<HomeMenuItem> {
...
new HomeMenuItem { id = MenuItemType.RateUs, Title="Rate Us", Icon="\uf005" },
...
}
}
}
}
HomeMenuItem.cs
namespace MyApp.Models {
public enum MenuItemType {
...
RateUs,
...
}
public class HomeMenuItem {
public MenuItemType Id { get; set; }
public string Title { get; set; }
public string Icon { get; set; }
}
}
What I tried
As you can see in //
comment in MainPage.xaml.cs I found a different solution, that would perhaps return me back to my app after going back from PlayStore.
This particular solution is (obviously???) problematic at startActivity
, tooltip stating
The name 'startActivity' does not exist in the current context
but there are other much more complex solution like THIS ONE that have startActivity
wrapped in public void function()
which - I guess - helps.
Problem 2
I need to add another List Item to side menu titled "Share" where the device will ask which app do you want to share with (or copy to clipboard) and then use that app to share some text and a link of my choosing (same for all users). Again, any LINK I find uses Intent
.
At a complete loss here. If you can't give me the tools and a manual how to use them, at least point me in the right direction please.