Skip to content

Commit 0674932

Browse files
committed
Implement purchase check
1 parent 00e3c68 commit 0674932

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ android {
5252
}
5353

5454
dependencies {
55+
implementation 'androidx.appcompat:appcompat:1.3.1'
5556
}

app/src/main/AndroidManifest.xml

+15-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525
<application
2626
android:allowBackup="false"
2727
android:icon="@mipmap/ic_launcher"
28-
android:label="@string/app_name" />
28+
android:label="@string/app_name"
29+
android:theme="@style/Theme.AppCompat">
30+
31+
<activity
32+
android:name=".MainActivity"
33+
android:exported="true">
34+
35+
<intent-filter>
36+
<action android:name="android.intent.action.MAIN" />
37+
<category android:name="android.intent.category.INFO" />
38+
</intent-filter>
39+
40+
</activity>
41+
42+
</application>
2943

3044
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)