OpenIAB dont work Unity3D - android

i include OpenIAB plugin in my Android application in unity3D, but when i test my app on device, purchase window isnt called. Where problem??
void Start() {
OpenIAB.mapSku (SKU, OpenIAB_Android.STORE_GOOGLE, "no_ads");
var options = new OnePF.Options();
options.checkInventory = false;
options.verifyMode = OptionsVerifyMode.VERIFY_EVERYTHING;
options.storeKeys.Add(OpenIAB_Android.STORE_GOOGLE, "My key");
OpenIAB.init(options);
}
void OnGUI(){
if (GUI.Button (new Rect (100, 100, 100, 100), "Push me")) {
OpenIAB.purchaseProduct(SKU);
GUI.TextArea(new Rect(200,200,150,150),"Its work!!!");
}
}
private void OnPurchaseSucceded(Purchase purchase)
{
if (purchase.Sku == SKU)
GUI.TextArea(new Rect(150,150,150,150),"Good job!");
}

GUI functions only work inside OnGUI() call. And GUI.TextArea(new Rect(200,200,150,150),"Its work!!!"); just probably blinks too fast.

Related

Silent printing functionality for Android & iOS application

I am working on iOS & Android application using Xamarin where I am trying to print implement silent printing functionality currently I am using following Android native scripts which always show dialog during print.
Android print script using Webview:
public void Print(WebView viewToPrint)
{
var droidViewToPrint = Platform.CreateRenderer(viewToPrint).ViewGroup.GetChildAt(0) as Android.Webkit.WebView;
if (droidViewToPrint != null)
{
// Only valid for API 19+
var version = Android.OS.Build.VERSION.SdkInt;
if (version >= Android.OS.BuildVersionCodes.Kitkat)
{
var printMgr = (PrintManager)Forms.Context.GetSystemService(Context.PrintService);
printMgr.Print("Forms-EZ-Print", droidViewToPrint.CreatePrintDocumentAdapter(), null);
}
}
}
iOS print script for Text:
public void Print()
{
var printInfo = UIPrintInfo.PrintInfo;
printInfo.JobName = "My first Print Job";
printInfo.OutputType = UIPrintInfoOutputType.General;
var textFormatter = new UISimpleTextPrintFormatter("Once upon a time...")
{
StartPage = 0,
MaximumContentWidth = 6 * 72,
PerPageContentInsets = new UIEdgeInsets(72, 72, 72, 72),
};
var printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
printer.PrintFormatter = textFormatter;
printer.ShowsPageRange = true;
printer.Present(true, (handler, completed, error) =>
{
if (!completed && error != null)
{
Console.WriteLine($"Error: {error.LocalizedDescription ?? ""}");
}
});
printInfo.Dispose();
textFormatter.Dispose();
}
Could please let know how can print silently from iOS and Android application without any print preview or dialog?

Xamarin.Forms Android Custom Animation not working even though it works on UWP. Ideas?

