I have a rather strange problem that I think is related to permissions. When I run my app in debug mode, it runs fine but when I run it in release mode it crashes. The reason I think it may be related to permissions is when I run the app in debug mode, when it is deployed on my test device (my Samsung phone), it asks me to allow access to photos and media. I've set every permission in the manifest even remotely related to photos and media and have code in MainActivity.cs
to check for those permissions, yet when I run the app in debug on my phone it STILL asks for permission to access Photos and Media. I do not see anything in the manifest that specifically mentions photos, and like I stated earlier, I granted access in the manifest to everything that even mentioned "media". My app also accesses the internet, foreground and other areas that require permissions to be set and I have set those in the manifest and have no issues, just this one. What am I missing here?
My MainActivity.cs
code:
protected override void OnCreate(Bundle savedInstanceState)
{
try
{
if (ActivityCompat.CheckSelfPermission(this, Android.Manifest.Permission.ReadExternalStorage) != Android.Content.PM.Permission.Granted)
{
ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.ReadExternalStorage }, 1);
}
if (ActivityCompat.CheckSelfPermission(this, Android.Manifest.Permission.ForegroundService) != Android.Content.PM.Permission.Granted)
{
ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.ForegroundService }, 1);
}
if (ActivityCompat.CheckSelfPermission(this,Android.Manifest.Permission.Internet) != Android.Content.PM.Permission.Granted)
{
ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.Internet }, 1);
}
if (ActivityCompat.CheckSelfPermission(this,Android.Manifest.Permission.AccessNetworkState) != Android.Content.PM.Permission.Granted)
{
ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.AccessNetworkState }, 1);
}
if (ActivityCompat.CheckSelfPermission(this, Android.Manifest.Permission.AccessMediaLocation) != Android.Content.PM.Permission.Granted)
{
ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.AccessMediaLocation }, 1);
}
if (ActivityCompat.CheckSelfPermission(this, Android.Manifest.Permission.MediaContentControl) != Android.Content.PM.Permission.Granted)
{
ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.MediaContentControl }, 1);
}
if (ActivityCompat.CheckSelfPermission(this, Android.Manifest.Permission.Camera) != Android.Content.PM.Permission.Granted)
{
ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.Camera }, 1);
}
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.logon);
RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
UserDialogs.Init(this);
Button MyButton_Submit = FindViewById<Android.Widget.Button>(Resource.Id.button_submit);
aTextboxUsername = FindViewById<EditText>(Resource.Id.aTextboxUsername);
aTextboxPassword = FindViewById<EditText>(Resource.Id.aTextboxPassword);
InputMethodManager board = (InputMethodManager)GetSystemService(Context.InputMethodService);
board.HideSoftInputFromWindow(aTextboxUsername.WindowToken, 0);
Button MyButton_CreateAccount = FindViewById<Android.Widget.Button>(Resource.Id.button_createaccount);
MyButton_CreateAccount.SetBackgroundColor(Android.Graphics.Color.YellowGreen);
MyButton_Submit.Click += async (sender, e) =>
{
ManualResetEvent resetEvent = new ManualResetEvent(false);
ProgressBarHandler myprogressbar = new ProgressBarHandler(this);
myprogressbar.show();
var thread = new System.Threading.Thread(new ThreadStart(async delegate
{
await SignOn(myprogressbar);
resetEvent.Set();
}));
thread.Start();
await Task.Run(() => resetEvent.WaitOne());
while (thread.ThreadState == ThreadState.Running)
{
await Task.Delay(100);
}
myprogressbar.hide();
if (myprogressbar.ErrorMesage != null)
{
showMessage(myprogressbar.ErrorMesage);
}
};
MyButton_CreateAccount.Click += (sender, e) =>
{
Intent intent = new Intent(this, typeof(CreateAccount));
Bundle bundlee = new Bundle();
intent.PutExtra("TheBundle", bundlee);
StartActivity(intent);
};
}
catch (Exception ex)
{
Utils.LogError("An error occured in MainActivity.cs, the error is: " + ex.Message);
}
}
*** Update ***
This is what I see in the device log:
Time Device Name Type PID Tag Message
06-24 08:58:00.417 Samsung SM-G973U Warning 1141 ContextImpl Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1162 com.android.server.am.AppErrors.crashApplicationInner:579 com.android.server.am.AppErrors.crashApplication:443 com.android.server.am.ActivityManagerService.handleApplicationCrashInner:12323 com.android.server.am.ActivityManagerService.handleApplicationCrash:12258
Force finishing activity My.App/crc64a23c41873b6fbff5.MainActivity
06-24 08:58:00.417 Samsung SM-G973U Info 2468 dumpstate skip_space_check : 0
06-24 08:58:00.417 Samsung SM-G973U Info 2468 dumpstate skeymaster_only: 0, keystore_only: 0
06-24 08:58:00.417 Samsung SM-G973U Info 2468 dumpstate shutdown_broadcast: 0, shutdown_delay: 0
06-24 08:58:00.417 Samsung SM-G973U Info 2468 dumpstate sec_mode : 1 dump_flags : 247031436, booting_delay : 0 booting_enospc : 0 sys_rescue : 0 sys_error : 0 sys_native : 0 sys_watchdog : 0 app_error : 1 app_native : 0 app_anr : 0
06-24 08:58:00.416 Samsung SM-G973U Info 2468 dumpstate do_zip_file: 1 do_vibrate: 0 use_socket: 0 use_control_socket: 0 do_screenshot: 0 is_remote_mode: 0 show_header_only: 0 do_start_service: 0 telephony_only: 0 wifi_only: 0 do_progress_updates: 0 fd: 10 bugreport_mode: BUGREPORT_A_ERROR dumpstate_hal_mode: DEFAULT limited_only: 0 args:
06-24 08:58:00.416 Samsung SM-G973U Warning 1141 ActivityManager crash : My.App,10511
Well, after an 2 day agonizing process I (apparently) figured it out.
I turned off (unchecked) Enable Multi-Dex
in Project->Properties->Android Options
The app now runs in Release mode with no issues.