├── .gitignore ├── .idea └── codeStyles │ └── Project.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── feizhang │ │ └── applink │ │ └── sample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── feizhang │ │ │ └── applink │ │ │ └── sample │ │ │ ├── MainActivity.java │ │ │ ├── MyApplication.java │ │ │ ├── OrderDetailActivity.java │ │ │ └── applink │ │ │ ├── AppHome.java │ │ │ ├── NewMsgAlert.java │ │ │ └── product │ │ │ └── OrderDetail.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ └── nofication_small_ic.png │ │ ├── layout │ │ ├── activity_main.xml │ │ └── activity_order_detail.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── feizhang │ └── applink │ └── sample │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── feizhang │ │ └── applink │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── feizhang │ │ │ └── applink │ │ │ ├── AppLink.java │ │ │ ├── AppLinkActivity.java │ │ │ ├── AppLinkParams.java │ │ │ ├── AppLinkUtils.java │ │ │ ├── PushContentReceiver.java │ │ │ ├── PushMessageDbHelper.java │ │ │ ├── PushMessageService.java │ │ │ ├── PushNotificationReceiver.java │ │ │ ├── PushReceiver.java │ │ │ └── RedDotView.java │ └── res │ │ ├── drawable │ │ └── red_dot_view.xml │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── feizhang │ └── applink │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | 67 | *idea -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # applink -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.feizhang.applink.sample" 7 | minSdkVersion 14 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | 29 | implementation project(':library') 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 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 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/feizhang/applink/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.feizhang.applink.sample; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.feizhang.applink.sample", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 12 | 13 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/feizhang/applink/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.feizhang.applink.sample; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.feizhang.applink.AppLinkUtils; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | 17 | findViewById(R.id.openBtn).setOnClickListener(new View.OnClickListener() { 18 | @Override 19 | public void onClick(View v) { 20 | startActivity(new Intent(v.getContext(), OrderDetailActivity.class)); 21 | } 22 | }); 23 | 24 | findViewById(R.id.sendBtn).setOnClickListener(new View.OnClickListener() { 25 | @Override 26 | public void onClick(View v) { 27 | String appLink = "my-scheme://product/OrderDetail?orderId=abc123"; 28 | AppLinkUtils.pushAppLink(v.getContext(), appLink, "您有新消息", "您的订单状态有变更", null); 29 | } 30 | }); 31 | } 32 | } -------------------------------------------------------------------------------- /app/src/main/java/com/feizhang/applink/sample/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.feizhang.applink.sample; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.support.annotation.NonNull; 6 | 7 | import com.feizhang.applink.AppLinkUtils; 8 | import com.feizhang.applink.PushNotificationReceiver; 9 | 10 | public class MyApplication extends Application { 11 | private static final String APP_LINK_PACKAGE = "com.feizhang.applink.sample.applink"; 12 | private static final String SCHEME = "my-scheme"; 13 | 14 | /** 15 | * account id is usually dynamic, it maybe a phone number or a uuid generated by server。 16 | */ 17 | public static String accountId = "account_123"; 18 | 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | AppLinkUtils.setup(APP_LINK_PACKAGE, R.drawable.nofication_small_ic, SCHEME); 23 | PushNotificationReceiver.register(this, new PushNotificationReceiver() { 24 | 25 | @Override 26 | public String getAccount(@NonNull Context context) { 27 | return accountId; 28 | } 29 | 30 | @Override 31 | public int getSmallIcon(@NonNull Context context) { 32 | return R.drawable.nofication_small_ic; 33 | } 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/feizhang/applink/sample/OrderDetailActivity.java: -------------------------------------------------------------------------------- 1 | package com.feizhang.applink.sample; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.view.View; 9 | import android.widget.TextView; 10 | import android.widget.Toast; 11 | 12 | import com.feizhang.applink.AppLink; 13 | import com.feizhang.applink.AppLinkUtils; 14 | import com.feizhang.applink.PushContentReceiver; 15 | import com.feizhang.applink.RedDotView; 16 | 17 | import java.util.Collections; 18 | import java.util.List; 19 | 20 | public class OrderDetailActivity extends AppCompatActivity { 21 | private RedDotView mRedDotView; 22 | 23 | private PushContentReceiver mReceiver = new PushContentReceiver() { 24 | 25 | /** 26 | * 告诉receiver当前可以接收处理哪些appLink, 27 | * 在微信聊天场景就好比可以接收文字消息、表情消息、定位消息等 28 | */ 29 | @Override 30 | public List getAppLinks() { 31 | return Collections.singletonList("my-scheme://product/OrderDetail"); 32 | } 33 | 34 | @Override 35 | public String getAccount(@NonNull Context context) { 36 | return MyApplication.accountId; 37 | } 38 | 39 | /** 40 | * 一般这里我们会再次调用订单接口并刷新当前页面 41 | * @return true: 终止消息传递,即其他receiver收不到此message 42 | */ 43 | @SuppressLint("SetTextI18n") 44 | @Override 45 | public boolean onReceive(@NonNull Context context, @NonNull AppLink appLink) { 46 | Toast.makeText(context, "订单已刷新", Toast.LENGTH_SHORT).show(); 47 | return true; 48 | } 49 | }; 50 | 51 | @Override 52 | protected void onCreate(Bundle savedInstanceState) { 53 | super.onCreate(savedInstanceState); 54 | setContentView(R.layout.activity_order_detail); 55 | 56 | TextView newsText = findViewById(R.id.alertText); 57 | newsText.setOnClickListener(new View.OnClickListener() { 58 | @Override 59 | public void onClick(View v) { 60 | mRedDotView.remove(); 61 | } 62 | }); 63 | 64 | mRedDotView = findViewById(R.id.redDotView); 65 | mRedDotView.setAccount(MyApplication.accountId); 66 | mRedDotView.setAppLinks("my-scheme://NewMsgAlert"); 67 | 68 | findViewById(R.id.sendOrderBtn).setOnClickListener(new View.OnClickListener() { 69 | @Override 70 | public void onClick(View v) { 71 | String appLink = "my-scheme://product/OrderDetail?orderId=abc123"; 72 | AppLinkUtils.pushAppLink(v.getContext(), appLink); 73 | } 74 | }); 75 | 76 | findViewById(R.id.sendNewMsgBtn).setOnClickListener(new View.OnClickListener() { 77 | @Override 78 | public void onClick(View v) { 79 | String appLink = "my-scheme://NewMsgAlert"; 80 | AppLinkUtils.pushAppLink(v.getContext(), appLink); 81 | } 82 | }); 83 | 84 | PushContentReceiver.register(this, mReceiver, true); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/feizhang/applink/sample/applink/AppHome.java: -------------------------------------------------------------------------------- 1 | package com.feizhang.applink.sample.applink; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.annotation.NonNull; 6 | import android.widget.Toast; 7 | 8 | import com.feizhang.applink.AppLink; 9 | import com.feizhang.applink.sample.OrderDetailActivity; 10 | 11 | public class AppHome extends AppLink { 12 | 13 | @Override 14 | public Intent onStartActivity(@NonNull Context context) { 15 | return new Intent(context, OrderDetailActivity.class); 16 | } 17 | 18 | @Override 19 | public void onExecute(@NonNull Context context) { 20 | super.onExecute(context); 21 | Toast.makeText(context, "onExecute", Toast.LENGTH_SHORT).show(); 22 | } 23 | 24 | @Override 25 | public boolean isPrivate() { 26 | return false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/feizhang/applink/sample/applink/NewMsgAlert.java: -------------------------------------------------------------------------------- 1 | package com.feizhang.applink.sample.applink; 2 | 3 | import com.feizhang.applink.AppLink; 4 | 5 | public class NewMsgAlert extends AppLink { 6 | 7 | @Override 8 | public boolean isPrivate() { 9 | return true; 10 | } 11 | 12 | @Override 13 | public boolean shouldSave() { 14 | return true; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/feizhang/applink/sample/applink/product/OrderDetail.java: -------------------------------------------------------------------------------- 1 | package com.feizhang.applink.sample.applink.product; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.annotation.NonNull; 6 | import android.widget.Toast; 7 | 8 | import com.feizhang.applink.AppLink; 9 | import com.feizhang.applink.sample.OrderDetailActivity; 10 | 11 | public class OrderDetail extends AppLink { 12 | 13 | /** 14 | * 构建收到appLink打开页面的Intent 15 | */ 16 | @Override 17 | public Intent onStartActivity(@NonNull Context context) { 18 | String orderId = params.get("orderId"); 19 | Intent intent = new Intent(context, OrderDetailActivity.class); 20 | intent.putExtra("orderId", orderId); 21 | return intent; 22 | } 23 | 24 | /** 25 | * 和{@link #onStartActivity(Context)}一并会执行,当收到appLink时候可以做一些额外的工作 26 | */ 27 | @Override 28 | public void onExecute(@NonNull Context context) { 29 | super.onExecute(context); 30 | Toast.makeText(context, "您的订单有更新", Toast.LENGTH_SHORT).show(); 31 | } 32 | 33 | /** 34 | * 是否特定账户的信息,对于特定账户的订单推送是需要账户隔离的 35 | */ 36 | @Override 37 | public boolean isPrivate() { 38 | return true; 39 | } 40 | 41 | /** 42 | * 是否需要用DB存储,以DB存储是为了下次启动查询到未读状态 43 | */ 44 | @Override 45 | public boolean shouldSave() { 46 | return false; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/nofication_small_ic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daydream123/applink/f2abaf954207dd90943c8e05bc422fefa2a78be5/app/src/main/res/drawable/nofication_small_ic.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |