Xamarin Form: Is Google Drive File Dialog available? - xamarin

I have get the Android to load a file dialog for google drive after authorization. Now I have to do it on Xamarin Form but unable to find a file picker for google drive. Does google drive have a file picker for Xamarin Form.
public void RequestGoogleDrivePicker() {
IntentSender intentSender =
Android.Gms.Drive.DriveClass.DriveApi.NewOpenFileActivityBuilder ()
.SetMimeType (new string[] { "application/pdf" })
.Build (GoogleApiClient);
try {
StartIntentSenderForResult ( intentSender, GOOGLE_REQUESTING_OPENER_CODE, null, 0, 0, 0);
} catch (Android.Content.IntentSender.SendIntentException e) {
}
}

Google Drive file browser dialog for Xamarin.Forms?
Short answer: No
Longer answer: Yes, but...
1) You either use the "native" platform Drive SDKs that contain pre-build file browser dialogs for Android and iOS and do this via a Forms' dependency service like you already started in the Xamarin.Android code in your question.
2) You skip the "native" mobile libraries, use the C# PCL-based Google Nugets in your Forms' project and build your own file dialog in Forms as there are no dialogs in these libraries as they are convenience wrappers for the Drive's REST API.
Nugets:
Google.Apis
Google.Apis.Auth
i.e. You can retrieve all the files in Drive, you would need to present these in a UI of your own design (Listview, ...), see link below for full sample:
IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files;
if (files != null && files.Count > 0)
{
foreach (var file in files)
{
Console.WriteLine("{0} ({1})", file.Name, file.Id);
}
}
else
{
Console.WriteLine("No files found.");
}
Google Drive .NET Quickstart

Related

NativeScript Monetization and Ads, AdMob plugin

