Skip to content

Commit 417c1de

Browse files
committed
Refactor MetaPull to fetch dynamic app info
Updated MetaPull to retrieve app version, build, and SDK info dynamically using PackageManager and ApplicationInfo instead of hardcoded values. Improved error handling and code structure for maintainability.
1 parent 4566dde commit 417c1de

1 file changed

Lines changed: 40 additions & 48 deletions

File tree

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,50 @@
11
package mgks.os.swv;
22

3-
/*
4-
Smart WebView v7
5-
https://github.com/mgks/Android-SmartWebView
6-
7-
A modern, open-source WebView wrapper for building advanced hybrid Android apps.
8-
Native features, modular plugins, and full customisation—built for developers.
3+
import android.content.Context;
4+
import android.content.pm.ApplicationInfo;
5+
import android.content.pm.PackageInfo;
6+
import android.content.pm.PackageManager;
7+
import android.os.Build;
8+
import android.util.Log;
99

10-
- Documentation: https://docs.mgks.dev/smart-webview
11-
- Plugins: https://docs.mgks.dev/smart-webview/plugins
12-
- Discussions: https://github.com/mgks/Android-SmartWebView/discussions
13-
- Sponsor the Project: https://github.com/sponsors/mgks
10+
import androidx.multidex.BuildConfig;
1411

15-
MIT License — https://opensource.org/licenses/MIT
12+
public class MetaPull {
1613

17-
Mentioning Smart WebView in your project helps others find it and keeps the dev loop alive.
18-
*/
14+
private final Context context;
15+
private static final String TAG = "MetaPull";
1916

20-
import android.os.Build;
17+
public MetaPull(Context context) {
18+
this.context = context;
19+
}
2120

22-
public class MetaPull {
23-
String swv(){
24-
return "SWV.RELEASE : 7.1"
25-
+"\nSWV.BUILD : 7"
26-
+"\nSWV.SDK.MIN : 23"
27-
+"\nSWV.SDK.MAX : 35"
28-
+"\nSWV.BUILD.TYPE : release"
29-
+"\nSWV.BUILD.NAME : 7.1"
30-
+"\nSWV.PACKAGE.NAME : mgks.os.swv";
21+
String swv() {
22+
try {
23+
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
24+
ApplicationInfo appInfo = context.getApplicationInfo();
25+
26+
String buildType = BuildConfig.DEBUG ? "debug" : "release";
27+
int minSdk = appInfo.minSdkVersion;
28+
int targetSdk = appInfo.targetSdkVersion;
29+
30+
return "SWV.RELEASE : " + pInfo.versionName
31+
+ "\nSWV.BUILD : " + pInfo.versionCode
32+
+ "\nSWV.SDK.MIN : " + minSdk
33+
+ "\nSWV.SDK.MAX : " + targetSdk
34+
+ "\nSWV.BUILD.TYPE : " + buildType
35+
+ "\nSWV.BUILD.NAME : " + pInfo.versionName
36+
+ "\nSWV.PACKAGE.NAME : " + context.getPackageName();
37+
38+
} catch (PackageManager.NameNotFoundException e) {
39+
Log.e(TAG, "Could not get package info", e);
40+
return "Error fetching app info.";
41+
}
3142
}
3243

33-
String device(){
34-
return "VERSION.RELEASE : "+Build.VERSION.RELEASE
35-
+"\nVERSION.SDK.NUMBER : "+Build.VERSION.SDK_INT
36-
+"\nMANUFACTURER : "+Build.MANUFACTURER
37-
+"\nMODEL : "+Build.MODEL;
38-
39-
// consider these if really necessary
40-
/*
41-
//+"\nVERSION.INCREMENTAL : "+Build.VERSION.INCREMENTAL
42-
//+"\nBOARD : "+Build.BOARD
43-
//+"\nBOOTLOADER : "+Build.BOOTLOADER
44-
//+"\nDISPLAY : "+Build.DISPLAY
45-
//+"\nFINGERPRINT : "+Build.FINGERPRINT
46-
//+"\nHARDWARE : "+Build.HARDWARE
47-
//+"\nBRAND : "+Build.BRAND
48-
//+"\nHOST : "+Build.HOST
49-
//+"\nID : "+Build.ID
50-
//+"\nPRODUCT : "+Build.PRODUCT
51-
//+"\nTAGS : "+Build.TAGS
52-
//+"\nTIME : "+Build.TIME
53-
//+"\nTYPE : "+Build.TYPE
54-
//+"\nUNKNOWN : "+Build.UNKNOWN
55-
//+"\nUSER : "+ Build.USER;
56-
*/
44+
String device() {
45+
return "VERSION.RELEASE : " + Build.VERSION.RELEASE
46+
+ "\nVERSION.SDK.NUMBER : " + Build.VERSION.SDK_INT
47+
+ "\nMANUFACTURER : " + Build.MANUFACTURER
48+
+ "\nMODEL : " + Build.MODEL;
5749
}
58-
}
50+
}

0 commit comments

Comments
 (0)