|
3 | 3 | import android.annotation.SuppressLint; |
4 | 4 | import android.content.Context; |
5 | 5 | import android.content.Intent; |
| 6 | +import android.content.pm.PackageInfo; |
| 7 | +import android.content.pm.PackageManager; |
6 | 8 | import android.database.Cursor; |
7 | 9 | import android.graphics.Canvas; |
8 | 10 | import android.graphics.Color; |
|
38 | 40 | import com.google.android.material.snackbar.Snackbar; |
39 | 41 | import com.google.gson.Gson; |
40 | 42 | import com.google.gson.GsonBuilder; |
| 43 | +import com.google.gson.JsonSyntaxException; |
41 | 44 |
|
42 | 45 | import java.io.BufferedReader; |
43 | 46 | import java.io.File; |
44 | 47 | import java.io.FileInputStream; |
45 | 48 | import java.io.FileNotFoundException; |
46 | 49 | import java.io.IOException; |
47 | 50 | import java.io.InputStreamReader; |
| 51 | +import java.net.HttpURLConnection; |
| 52 | +import java.net.URL; |
| 53 | +import java.nio.charset.Charset; |
48 | 54 | import java.util.Collections; |
49 | 55 | import java.util.concurrent.atomic.AtomicBoolean; |
50 | 56 | import java.util.stream.Collectors; |
@@ -77,6 +83,8 @@ protected void onCreate(Bundle savedInstanceState) { |
77 | 83 | INSTANCE = this; |
78 | 84 | Thread.setDefaultUncaughtExceptionHandler(new ExeptionHandlerPrint()); |
79 | 85 |
|
| 86 | + checkUpdate(); |
| 87 | + |
80 | 88 | mAppManager = new AppManager(getApplicationContext()); |
81 | 89 | mNoteAdapter = new NoteAdapter(mAppManager.getNoteList(), this); |
82 | 90 | binding = ActivityMainBinding.inflate(getLayoutInflater()); |
@@ -287,6 +295,42 @@ protected void onCreate(Bundle savedInstanceState) { |
287 | 295 | }); |
288 | 296 | } |
289 | 297 |
|
| 298 | + private void checkUpdate() { |
| 299 | +// PackageManager manager = getApplicationContext().getPackageManager(); |
| 300 | +// PackageInfo info; |
| 301 | +// try { |
| 302 | +// info = manager.getPackageInfo( |
| 303 | +// getApplicationContext().getPackageName(), 0); |
| 304 | +// } catch (PackageManager.NameNotFoundException e) { |
| 305 | +// throw new RuntimeException(e); |
| 306 | +// } |
| 307 | +// String version = info.versionName; |
| 308 | +// |
| 309 | +// System.out.println("Version: "+version); |
| 310 | +// |
| 311 | +// try { |
| 312 | +// System.out.println("connection"); |
| 313 | +// final HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/repos/ShayF0x/K-Note/releases/latest").openConnection(); |
| 314 | +// //connection.setRequestProperty("User-Agent", USER_AGENT); |
| 315 | +// connection.connect(); |
| 316 | +// |
| 317 | +// if (connection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) { |
| 318 | +// System.out.println("error"); |
| 319 | +// return; |
| 320 | +// } |
| 321 | +// |
| 322 | +// try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF8")))) { |
| 323 | +// System.out.println(reader); |
| 324 | +// } catch (JsonSyntaxException | NumberFormatException ex) { |
| 325 | +// System.out.println("Failed to parse the latest version info."); |
| 326 | +// ex.printStackTrace(); |
| 327 | +// } |
| 328 | +// } catch (IOException ex) { |
| 329 | +// System.out.println("LOG: Failed to get release info from api.github.com."); |
| 330 | +// ex.printStackTrace(); |
| 331 | +// } |
| 332 | + } |
| 333 | + |
290 | 334 | @Override |
291 | 335 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
292 | 336 | switch (requestCode) { |
|
0 commit comments