Need help with OkDeepLink?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

jjerry
129 Stars 85 Forks Apache License 2.0 12 Commits 0 Opened issues

Description

OkDeepLink provides a annotation-based api to manipulate android app deep links.

Services available

!
?

Need anything else?

Contributors list

OkDeepLink

Build Status Download

OkDeepLink provides a annotation-based api to manipulate app deep links.

  • register deep links with annotation
    @Path
    @Activity
  • start deep links by service which generates an implementation by
    Annotation-processor
    , auto inject to activity with annotation
    @Service
  • url or bundle parameters auto inject to activity , restore when activity recreate by annotation
    @Query
  • async intercept deep links in ui thread with annotation
    @Intercept
  • support activity result with
    rxJava

Config

In Root Gradle

repositories {
   jcenter()
}
dependencies {
    classpath 'com.hongjun:okdeeplink-gradle:1.0.0'
}

In App Or Lib Gradle

apply plugin: 'okdeeplink.plugin'

if use multiple apt lib, you must use

packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
}

Example

If you want define

old://app/main?key=value
uri, you can do like this

Define Host And Scheme

you can define dispatch activity which receive deep links in your

AndroidManifest.xml
file (using
odl
as an example):

In App AndroidManifest ```xml

            
            

        <data android:host="app" android:scheme="odl"></data>

``

In the future, I will use annotation
@AppLink
which define scheme and host  instead of
AndroidManifest.xml`. I already have a simple way.

In Service File

public interface SampleService {


@Path("/main")
@Activity(MainActivity.class)
void startMainActivity(@Query("key") String key);

}

path must start with "/" when app receive uri like

old://app/main?key=value
,
DeepLinkActivity
will start ,then dispatch the deep link to the appropriate
Activity
.

In Activity Or Fragment File

You also start MainActivity by service in app. ```java public class SecondActivity extends AppCompatActivity {

   @Service
   SampleService sampleService;
   @Query("key")
   String key;


sampleService.startMainActivity("value");

}

### Intercept
If you want Intercept `old://app/second`, you can use `@Intercept`

```java @Intercept(path = "/second") public class SecondInterceptor extends Interceptor { @Override public void intercept(final Call call) { Request request = call.getRequest(); final Intent intent = request.getIntent(); Context context = request.getContext();

    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append("Intercept\n");
    stringBuffer.append("URL: " + request.getUrl() + "\n");

    AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.Theme_AppCompat_Dialog_Alert);
    builder.setTitle("Notice");
    builder.setMessage(stringBuffer);
    builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            call.cancel();
        }
    });
    builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            intent.putExtra("key1", "value3");
            call.proceed();
        }
    });
    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            call.cancel();
        }
    });
    builder.show();
}

}

intercept`old://app/second`

Log

I define

LogInterceptor
, this can log deep links which start、notFound、error , log tag is
OkDeepLink

Other Way

You can start intent action by service

public interface SampleService {

@Action(MediaStore.ACTION_IMAGE_CAPTURE)
Observable<response> startImageCapture();

 @Action(Intent.ACTION_DIAL)
 @Uri("tel:{phone}")
 void startTel(@UriReplace("phone") String phone);

}

    public void startImageCapture(){
        sampleService
                .startImageCapture()
                .subscribe(new Action1() {
                    @Override
                    public void call(Response response) {
                        Intent data = response.getData();
                        int resultCode = response.getResultCode();
                        if (resultCode == RESULT_OK) {
                            Bitmap imageBitmap = (Bitmap) data.getExtras().get("data");
                            ImageView imageView = (ImageView) findViewById(R.id.ImageView_Capture_Image);
                            imageView.setImageBitmap(imageBitmap);
                        }
                    }
                });
    }

public void startTel(String phone){
        sampleService
                .startTel(phone);
    }

Words

It is so simple,then you just do it like

sample

License

Copyright 2017 Hongjun2046

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.