Unity not opening plugin activity, package seems incorrect - c#

I am attempting to use this plugin to open an android image picker, however it errors when launched.
The calling script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using LukeWaffel.AndroidGallery;
public class LoadImageWithMagic : MonoBehaviour {
public Image image;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OpenGallery() {
Debug.Log ("It clicked");
AndroidGallery.Instance.OpenGallery (GalleryCallback);
}
public void GalleryCallback() {
image.material.mainTexture = AndroidGallery.Instance.GetTexture ();
AndroidGallery.Instance.ResetOutput ();
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<application
android:theme="#style/UnityThemeSelector"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<activity android:name= "com.lukewaffel.androidgallery.Gallery"></activity>
</application>
</manifest>
Error from logcat:
08-25 09:53:09.029 3458-3474/com.TNOAB.FindMyPet I/Unity: It clicked
(Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-25 09:53:09.036 3458-3474/com.TNOAB.FindMyPet I/Unity: [Singleton] An instance of LukeWaffel.AndroidGallery.AndroidGallery is needed in the scene, so '(singleton) LukeWaffel.AndroidGallery.AndroidGallery (UnityEngine.GameObject)' was created with DontDestroyOnLoad.
(Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
08-25 09:53:09.060 1485-1737/system_process I/ActivityManager: START u0 {cmp=com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery} from uid 10061 on display 0
08-25 09:53:09.082 3458-3474/com.TNOAB.FindMyPet I/Unity: AndroidJavaException: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery}; have you declared this activity in your AndroidManifest.xml?
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.TNOAB.FindMyPet/com.lukewaffel.androidgallery.Gallery}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
at android.app.Activity.startActivityForResult(Activity.java:3745)
at android.app.Activity.startActivityForResult(Activity.java:3706)
at android.app.Activity.startActivity(Activity.java:4016)
at android.app.Activity.startActivity(Activity.java:3984)
at com.lukewaffel.androidgallery.UnityBinder.OpenGallery(UnityBinder.java:12)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.c
It appears that the issue is Unity is prepending my package to the package of the plugin, causing it to not be found. I have attempted to change my package to the package of the plugin and it still had the same error.
I have tried reinstalling the app and still cannot get the gallery to open.

I have discovered that the issue was all of the plugin files were placed into a subdirectory, so unity could not find the AndroidManifest.xml. After moving all of the items out of the subdirectory, the Gallery opened.
As a note to anyone copying the above code, I then discovered an unrelated error, image.material.mainTexture = AndroidGallery.Instance.GetTexture (); should be image.sprite = AndroidGallery.Instance.GetSprite ();

Related

How to configure android packagename within Maui android project?

I have created a dummy maui app. I managed to get the package name with the following code after following App information
#page "/"
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
<ul>
<li>Name: #name</li>
<li>Package: #package</li>
<li>Version: #version</li>
<li>Build: #build</li>
</ul>
#code {
private string name = AppInfo.Current.Name;
private string package = AppInfo.Current.PackageName;
private string version = AppInfo.Current.VersionString;
private string build = AppInfo.Current.BuildString;
protected override async Task OnInitializedAsync()
{
}
}
As you can see from the following image this does work it displays my android application information. but ...
My question is how to configure this Package name shows as com.companyname.blazortest. I would like to be able to supply my company name
There is no appsettings.json file, its not in the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="#mipmap/appicon" android:roundIcon="#mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Im a bit stumped as to where this is configured.
You can change it manually in your .csproj file
<!-- App Identifier -->
<ApplicationId>com.companyname.app.maui</ApplicationId>
or you can change it in project properties
or if you want to change it in android project only you can do it under Android section (it will change your manifest file)

Is my Universal Windows Platform software able to gain the permission that is necessary for initiation of shutdown?

I am desiring addition to my Universal Windows Platform software the ability for it to shut-down its host machine after invocation of it by 1 button-click, however, 0 methods that I have tried thus far have operated:
I have attempted to instruct Windows to shut-down, but shutdown /s /t 120 is not able to operate, specifically after invocation by my application.
Therefore, I attempted uage of native C# code. However, usage of this has informed me that it has not been permitted to invoke shutdown:
ShutdownManager.BeginShutdown(Windows.System.ShutdownKind.Shutdown, TimeSpan.FromSeconds(120));
I have used many methods, but I am not able to remediate this problem.
Relevant files
MainPage.xaml.cs
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System;
using Windows.System;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409.
// Delete the extra namespaces when the application is complete.
namespace Shutdown_Roulette
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Button_click(object sender, RoutedEventArgs e)
{
ShutdownManager.BeginShutdown(Windows.System.ShutdownKind.Shutdown, TimeSpan.FromSeconds(120));
}
}
}
Package.appxmanifest
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
IgnorableNamespaces="uap mp iot">
<Identity
Name="7eb73f1e-b159-4fd0-aab9-4158e57ba08a"
Publisher="CN=rokeb"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="7eb73f1e-b159-4fd0-aab9-4158e57ba08a" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>Shutdown Roulette</DisplayName>
<PublisherDisplayName>Master Roke Julian Lockhart Beedell</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="Shutdown_Roulette.App">
<uap:VisualElements
DisplayName="Shutdown Roulette"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="Shutdown Roulette"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" ShortName="Shutdown Roulette">
</uap:DefaultTile >
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<iot:Capability Name="systemManagement"/></Capabilities>
</Package>
Please do note that I am wanting to use this command on Windows 10, rather than Windows 10 IoT; I merely am attempting to use those commands because they are the only other way I have been able to conceive of invocation of this without reliance upon either PowerShell, Python or the Windows Command Processor.
According to the description of ShowdownManager, it needs the support of IOT SDK, which means it is a platform-limited API (only valid on IOT devices).
In Windows 10 desktop devices, UWP does not have the permission to turn off the device.

