|
| 1 | +/* |
| 2 | + * This file is part of Grocy Android. |
| 3 | + * |
| 4 | + * Grocy Android is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * Grocy Android is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with Grocy Android. If not, see http://www.gnu.org/licenses/. |
| 16 | + * |
| 17 | + * Copyright (c) 2020-2021 by Patrick Zedler and Dominic Zedler |
| 18 | + */ |
| 19 | + |
| 20 | +package xyz.zedler.patrick.grocy.unlock; |
| 21 | + |
| 22 | +import android.content.pm.PackageManager.NameNotFoundException; |
| 23 | +import android.os.Build; |
| 24 | +import android.os.Bundle; |
| 25 | +import androidx.annotation.Nullable; |
| 26 | +import androidx.appcompat.app.AppCompatActivity; |
| 27 | + |
| 28 | +public class MainActivity extends AppCompatActivity { |
| 29 | + |
| 30 | + private final static int PURCHASED = 1; |
| 31 | + private final static int NOT_PURCHASED = 0; |
| 32 | + |
| 33 | + @Override |
| 34 | + protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 35 | + super.onCreate(savedInstanceState); |
| 36 | + |
| 37 | + try { |
| 38 | + String packageName = getApplicationContext().getPackageName(); |
| 39 | + String source; |
| 40 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
| 41 | + source = getPackageManager().getInstallSourceInfo(packageName).getInitiatingPackageName(); |
| 42 | + } else { |
| 43 | + source = getPackageManager().getInstallerPackageName(packageName); |
| 44 | + } |
| 45 | + setResult(source != null && source.equals("com.android.vending") ? PURCHASED : NOT_PURCHASED); |
| 46 | + } catch (Exception ignored) { |
| 47 | + } |
| 48 | + |
| 49 | + finish(); |
| 50 | + } |
| 51 | +} |
0 commit comments