Skip to content

Commit

Permalink
Fixed Update Alarm code
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbunny2008 committed Jan 5, 2023
1 parent 25638e5 commit 3edd484
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ android {
compileSdkVersion 33
defaultConfig {
applicationId "com.odiousapps.weewxweather"
minSdkVersion 21
minSdkVersion 23
targetSdkVersion 33
versionCode 1000003
versionName "1.0.3"
versionCode 1000004
versionName "1.0.4"
}
buildTypes {
release {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
</intent-filter>
</receiver>
<receiver android:name=".UpdateCheck" />
<receiver android:name="com.odiousapps.weewxweather.Common$AlarmRestart" />
</application>
</manifest>
17 changes: 4 additions & 13 deletions app/src/main/java/com/odiousapps/weewxweather/Common.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.odiousapps.weewxweather;

import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
Expand All @@ -22,7 +21,6 @@
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.text.Html;
import android.util.Base64;
import android.util.Log;
Expand Down Expand Up @@ -152,7 +150,6 @@ long[] getPeriod()
return new long[]{period, 45000};
}

@SuppressLint("UnspecifiedImmutableFlag")
void setAlarm(String from)
{
long[] ret = getPeriod();
Expand All @@ -170,16 +167,10 @@ void setAlarm(String from)
LogMessage(from + " - period == " + period, true);
LogMessage(from + " - wait == " + wait, true);

AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent myIntent = new Intent(context, UpdateCheck.class);
PendingIntent pendingIntent;
if(Build.VERSION.SDK_INT >= 23)
pendingIntent = PendingIntent.getActivity(context, 0, myIntent, PendingIntent.FLAG_IMMUTABLE);
else
pendingIntent = PendingIntent.getActivity(context, 0, myIntent, 0);

if (mgr != null)
mgr.setExact(AlarmManager.RTC_WAKEUP, start, pendingIntent);
Intent myAlarm = new Intent(context.getApplicationContext(), UpdateCheck.class);
PendingIntent recurringAlarm = PendingIntent.getBroadcast(context.getApplicationContext(), 0, myAlarm, PendingIntent.FLAG_IMMUTABLE);
AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarms.setExact(AlarmManager.RTC_WAKEUP, start, recurringAlarm);
}

String getAppversion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
setContentView(R.layout.main_activity);

common = new Common(this);

Expand Down

0 comments on commit 3edd484

Please sign in to comment.