Xamarin.Android Firebase.Messaging - D/FirebaseInstanceId(13164): background sync failed: INVALID_SENDER

I am adding push notifications to a Xamarin app in development.
After following guides I've done everything that should allow it to work.
google-services.json downloaded from firebase, added to project and build action set to GoogleServicesJson
play services is available as confirmed in a check
receiver node added to AndroidManifest.xml
FirebaseIIDService implemented
Notification channel is created
mainfest receiver code:
<application android:label="RMS Metro Calendar">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application>
FirebaseIID code (I'm not implementing registration management on the server side):
[Service]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyFirebaseIIDService : FirebaseInstanceIdService
{
const string TAG = "MyFirebaseIIDService";
public override void OnTokenRefresh()
{
var refreshedToken = FirebaseInstanceId.Instance.Token;
Log.Debug(TAG, "Refreshed token: " + refreshedToken);
SendRegistrationToServer(refreshedToken);
}
void SendRegistrationToServer(string token)
{
// Add custom implementation, as needed.
}
}
The app builds and deploys fine, I can sucessfully log out that Play services is available and in logging I get: FirebaseApp initialization successful
However it does not generate a Firebase instance and no Instance.Token is ever received. All I get is the following logging message:
09-19 13:48:31.576 D/FirebaseInstanceId(18578): background sync
failed: INVALID_SENDER, retry in 10s
from which is continues to retry in ever growing time scales.
I'm sure there must be something I've configured incorrectly somewhere with regards to the receiver/IID service implementation, but for the life of me cannot figure it out.
Has anyone else ever come across this? Is there a way I can test the FCM service for my configuration to get back more information on why it is failing?
Thank you!

Problem with Xamarin autostart application

I am currently developing an app to use a barcode scanner, one of the requirements is that app autostart with the device.
so, google on that I found some interest thinks, but when I implemented it fails epicly, the app does not starts.
this is mainfest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="AppConsulta.Droid" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="24" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="AppConsulta.Android" android:icon="#drawable/Logo_Jumbo_Cencosud">
<activity android:name="MainActivity" />
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
and this is my receiver
namespace AppConsulta.Droid
{
[BroadcastReceiver]
[IntentFilter(new[] { Intent.ActionBootCompleted }, Priority = (int)IntentFilterPriority.LowPriority)]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Intent serviceStart = new Intent(context, typeof(MainActivity));
serviceStart.AddFlags(ActivityFlags.NewTask);
context.StartActivity(serviceStart);
}
}
}
using adb.exe I manage to extract the log of the device
and it shows this
10-22 16:33:00.412 2007 2007 E AndroidRuntime: FATAL EXCEPTION: main
10-22 16:33:00.412 2007 2007 E AndroidRuntime: Process: AppConsulta.Droid, PID: 2007
10-22 16:33:00.412 2007 2007 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate receiver AppConsulta.Droid.BootReceiver: java.lang.ClassNotFoundException: Didn't find class "AppConsulta.Droid.BootReceiver" on path: DexPathList[[zip file "/data/app/AppConsulta.Droid-1/base.apk"],nativeLibraryDirectories=[/data/app/AppConsulta.Droid-1/lib/arm, /data/app/AppConsulta.Droid-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]

Xamarin Maps Crashing in Android Emulator

