I have 3 issues to upgrading at android 13 and i don't know to solve
Hello everybody!
Issue number 1:
In principally the problems are when the app is background or the moblie is in idle mode for example the vibration only works when the app its foreground or only when it lets open a new activity if it is in this mode. I even tried previously to bring the app to the foreground but it doesn't work for me i try to do the following:
Intent intent = new Intent(AndroidApp.Context, typeof(MainActivity)); intent.AddFlags(ActivityFlags.BroughtToFront | ActivityFlags.ReorderToFront | ActivityFlags.NewTask);
AndroidApp.Context.StartActivity(intent);
MainActivity.instance.GoToActivity(typeof(AlertActivity));
in MainActivity
public void GoToActivity(Type myActicity)
{
StartActivity(myActicity);
}
my Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="3" android:versionName="Actions" package="com.DCVSYS.Adminsentinel" android:installLocation="auto">
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="33" /> <application android:label="AdminSentinel" android:theme="@style/MainTheme"> <activity android:name="com.DCVSYS.Adminsentinel.MainActivity" android:label="AdminSentinel" android:icon="@mipmap/icon" android:exported="true" android:theme="@style/MainTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
</activity>
<activity android:name="com.DCVSYS.Adminsentinel.AlertActivity" android:theme="@style/MyTheme.Splash" android:exported="false"> <intent-filter>
<action android:name="android.intent.action.MAIN" /> </intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
</manifest>
Activities
[Activity(Name= "com.DCVSYS.Adminsentinel.MainActivity", Label = "AdminSentinel", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, Exported=true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity :global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
...
}
[Activity(Name = "com.DCVSYS.Adminsentinel.AlertActivity", Theme = "@style/MyTheme.Splash", MainLauncher = false, NoHistory = true, Exported = false)]
public class AlertActivity : AppCompatActivity
{
...
}
in background or idle not shows the Alertactivity, this Activity has sound and vibration if when is in idle only make the sound and vibration is good for me too.
Issue number 2:
I'm using an Shedule Alarm i have the permission declared and the .CanScheduleExactAlarms() returns true
this alarm when is executed is reprogramed again by default is each 30 seconds
i try to use .SetExactAndAllowWhileIdle, .SetAndAllowWhileIdle, .SetExact, .Set methods, but all this have the same behavior.
in the foreground and in the background it is acceptable even though it is not exact they appear many times 30 but there are also delays of 10, 20 and 30 seconds more.
the problem is in idle mode can be 10,12, 13 times more than the programed value!
this is my alarm receiver
[BroadcastReceiver(Enabled = true, Label = "Local Notification Broadcast Receiver", Exported =true)]
public class AlarmHandler : BroadcastReceiver, IPolling
{
static Intent intent =
new Intent(AndroidApp.Context, typeof(AlarmHandler));
private static DateTime TimeAnterior;
private static DateTime ActualTime;
private static DateTime TimeGlobalAnterior;
private PowerManager.WakeLock _cpuWakeLock;
public override void OnReceive(Context context, Intent intent)
{
Task.Run(() =>
{
PowerManager powerManager= (PowerManager)AndroidApp.Context.GetSystemService("power");
_cpuWakeLock = powerManager.NewWakeLock(WakeLockFlags.Partial, "AlarmWakeLock");
_cpuWakeLock.Acquire(); //keeps awake cpu
if (!App.AppIsRunning) // the app is killed, Launch again
{
Intent _intent = new Intent(AndroidApp.Context, typeof(MainActivity)); _intent.AddFlags(ActivityFlags.FromBackground | ActivityFlags.NewTask); _intent.PutExtra("background", true); PendingIntent pendingIntent = pendingIntent = PendingIntent.GetActivity(context, 0, _intent, PendingIntentFlags.OneShot | PendingIntentFlags.Immutable);
Settings.IniAppInBackground = "true";
}
if (Settings.Stadistics == "true")
Stadistics();
if (Settings.Running == "true")
PollingInitialize();
ConnectionManager.Interval();
TimeAnterior = DateTime.Now;
_cpuWakeLock.Release(); });
}
public void PollingInitialize()
{
DateTime? notifyTime = DateTime.Now.AddSeconds(Convert.ToDouble(Settings.PollingPeriod)); PendingIntent pendingIntent = PendingIntent.GetBroadcast(AndroidApp.Context, 1, intent, PendingIntentFlags.CancelCurrent | PendingIntentFlags.Immutable); long triggerTime = GetNotifyTime(notifyTime.Value);
AlarmManager alarmManager = AndroidApp.Context.GetSystemService(Context.AlarmService) as AlarmManager; if (alarmManager.CanScheduleExactAlarms())
{
alarmManager.SetExactAndAllowWhileIdle(AlarmType.RtcWakeup, triggerTime, pendingIntent);
}
else
alarmManager.SetAndAllowWhileIdle(AlarmType.RtcWakeup, triggerTime, pendingIntent);
}
Issue number 3:
this is my .ActionBootCompleted receiver, it do the same intent to start main activity
like before, when the app is killed, but the inten not works, the app is not launched
PD:
all the NuGet packages are allready updated, running with VS 2022 17.7.4
What is your opinion? is it the OS of my mobile? or what am i doing wrong?
many thanks in advance any kind of help is welcome, I'm desperate!
Best Regards
Dani