I want to create a paid app with nativescript and keep it in "play store". But I want to allow to download my app as "free with ads" in it. Which option should I use? If I choose the paid version then it is not available to download so should I choose "pay in app" ?
https://play.google.com/about/monetization-ads/payments/
I intend to use NativeScript AdMob plugin to manage ads but how can I know that user has paid already and I should to not init my ads for him?
https://plugins.nativescript.rocks/plugin/nativescript-admob
Let's assume you are using nativescript-admob plugin alongside nativescript-purchase. Then you could track when a product is purchased or restored and "remember" this via the application-settings module.
For example,
import {getBoolean, setBoolean } from "tns-core-modules/application-settings";
// ... more code follow here
if (transaction.transactionState === TransactionState.Purchased) {
/* Purchase of the FULL version */
if (transaction.productIdentifier.indexOf(".full") >= 0) {
setBoolean(transaction.productIdentifier, true);
}
// ... more code follows here
Then, before opening an AdMob advertisement, check if the product is puchased via the getBoolean.
For example:
this.isPurchased = getBoolean(fullVersionPurchase); // fullVersionPurchase === transaction.productIdentifie
if (!this.isPurchased) {
this.showBanner(); // where showBaneer is your AdMob functionality
}
And following the same logic, you could directly close the banner immediately after a successful purchase (or restore).
if (transaction.transactionState === TransactionState.Purchased) {
if (transaction.productIdentifier.indexOf(".full") >= 0) {
setBoolean(transaction.productIdentifier, true);
}
try {
admob.hideBanner();
} catch (err) { }
With the above approach, you could create a free app that comes with AdMob and then when a user purchases the full version to immediately provide the full version functionalities. See here for more details on the nativescript-purchase functionalities.

Download path in Xamarin iOS

I am using Xamarin.Forms and written the code to download the file for the iOS
platform. It is downloading the file successfully without any error. But after downloading it, I am not able to find the downloaded file in my apple device.
During debugging I found that it is showing
/var/mobile/Containers/Data/Application/1234567A-B8CD-9EF9-C850-9G73587DC7C/Documents/XF_Downloads/hausmann_abcd.jpg
path. So at which location file get saved? below is the image for the same.
I have written below code for this
public class IosDownloader : IDownloader
{
public event EventHandler<DownloadEventArgs> OnFileDownloaded;
public void DownloadFile(string url, string folder)
{
string pathToNewFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), folder);
Directory.CreateDirectory(pathToNewFolder);
try
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
string pathToNewFile = Path.Combine(pathToNewFolder, Path.GetFileName(url));
webClient.DownloadFileAsync(new Uri(url), pathToNewFile);
}
catch (Exception ex)
{
if (OnFileDownloaded != null)
OnFileDownloaded.Invoke(this, new DownloadEventArgs(false));
}
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
if (OnFileDownloaded != null)
OnFileDownloaded.Invoke(this, new DownloadEventArgs(false));
}
else
{
if (OnFileDownloaded != null)
OnFileDownloaded.Invoke(this, new DownloadEventArgs(true));
}
}
}
When a file is saved on an application it is a temporary url within the app's sandbox. To make this image file be publicly accessible through Apple's Photos, You'll have to use native code to do a request to add a new PHImageAsset to the photos library.
In forms you would need to access the native frameworks and therefore run native code. There are plenty of examples of doing this online if you don't know how to already. But here is an introduction if you want to run native code within a shared code framework. https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction
Here is a sample of taking that temp file URL and saving it to Photos Framework once you can code w/ native Xamarin.iOS frameworks:
public void AddImageUrlToPhotosLibrary(string urlToSaveToPhotos)
{
PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => {
//This is bound to native https://developer.apple.com/documentation/photokit/phassetchangerequest/1624060-creationrequestforasset
//Parameter is an NSURL of path to image.
PHAssetChangeRequest.FromImage(new NSUrl(urlToSaveToPhotos));
}, (completed, error) => {
if (completed)
{
if (error != null)
{
Console.WriteLine($"Failed saving image asset {error.LocalizedDescription}");
} else
{
Console.WriteLine($"Successfully saved image to photos library.");
}
}
});
}
I am not able to find the downloaded file in my apple device.
If you use a simulator, you can directly find the folder in the mac by entering the path in the
your mac --> select Finder --> Then open the Go menu --> Click Go to Folder as I described in this thread:
Where can I find the MyDocuments folder on iPhone Simulator?
If you installed the app in a real device. You can browse the file in
Xcode --> Devices and Simulators --> download container as described in this thread:
Browse the files created on a device by the iOS application I'm developing, after downloading the container, you can right click it and choose Show Package Contents. Then you can see the folders.
You can also access the file by the path in the project.

Get IntelliJ IDEA/Android Studio Opened Project Folder with ElectronJS Application

I'm trying to make an application which can communicate with android studio, but IntelliJ plugin SDK is not giving me enough option to build the features that I want, so I'm thinking about trying a different approach to create a separate windows application for functionality but as application needs to know the project folder that is currently opened with android studio, I'm trying to search the same from 4-5 days but haven't found anything helpful if this is possible to read folder location of open project in android studio with a different application please help me, if there is some way that building plugin that can send location to external application please tell me.
Thank you
Just manage to achieve the same with WPF, still don't know if electron can do it or not
if someone is finding the answer for this here's my approach, not the best and final but just figured out how I can do it make sure you will optimize code before implementation
private void Button_Click(object sender, RoutedEventArgs e)
{
var allProcesses = Process.GetProcesses();
String data = "";
for(int a =0; a < allProcesses.Length; a++)
{
Console.WriteLine(data);
if (allProcesses[a].MainWindowTitle.Contains("Android"))
{
Console.WriteLine(data);
data = allProcesses[a].MainWindowTitle;
if(data.Contains("["))
{
data = data.Substring(data.IndexOf("["));
data= data.Substring(0, data.IndexOf("]") + 1);
data = data.Replace("[", "");
data = data.Replace("]", "");
Console.WriteLine(data);
MessageBox.Show(data);
return;
}
else
{
MessageBox.Show("Project is not open in Android Studio");
return;
}
}
}
MessageBox.Show("Android Studio Not Running");
return;
}

Properly implement In-App Updates in App Center?