I have a custom animation that expands a Cell inside a TableView. I also refresh the tableView size before/after the animation as appropriate. This works on UWP, and I don't have a Mac yet, so I can't test it on IOS.
This doesn't work at all on Android. It does not refresh the tableRoot to update the size of it, nor does it seem to play the expanding animations.
I say the second part, because when I lock the tableview to the full size it doesn't play.
The animation itself is pretty straight forward:
private void AnimateLinearRowAppear(VisualElement visual, double targetHeight = 40, TableRoot _tableRoot, bool visible)
{
visual.IsVisible = visible;
TableRootRefresher(_tableRoot);
Animation _animation;
_animation = new Animation(
(d) => visual.HeightRequest = d, 0, targetHeight);
_animation.Commit(visual, "The Animation", 16, 250, Easing.Linear, (target, b) =>
{
_animation = null;
});
}
Any one have any ideas as to why it doesn't work on Android?
Unless I'm mistaken this is for cross platform development.
Do I have to write an interface and call each of my animations in a platform specific way?
Oh, this is the latest version of Xamarin 2.3.4.270.
Thanks for any help in advance!
I'm calling the animation from an event such as a specific picker selection or switch.
Switch.toggled += (sender, e) =>
{
AnimationChooser(celltochange,switch.toggle, tableRootCellIsPartOf);
}
AnimationChooser decides if we're playing the appearing or disappearing animation and is working correctly.
private void AnimationChooser(Cell celltoChange, bool stateOfSwitch, TableRoot _tableRoot)
{
var visual = (celltoChange as ViewCell).View
if(visual.IsVisible && stateOfSwitch)
{ AnimateLinearRowDissappear(visual, 40 ,_tableRoot, stateOfSwitch);}
else AnimateLinearRowAppear(visual,40,_tableRoot,stateOfSwitch);
}
TableRootRefresher(TableRoot _tableRoot)
{
Var tempRoot = _tableRoot;
_tableRoot = null;
_tableRoot = tempRoot:
}
The XAML:
<TableView>
<TableRoot x:Name="root">
<TableSection>
<SwitchCell x:Name="switch"/>
<EntryCell x:Name="toAppear" HieghtRequest="0" IsVisible="False"/>
</TableSection>
</TableRoot>
</TableView>
Here is a sample project.
I have used the below codesnippet animation working fine for me.
//animate changed the opacity from 1 to 0.
//XFtabbody is my UI elements
var animation = new Animation(v => XFTabBody.Opacity = v, 1, 0);
Action<double, bool> finished = animate;
animation.Commit(XFTabBody, "aa", 0, 100, Easing.Linear, finished);
void animate(double d, bool b)
{
XFTabBody.Children.Clear();
}

After downloading file .obb not find the next scene

