Cant create an alarm in Xamerin Android C#
Copied my teacher's simplified code in order to see if the code i wrote was wrong or somthing yet even her's isnt working. Here is it:
private void BtnAlarm_Click(object sender, EventArgs e)
{
Intent intentAlarm = new Intent(this, typeof(AlarmReceiver));
// #2 - Pending intent - > Broadcast
PendingIntent pendingIntent = PendingIntent.GetBroadcast(Application.Context, 1, intentAlarm, 0);
// #3 - Set Alarm Manager
AlarmManager alarmManager = (AlarmManager)GetSystemService(AlarmService);
//30s
alarmManager.SetExactAndAllowWhileIdle(AlarmType.ElapsedRealtimeWakeup,
SystemClock.ElapsedRealtime() + 30 * 1000, pendingIntent);
}
The debugger wont run onto this activity:
public class AlarmReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
}
}
Just to be clear, while running her app the alarm was working.
do you know?
how many words do you know
See also questions close to this topic
-
C# - Adding condition to func results in stack overflow exception
I have a func as part of specification class which sorts the given iqueryable
Func<IQueryable<T>, IOrderedQueryable<T>>? Sort { get; set; }
When i add more than one condition to the func like below , it results in stack overflow exception.
spec.OrderBy(sc => sc.Case.EndTime).OrderBy(sc => sc.Case.StartTime);
The OrderBy method is implemented like this
public ISpecification<T> OrderBy<TProperty>(Expression<Func<T, TProperty>> property) { _ = Sort == null ? Sort = items => items.OrderBy(property) : Sort = items => Sort(items).ThenBy(property); return this; }
Chaining or using separate lines doesn't make a difference.
This problem gets resolved if I assign a new instance of the specification and set it's func, but i don't want to be assigning to a new instance everytime. Please suggest what am i missing here and how to reuse the same instance (if possible).
-
How to projection fields for a dictionary (C#, MongdoDB)
I am trying my luck here, I have a model which is like the following
public class RowData : BaseBsonDefinition { . [BsonExtraElements] [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] public Dictionary<string, object> Rows { get; set; } = new(StringComparer.OrdinalIgnoreCase); . }
In result, the schema in the MongoDB looks like
{ "_id": { "$binary": { "base64": "HiuI1sgyT0OZmcgGUit2dw==", "subType": "03" } }, "c1": "AAA", "c8": "Fully Vac", "c10": "", }
Those c1, c8 and c10 fields are keys from the dictionary, my question is how to dynamic project those fields?
I tried
Builders<RowData>.Projection.Exclude(p => "c1")
It seems the MongoDB driver can not handle a value directly.
Anyone could point me in the correct direction?
Thanks,
-
How do I add new DataSource to an already Databinded CheckBoxList
i'm building a web form that show Database's item(Tables, Rows, FK,...)
I have a CheckBoxList of Tables (
chkListTable
) which will show a new CheckBoxList of Rows (chkListRow
) everytime I SelectedIndexChanged fromchkListTable
. The problem is i can show the items fromchkListTable
with 1 selected item. But i don't know how to showchkListRow
if multiple item fromchkListTable
are selected.Here are my codes:
aspx
:<div> <asp:Label ID="Label2" runat="server" Text="Table: "></asp:Label> <asp:CheckBoxList ID="chkListTable" runat="server" DataTextField="name" DataValueFeild="name" AutoPostBack="true" OnSelectedIndexChanged="chkListTable_SelectedIndexChanged"> </asp:CheckBoxList> </div> <div> <asp:CheckBoxList ID="chkListRow" runat="server" DataTextField="COLUMN_NAME" DataValueField="COLUMN_NAME" RepeatDirection="Horizontal"> </asp:CheckBoxList> </div>
aspx.cs
:protected void chkListTable_SelectedIndexChanged(object sender, EventArgs e) { tableName.Clear(); foreach (ListItem item in chkListTable.Items) { if(item.Selected) { tableName.Add(item.Text.Trim()); } } for(int i = 0; i < tableName.Count; i++) { String query = "USE " + dbname + " SELECT * FROM information_schema.columns" + " WHERE table_name = '" + tableName[i] + "'" + " AND COLUMN_NAME != 'rowguid'"; chkListRow.DataSource = Program.ExecSqlDataReader(query); chkListRow.DataBind(); Program.conn.Close(); } }
Program.cs
:public static bool Connect() { if (Program.conn != null && Program.conn.State == ConnectionState.Open) Program.conn.Close(); try { Program.conn.ConnectionString = Program.constr; Program.conn.Open(); return true; } catch (Exception e) { return false; } } public static SqlDataReader ExecSqlDataReader(String query) { SqlDataReader myreader; SqlCommand sqlcmd = new SqlCommand(query, Program.conn); sqlcmd.CommandType = CommandType.Text; if (Program.conn.State == ConnectionState.Closed) Program.conn.Open(); try { myreader = sqlcmd.ExecuteReader(); return myreader; myreader.Close(); } catch (SqlException ex) { Program.conn.Close(); return null; } }
I want my display to be like this:
[x]Table1 [x]Table2 [ ]Table3 [ ]Row1(Table1) [ ]Row2(Table1) [ ]Row3(Table1) [ ]Row1(Table2) [ ]Row2(Table2)
-
Updating a Single Column In Room Database
That's the function I'm using for updat
private fun updateSettingsDatabase(settingsDao: SettingsDao) { lifecycleScope.launch { settingsDao.update(SettingsEntity( 1, nightMode=nightModeResult, )) } } @Query("SELECT * FROM `settings-table`") fun fetchCurrentSettings(): Flow<List<SettingsEntity>>
I specified
nightMode=
because I thought that this way I'm only updating this colummn, but it turns out that it resets every column, how do I update a single column, while keeping the values the rest of the columns? -
Using EdittextPreference for Goto search
sorry for my poor English. I want to use EditTextPreference in my bottom nav like the pic below, ![screenshot][1]
I have recycleview xml in my project with in many sub cardview layouts(which is scrollable) and I want to create item in the bottom nav which is called "Goto". When the "Goto" item is clicked i want it to pop-up like the screenshot. And when user enters a number(according to the cardviews i.e if the number of cardview is 40 user must enter 1-40) I want to search the cardview by its ID. Thank you and I hope u got it, If u have any questions let me know [1]: https://i.stack.imgur.com/grK8P.jpg
My xml format look like this. As you see in the blow since the cardviews are huge in number it is not cool to scroll all the way down that is why i need Goto item in the bottom nav to search it by its ID when the user click number in the EditTextPreference as u see in the screenshot. i.e The screenshot is not from my app
<LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> .. .. .. .. many more..
-
IOS Launcher in android studio
I'm trying to change the whole Android OS installed app icons into IOS icons, please help me with the proper code or library for android kotlin
-
Azure B2C broken when explicitly-declared value for android:exported is used
My Xamarin.Forms application uses Azure AD B2C for authentication. Currently, I have to use Android 12 instead of Android 10. According to the documentation, it required a certain change:
Warning: If an activity, service, or broadcast receiver uses intent filters and doesn't have an explicitly-declared value for android:exported, your app can't be installed on a device that runs Android 12 or higher.
(https://developer.android.com/about/versions/12/behavior-changes-12#security)
This is my code from MsalActivity.cs:
namespace UserDetailsClient.Droid { [Activity(Exported = false)] [IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault }, DataHost = "auth", DataScheme = "msal5c32fe58-4a77-49ea-8b5d-010c4a684e4f")] public class MsalActivity : BrowserTabActivity { } }
After I added (Exported = false), I was able to deploy and run the app. But now I am not able to log in. The login screen does show up. And the user can enter the credentials, but after submitting, we get stuck on this screen:
Nothing new appears in the output window. How can this be diagnosed and fixed?
-
Convert a short DateTime string with date and time to DateTime
Having trouble with my Android project here trying to convert a string of DateTime into an actual DateTime object. here's the code I wrote:
string strDateTime = reminder.Date + " " + ((ReminderByTime)reminder).ReminderTime; userDateTime = DateTime.ParseExact(strDateTime, "MM/dd/yyyy HH/mm", null);
While running the problem I've checked the values and they do coordinate:
How can I fix this?
-
Alarm with Broadcast not working in my android compose application
I have a android compose application and broadcast not working with alarm.
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> <receiver android:name=".broadcast.EventAlarmBroadcastReceiver" android:exported="false" android:process=":remote" android:enabled="true"> <intent-filter> <action android:name="com.zxy.control_time.app.REMIND_ACTION"/> </intent-filter> </receiver>
kotlin code , setExact function is not working
val intent = Intent(context,EventAlarmBroadcastReceiver::class.java) intent.`package` = BuildConfig.APPLICATION_ID val pendingIntent = PendingIntent.getService( context, EventAlarmBroadcastReceiver.REMIND_INTENT_ID_BASIC_NUMBER + this.id, intent, 0 ) // alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + 5 * 1000,pendingIntent) not working // context.sendBroadcast(intent) working fine
-
Android. Show notification in exact time
I have a question, that has been asked here many times, but I still can't find correct solution.
I need to implement in an app a feature, that will show notification in exact time (for example, show notification every 30 minutes).
I tried use::
- Standard notifications with High Priority flag
- Standard notifications with High Priority flag and disabled doze optimization
- Notifications with Alarm Manager
- Alarm Manager and disabled Doze
Points 2 and 4 are working well, but not enough. In this case notification could be delayed for 3 minutes (if phone is not used in a long time period).
So, the question is :: Is there any way to show notifications in exact time without delay larger than 1 min ??
P.S. It is said everywhere, that using of AlarmManager will drain you battery much. I didn't find that.
-
Is there a way to play Twitch audio without interaction from the user when the phone is asleep?
--First off I am aware this is invasive, I'm trying to make an alarm--
I'm looking to create an Android app that sets an alarm which will play Twitch audio without any interaction from the user. For the alarm part I'm using AlarmManager However I am struggling to get twitch to autoplay on the locked phone screen when the alarm triggers.
My two leading ideas for how to do this (on Android) are:
Idea#1: Embed twitch player in a webpage that is shown on the lockscreen when the alarm triggers: Twitch Embed Fullscreen intent However the player is muted and I haven't been able to find a way around this (and doesn't seem like it is supported) [Similar issue #1]https://discuss.dev.twitch.tv/t/i-am-unable-to-mute-unmute-video-clips-in-twitch-preview/31585 [Similar issue #2]https://discuss.dev.twitch.tv/t/how-to-unmute-clips-on-load/26054/2
Idea #2: Just launch a stream using the Twitch app while the screen is locked. This is currently how I am starting a stream for Youtube audio and it launches while the phone is locked in the background fine. I know there is some functionality for this in the Twitch android app due to being able to play streams without the app open by changing settings in a stream. However currently if I try to launch a stream using Twitch while the screen is locked, as far as I can tell the video doesn't load until the user opens the phone.
So yeah, Is there a way to play Twitch audio without interaction from the user when the phone is asleep?
Thanks