I'm having a bit of an issue with the Xamarin.Forms.Maps and the exceptions are not propagated up into the debugger in a meaningful way to help me diagnose the issue.
I can get it to work, everytime I reinstall Visual Studio. It will work a couple times then eventually it will crash 100% of the time as long as the Map item is in the xaml. I am not remaking the project between running, just reinstalling Visual Studio. I'm running Visual Studio 17 Community.
The error just says:
'Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code).'
I have a valid API Key, and even if I comment out ALL code relating to the Map it eventually happens other than the Xaml that will create it. If I reinstall visual studio I can manipulate the map the first few times I invoke the debugger before it fails.
I wish I could give more information, but I'm pretty new to Xamarin development so I'm a bit unsure why reinstalling Visual Studio fixes the issue, temporarily. Any insight would be much appreciated, as I've spent many hours trying to diagnose and reinstall, but have no idea what the issue could be given the error doesn't really say much of anything. I'd love to provide more information if someone has more ideas for me to check out.
In general, it also fails to deploy eventually also : / which is why I tried an install originally. I'm not sure if this is related.
MainPage.xaml.cs
using System;
using System.Linq;
using System.Text;
using Xamarin.Forms;
using Plugin.Geolocator;
using System.Threading.Tasks;
using System.Collections.Generic;
using Plugin.Geolocator.Abstractions;
namespace LawnDroneCompanion
{
public partial class MainPage : ContentPage
{
private List<Position> RecordedPositions = new List<Position>();
public MainPage()
{
InitializeComponent();
}
private void StopGeoLocatorListening()
{
BeginTrackingRoute.Text = "Begin Tracking";
BeginTrackingRoute.BackgroundColor = Color.Green;
CrossGeolocator.Current.StopListeningAsync();
}
private async void StartGeoLocatorListening(object obj, EventArgs e)
{
if (CrossGeolocator.Current.IsListening)
{
StopGeoLocatorListening();
return;
}
BeginTrackingRoute.Text = "Stop Tracking";
BeginTrackingRoute.BackgroundColor = Color.Red;
CrossGeolocator.Current.DesiredAccuracy = 10;
///This logic will run on the background automatically on iOS, however for Android and UWP you must put logic in background services. Else if your app is killed the location updates will be killed.
await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(1), 1, true, new Plugin.Geolocator.Abstractions.ListenerSettings
{
ActivityType = Plugin.Geolocator.Abstractions.ActivityType.Other,
AllowBackgroundUpdates = true,
DeferLocationUpdates = true,
DeferralDistanceMeters = 1,
DeferralTime = TimeSpan.FromSeconds(1),
ListenForSignificantChanges = true,
PauseLocationUpdatesAutomatically = false
});
Position StartLocation = await CrossGeolocator.Current.GetLastKnownLocationAsync();
//MyMap.MoveToRegion(Xamarin.Forms.Maps.MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(StartLocation.Latitude, StartLocation.Longitude), Xamarin.Forms.Maps.Distance.FromMiles(0.2)));
CrossGeolocator.Current.PositionChanged += GeoLocateHandler;
}
private void DrawNewLocation(Plugin.Geolocator.Abstractions.Position position)
{
if(RecordedPositions.Count > 1000)
{
return;
}
RecordedPositions.Add(position);
//MyMap.MoveToRegion(Xamarin.Forms.Maps.MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude), MyMap.VisibleRegion.Radius));
}
private void GeoLocateHandler(object sender, PositionEventArgs e)
{
Device.BeginInvokeOnMainThread(() =>
{
DrawNewLocation(e.Position);
});
}
}
}
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:LawnDroneCompanion"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
x:Class="LawnDroneCompanion.MainPage">
<ContentPage.Content>
<StackLayout>
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<!-- If I comment this out it works, this comment isn't in my real code -->
<maps:Map x:Name="MyMap" IsShowingUser="True" MapType="Hybrid"/>
</StackLayout>
<Button x:Name="BeginTrackingRoute" HorizontalOptions="FillAndExpand" Text="Begin Tracking" Clicked="StartGeoLocatorListening" BackgroundColor="Green" TextColor="WhiteSmoke" BorderRadius="0"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.LawnDroneCompanion" android:installLocation="auto">
<uses-sdk android:minSdkVersion="25" />
<!-- Google Maps for Android v2 requires OpenGL ES v2 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Allow the application to access Google web-based services. -->
<!-- Google Maps for Android v2 will cache map tiles on external storage -->
<application android:label="LawnDroneCompanion.Android">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="{IMAGINE-MY-KEY-HERE}" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</application>
</manifest>

Categories