I am making an application in Unity3D and I have a problem with the file .obb. After downloading the file .obb from my dropbox try to open the next scene and tells me I can not find it. If I close the application and return open functioning OK. What can be?
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using UnityEngine.UI;
public class DownloadFile : MonoBehaviour {
private string path;
private string url = "";
private float m_CurrentValue = 0;
public GameObject btnStart;
private string nextScene = "Splash";
void log( string t )
{
print("MYLOG " + t);
}
// Use this for initialization
void Start ()
{
CheckObb ();
}
// Update is called once per frame
void Update () {
}
void CheckObb()
{
if (!GooglePlayDownloader.RunningOnAndroid())
{
log ( "Use GooglePlayDownloader only on Android device!");
return;
}
string expPath = GooglePlayDownloader.GetExpansionFilePath();
if (expPath == null)
{
log("External storage is not available!");
}
else
{
string package = GooglePlayDownloader.Package();
int version = GooglePlayDownloader.Version();
path = String.Format("{0}/main.{1}.{2}.obb", expPath, version, package);
url = String.Format("https://www.dropbox.com/s/xxxxxxxxxxxxxx/main.{0}.{1}.obb?dl=1", version, package);
if (File.Exists(path))
{
// After downloading the file if you close the game and you become open, OK ¿?
Application.LoadLevel(nextScene);
}
else
{
//check if directory doesn't exit
if(!Directory.Exists(expPath))
{
//if it doesn't, create it
Directory.CreateDirectory(expPath);
}
btnStart.SetActive(true);
}
}
}
// Click Start button download obb
public void ClickStart()
{
btnStart.SetActive(false);
StartCoroutine(DownloadObb());
}
// Download obb
IEnumerator DownloadObb() {
WWW download = new WWW(url);
while( !download.isDone ) {
m_CurrentValue = download.progress * 100;
yield return null;
}
if (!string.IsNullOrEmpty(download.error)) {
//Error
} else
{
// success!
File.WriteAllBytes (path, download.bytes);
// Here says that there is the scene
Application.LoadLevel(nextScene);
}
}
}
I tried to upload the apk and obb as alpha version in the developer console but when I go to download the .obb tells me this:
"Download failed because the resources could not be found"
Thanks.
I follow this tutorial in order to split my Unity app into *.obb file. It help me a lot.
Now, when I was performing my test in GooglePlay as an Alpha version everything goes OK, the download of the obb file and the process in the app but it doesn`t load my first scene.
It took me a lot to notice that when I put the loader as the scene 0 my index to load the next Scene was wrong. I know it is a poor error but thats the History behind my 10 hours research.
Hope you'll find useful.

How to navigate in sygic maps

I have integrated sygic in my android application using a surface view. I want to navigate in that sygic application . I have used this code :
SWayPoint wp = new SWayPoint();
wp.Location = new LONGPOSITION(34, 35);
ApplicationAPI.StartNavigation(err, wp, 0, true, false, MAX);
But it is not working. Any ideas ?
I have once implemented Sygic in an app and this is basically how my code looks like (after hours of debug because the documentation was very poor...):
// surfaceView for displaying the "map"
SurfaceView mSygicSurface = (SurfaceView) findViewById(R.id.sygic_surface); // surface
// api status
int mSygicAPIStatus = -2;
// start the drive
ApplicationAPI.startDrive(new ApiCallback() {
public void onRunDrive() {
mSygicSurface.post(new Runnable() {
public void run() {
runDrive(mSygicSurface, getPackageName());
}
});
}
public void onInitApi() // gets called after runDrive();
{
mSygicAPIStatus = ApplicationAPI.InitApi(getPackageName(), true, new ApplicationHandler() { /* nothing relevant here */ }); // api initialization
if (mSygicAPIStatus != 1) {
// error
return;
}
}
});
Once you want to navigate somewhere:
GeoPoint point = new GeoPoint(/* ... */, /* ... */);
final SWayPoint wayPoint = new SWayPoint("", point.getLongitudeE6(), point.getLatitudeE6());
SError error = new SError();
final int returnCode = ApplicationAPI.StartNavigation(error, point, NavigationParams.NpMessageAvoidTollRoadsUnable, true, true, 0);
Carefully note that Sygic uses E6 coordinates.
This is not an answer on the question, but for whose who searching for weird sygic exmaples in 2017 I put it here
ApiMaps.showCoordinatesOnMap(new Position((int)(-84.41949*100000.0),(int)(33.7455*100000.0)),1000,0);
//LONGITUDE first!!
//and multiply on 100 000
//https://developers.sygic.com/reference/java3d/html/classcom_1_1sygic_1_1sdk_1_1remoteapi_1_1_api_maps.html
p.s. this is for standalone apk

Need an example of take a Picture with MonoDroid and MVVMCross

Can anyone point me to an example of take a Photo and store it using MVVMCross?
I have been searching but only have found this:
Monodroid Take a picture with Camera (Doesn't Implement MVVMCross)
Video Recording (It's Video and i can't make it work :S)
The Oficialy Recipe Example (It Works but does not implement MVVMCross)
Thanks!!!
Resolved! Thanks!
To Future References: (Using Master Branch)
Credits to Stuart, I just changed the code to work with my reality
using Cirrious.MvvmCross.ExtensionMethods;
using Cirrious.MvvmCross.Interfaces.Platform.Tasks;
using Cirrious.MvvmCross.Interfaces.ServiceProvider;
using SIGEP.DummyService;
using SIGEP.Mobile.Core.Interfaces;
namespace SIGEP.Mobile.Core.Models
{
public class PhotoService : IMvxServiceConsumer<IMvxPictureChooserTask>
{
private const int MaxPixelDimension = 1024;
private const int DefaultJpegQuality = 92;
public void GetNewPhoto()
{
this.GetService<IMvxPictureChooserTask>().TakePicture(
MaxPixelDimension,
DefaultJpegQuality,
HandlePhotoAvailable,
() => { /* cancel is ignored */ });
}
public event EventHandler<PhotoStreamEventArgs> PhotoStreamAvailable;
private void HandlePhotoAvailable(Stream pictureStream)
{
var handler = PhotoStreamAvailable;
if (handler != null)
{
handler(this, new PhotoStreamEventArgs() { PictureStream = pictureStream, OnSucessGettingPhotoFileName = OnSucessGettingPhotoFileName });
}
}
public static void TakePhoto(Action<string> successFileName, Action<Exception> error)
{
var service = new PhotoService();
service.OnSucessGettingPhotoFileName = successFileName;
service.OnError = error;
service.GetNewPhoto();
service.PhotoStreamAvailable += new EventHandler<PhotoStreamEventArgs>(service_PhotoStreamAvailable);
}
static void service_PhotoStreamAvailable(object sender, PhotoStreamEventArgs e)
{
//grava pra ficheiro!!!
var directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filename = Path.Combine(directory, "photo.jpeg");
string saveTo = filename;
FileStream writeStream = new FileStream(saveTo, FileMode.Create, FileAccess.Write);
ReadWriteStream(e.PictureStream, writeStream);
e.OnSucessGettingPhotoFileName(filename);
}
private static void ReadWriteStream(Stream readStream, Stream writeStream)
{
int Length = 256;
Byte[] buffer = new Byte[Length];
int bytesRead = readStream.Read(buffer, 0, Length);
// write the required bytes
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = readStream.Read(buffer, 0, Length);
}
readStream.Close();
writeStream.Close();
}
public Action<string> OnSucessGettingPhotoFileName { get; set; }
public Action<Exception> OnError { get; set; }
}
[Serializable]
[ComVisible(true)]
public class PhotoStreamEventArgs : EventArgs
{
public Stream PictureStream { get; set; }
public Action<string> OnSucessGettingPhotoFileName { get; set; }
}
}
I generally implement a service using the built-in IMvxPictureChooserTask (this is in a Plugin if using vNext):
using Cirrious.MvvmCross.ExtensionMethods;
using Cirrious.MvvmCross.Interfaces.Platform.Tasks;
using Cirrious.MvvmCross.Interfaces.ServiceProvider;
public class PhotoService
: IMvxServiceConsumer<IMvxPictureChooserTask>
, IPhotoService
{
private const int MaxPixelDimension = 1024;
private const int DefaultJpegQuality = 92;
public void GetNewPhoto()
{
Trace.Info("Get a new photo started.");
this.GetService<IMvxPictureChooserTask>().TakePicture(
MaxPixelDimension,
DefaultJpegQuality,
HandlePhotoAvailable,
() => { /* cancel is ignored */ });
}
public event EventHandler<PhotoStreamEventArgs> PhotoStreamAvailable;
private void HandlePhotoAvailable(Stream pictureStream)
{
Trace.Info("Picture available");
var handler = PhotoStreamAvailable;
if (handler != null)
{
handler(this, new PhotoStreamEventArgs() { PictureStream = pictureStream });
}
}
}
I generally register this service as a singleton during startup, and then call it from a ViewModel ICommand handler.
One app which uses this service is the Blooor sample - see BaseEditProductViewModel.cs - this isn't a sample I had anything to do with, but I believe it brings in both Picture taking and ZXing - both using external services.
One warning: On MonoDroid, you can see some strange/unexpected Activity/ViewModel lifecycle behaviour - basically you can see that the Activity you take the photo from is unloaded/wiped from memory during the photo taking. If this happens to your app then you'll probably need to start looking at questions like: Saving Android Activity state using Save Instance State - this isn't automatically handled in MvvmCross (yet).
I believe the Blooor sample might suffer from this issue - but whether a user would ever see it in normal app use is debatable.
As an alternative to the IMvxPictureChooserTask service, you can also look at using some of the cross-platform APIs from Xamarin.Mobile - see MvvmCross vnext : monodroid use a VideoView inside a plugin for a possible starting place - or for Android only you can easily implement your own.

Categories

Resources