Skip to content

Commit ff5b459

Browse files
author
chenhailong
committed
appsp android Demo commit
1 parent d640f33 commit ff5b459

File tree

86 files changed

+4679
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+4679
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion "29.0.2"
6+
defaultConfig {
7+
applicationId "com.anji.appsp.sdktest"
8+
minSdkVersion 21
9+
targetSdkVersion 29
10+
versionCode 1
11+
versionName "0.0.1"
12+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
repositories {
21+
flatDir {
22+
dirs 'libs'
23+
}
24+
}
25+
}
26+
27+
dependencies {
28+
implementation fileTree(dir: 'libs', include: ['*.jar'])
29+
implementation 'androidx.appcompat:appcompat:1.1.0'
30+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
31+
testImplementation 'junit:junit:4.12'
32+
androidTestImplementation 'androidx.test:runner:1.2.0'
33+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
34+
implementation 'com.amap.api:location:latest.integration'
35+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
36+
implementation 'anji.sdk.appsp:aar:0.0.1'
37+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.anji.appsp.sdktest;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.InstrumentationRegistry;
6+
import androidx.test.runner.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getTargetContext();
24+
25+
assertEquals("com.anji.appsp.sdk", appContext.getPackageName());
26+
}
27+
}

app/src/main/AndroidManifest.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.anji.appsp.sdktest">
4+
5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
6+
<uses-permission android:name="android.permission.INTERNET" />
7+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
8+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9+
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
10+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
11+
<!--android:usesCleartextTraffic="true" 开发阶段用,生产要删除-->
12+
<application
13+
android:name=".AppContext"
14+
android:allowBackup="true"
15+
android:icon="@mipmap/logo"
16+
android:label="@string/app_name"
17+
android:persistent="true"
18+
android:roundIcon="@mipmap/ic_launcher_round"
19+
android:supportsRtl="true"
20+
android:theme="@style/AppTheme"
21+
android:usesCleartextTraffic="true">
22+
<activity android:name="com.anji.appsp.sdktest.MainActivity">
23+
<intent-filter>
24+
<action android:name="android.intent.action.MAIN" />
25+
26+
<category android:name="android.intent.category.LAUNCHER" />
27+
</intent-filter>
28+
</activity>
29+
<activity
30+
android:name="com.anji.appsp.sdktest.update.UpdateTestActivity"
31+
android:label="版本更新"
32+
android:screenOrientation="portrait" />
33+
<activity
34+
android:name="com.anji.appsp.sdktest.notice.NoticeTestActivity"
35+
android:label="公告样式"
36+
android:screenOrientation="portrait" />
37+
<!-- 7.0文件读取 -->
38+
<provider
39+
android:name="androidx.core.content.FileProvider"
40+
android:authorities="com.anji.appsp.sdktest.fileprovider"
41+
android:exported="false"
42+
android:grantUriPermissions="true">
43+
<meta-data
44+
android:name="android.support.FILE_PROVIDER_PATHS"
45+
android:resource="@xml/file_paths" />
46+
</provider>
47+
48+
</application>
49+
50+
</manifest>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.anji.appsp.sdktest;
2+
3+
import android.app.Application;
4+
5+
import com.anji.appsp.sdk.AppSpConfig;
6+
7+
public class AppContext extends Application {
8+
private static AppContext mInstance;
9+
public static final String appKey = "24b14615101b4fe0ab9595d6e1d5e428";
10+
11+
public static AppContext getInstance() {
12+
return mInstance;
13+
}
14+
15+
@Override
16+
public void onCreate() {
17+
super.onCreate();
18+
AppSpConfig.getInstance().init(this, appKey);
19+
mInstance = this;
20+
}
21+
22+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.anji.appsp.sdktest;
2+
3+
import android.Manifest;
4+
import android.content.Context;
5+
import android.content.pm.PackageManager;
6+
import android.content.res.Resources;
7+
import android.telephony.TelephonyManager;
8+
import android.util.DisplayMetrics;
9+
import android.util.Log;
10+
11+
12+
public class DeviceUtil {
13+
protected static String sDeviceId;
14+
static int screen_width;
15+
static int screen_height;
16+
static int screen_density_dpi;
17+
static int stateBar_height;
18+
private static String packageName;
19+
20+
public static int getVerCode(Context context) {
21+
int verCode = -1;
22+
try {
23+
verCode = context.getPackageManager().getPackageInfo("com.jinjiajinrong.zq", 0).versionCode;
24+
} catch (PackageManager.NameNotFoundException e) {
25+
Log.e("msg", e.getMessage());
26+
}
27+
return verCode;
28+
}
29+
30+
public static String getVerName(Context context) {
31+
String verName = "";
32+
try {
33+
verName = context.getPackageManager().getPackageInfo("com.jinjiajinrong.zq", 0).versionName;
34+
} catch (PackageManager.NameNotFoundException e) {
35+
e.printStackTrace();
36+
}
37+
return verName;
38+
}
39+
40+
public static int getScreenWidth() {
41+
if (screen_width == 0) {
42+
initDeviceInfo();
43+
}
44+
45+
return screen_width;
46+
}
47+
48+
public static int getScreenHeight() {
49+
if (screen_height == 0) {
50+
initDeviceInfo();
51+
}
52+
53+
return screen_height;
54+
}
55+
56+
public static int getStateBarHeight() {
57+
if (stateBar_height == 0) {
58+
int resourceId = Resources.getSystem().getIdentifier(
59+
"status_bar_height", "dimen", "android");
60+
if (resourceId > 0) {
61+
stateBar_height = Resources.getSystem().getDimensionPixelSize(resourceId);
62+
}
63+
}
64+
return stateBar_height;
65+
}
66+
67+
68+
public static int getScreenDpi() {
69+
if (screen_density_dpi == 0) {
70+
initDeviceInfo();
71+
}
72+
73+
return screen_density_dpi;
74+
}
75+
76+
static void initDeviceInfo() {
77+
DisplayMetrics displayMetrics = AppContext.getInstance().getResources().getDisplayMetrics();
78+
screen_width = displayMetrics.widthPixels;
79+
screen_height = displayMetrics.heightPixels;
80+
screen_density_dpi = displayMetrics.densityDpi;
81+
}
82+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.anji.appsp.sdktest;
2+
3+
import android.content.Intent;
4+
import android.os.Build;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
9+
import androidx.appcompat.app.AppCompatActivity;
10+
11+
import com.anji.appsp.sdktest.notice.NoticeTestActivity;
12+
import com.anji.appsp.sdktest.update.UpdateTestActivity;
13+
14+
15+
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
16+
17+
@Override
18+
protected void onCreate(Bundle savedInstanceState) {
19+
super.onCreate(savedInstanceState);
20+
setContentView(R.layout.activity_main);
21+
TextView cur_version = (TextView) findViewById(R.id.cur_version);
22+
cur_version.setText("当前版本为:" + BuildConfig.VERSION_NAME + " 版本号: " + BuildConfig.VERSION_CODE);
23+
findViewById(R.id.version).setOnClickListener(this);
24+
findViewById(R.id.notice).setOnClickListener(this);
25+
}
26+
27+
@Override
28+
public void onClick(View v) {
29+
switch (v.getId()) {
30+
case R.id.version:
31+
Intent intent = new Intent(this, UpdateTestActivity.class);
32+
startActivity(intent);
33+
break;
34+
case R.id.notice:
35+
intent = new Intent(this, NoticeTestActivity.class);
36+
startActivity(intent);
37+
38+
break;
39+
default:
40+
break;
41+
42+
}
43+
}
44+
45+
}

0 commit comments

Comments
 (0)