I am reading this documentation/article from Microsoft on how to Distribute Mobile apps with app center. The problem is I really don't understand how to implement this. I have a app on app center (Android) I want to implement mandatory update so that I can eliminate the bugs of the previous version. I tried to distribute the app with mandatory update enabled and it is not working. How can I fix this?
https://learn.microsoft.com/en-us/appcenter/distribution/
Here is what I did I added this code on my App.xaml.cs (XAMARIN FORMS PROJECT):
protected override void OnStart ()
{
AppCenter.Start("android={Secret Code};", typeof(Analytics), typeof(Crashes), typeof(Distribute));
Analytics.SetEnabledAsync(true);
Distribute.SetEnabledAsync(true);
Distribute.ReleaseAvailable = OnReleaseAvailable;
}
bool OnReleaseAvailable(ReleaseDetails releaseDetails)
{
string versionName = releaseDetails.ShortVersion;
string versionCodeOrBuildNumber = releaseDetails.Version;
string releaseNotes = releaseDetails.ReleaseNotes;
Uri releaseNotesUrl = releaseDetails.ReleaseNotesUrl;
var title = "Version " + versionName + " available!";
Task answer;
if (releaseDetails.MandatoryUpdate)
{
answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install");
}
else
{
answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install", "Ask Later");
}
answer.ContinueWith((task) =>
{
if (releaseDetails.MandatoryUpdate || (task as Task<bool>).Result)
{
Distribute.NotifyUpdateAction(UpdateAction.Update);
}
else
{
Distribute.NotifyUpdateAction(UpdateAction.Postpone);
}
});
return true;
}
And here is what I added on my MainActivity.cs(ANDROID PROJECT):
AppCenter.Start("{Secret Code}", typeof(Analytics), typeof(Crashes), typeof(Distribute));
Looking at this App Center documentation here for Xamarin Forms -
You can customize the default update dialog's appearance by implementing the ReleaseAvailable callback. You need to register the callback before calling AppCenter.Start
It looks like you need to swap your current ordering to get in-app updates working.
There could be a lot of different reasons as to why they are not working. As you can see in the Notes here and here,
Did your testers download the app from the default browser?
Are cookies enabled for the browser in their settings?
Another important point you'll read in the links, is that the feature is only available for listed distribution group users. It is not for all your members. You could use a simple version checker for your purpose instead or you could use a plugin.

Open activity in Xamarin Droid UITest

I've started using the Xamarin UITest to verify the behaviour of my application. I wanted to make the tests logically separated (by that I mean, if one test fails the other one should not fail because of the first, they should be independent). My application has multiple activities and I could not find in the documentation how to open a specific Activity.
The closest I could find was:
[SetUp]
public void BeforeEachTest()
{
app = ConfigureApp.Android.LaunchableActivity("MyActivity").StartApp ();
}
But nothing happend. Can I do this? Is there a workaround?
Thanks
A very late response but thought i'd put it up for others to find. In order to launch the app using a specific activity UITest requires two pieces of information, the app name (or APK file path) and the activity name.
Calling StartApp() on the AndroidConfigurator will look as follows for an app that is already installed onto the device or emulator:
app = ConfigureApp
.Android
.InstalledApp("packagename")
.LaunchableActivity("activityname")
.StartApp();
Or as follow for an APK file:
app = ConfigureApp
.Android
.ApkFile("filename")
.LaunchableActivity("activityname")
.StartApp();
try this code:
if (platform == Platform.Android)
{
string currentFile = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
FileInfo fi = new FileInfo(currentFile);
string dir = fi.Directory.Parent.Parent.Parent.FullName;
var PathToAPK = Path.Combine(dir, "LetsGetNative.Droid", "bin", "Debug", "LetsGetNative.Droid.apk");
app = ConfigureApp.Android.ApkFile(PathToAPK).WaitTimes(new WaitTimes()).EnableLocalScreenshots().StartApp();
}
else
{
app = ConfigureApp.iOS.StartApp();
}

Resources