Git Product home page Git Product logo

lyft-android-sdk's Introduction

Lyft Android SDK

The Official Lyft Android SDK makes it easy to integrate Lyft into your app. More specifically, it provides:

  • An easily configurable Lyft button which can display cost, ETA, and ride type. Tapping the button deeplinks into the Lyft app with pre-filled pickup/destination/ridetype.
  • A Java interface for making sync/async calls to Lyft's REST APIs
  • Two sample Android Activities that show how to use the SDK components.

Registration

  • You must first create a Lyft Developer account here.
  • Once registered, you will be assigned a Client ID and will be able to generate Client Tokens.

Setup and Installation

Gradle:

repositories {
  mavenCentral() // or jcenter()
}

dependencies {
    compile 'com.lyft:lyft-android-sdk:2.0.2'
}

If you only want to use the Lyft API Wrapper or Deeplink portion of the SDK, you can pull them individually.

compile 'com.lyft:lyft-android-sdk-networking:2.0.2'  // Lyft API Wrapper
compile 'com.lyft:lyft-android-sdk-deeplink:2.0.2'    // Deeplink

Maven:

<dependency>
  <groupId>com.lyft</groupId>
  <artifactId>lyft-android-sdk</artifactId>
  <version>2.0.2</version>
  <type>aar</type>
</dependency>

Lyft Button

Adding the Lyft Button in an XML layout is as simple as:

<com.lyft.lyftbutton.LyftButton
    android:id="@+id/lyft_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    lyft:lyftStyle="lyftMulberryDark"
    />

We recommend setting the width/height to wrap_content, which results in a width of 260dp and a height of 50dp. Otherwise, please keep in mind that a smaller width/height may result in undesirable UI, such as overlapping text.

To load ETA/cost:

ApiConfig apiConfig = new ApiConfig.Builder()
        .setClientId("your_client_id")
        .setClientToken("your_client_token")
        .build();

LyftButton lyftButton = (LyftButton) findViewById(R.id.lyft_button);
lyftButton.setApiConfig(apiConfig);

RideParams.Builder rideParamsBuilder = new RideParams.Builder()
        .setPickupLocation(37.7766048, -122.3943576)
        .setDropoffLocation(37.759234, -122.4135125);
rideParamsBuilder.setRideTypeEnum(RideTypeEnum.STANDARD);

lyftButton.setRideParams(rideParamsBuilder.build());
lyftButton.load();

Addresses can also be used for pickup/dropoff locations. Each address results in an extra API call to obtain the corresponding lat/lng pair. Therefore, we recommend using lat/lng values directly if they are available.

RideParams.Builder rideParamsBuilder = new RideParams.Builder()
        .setPickupAddress("185 Berry St, San Francisco, CA 94107")
        .setDropoffAddress("2300 Harrison St, San Francisco, CA 94110");

Ride types

Lyft is growing very quickly and is currently available in these cities. Please keep in mind that some ride types (such as Lyft Line) are not yet available in all Lyft cities. If you set the ride type of the button and it happens to be unavailable, the button will default to the Lyft Standard ride type. You can utilize the /v1/ridetypes endpoint to get a list of the available ride types in an area.

Button styles

To specify the button style via XML, use the lyft:lyftStyle attribute or set it programmatically:

lyftButton.setStyle(LyftStyle.MULBERRY_DARK);

There are 5 styles to pick from:

lyft-styles

Lyft API Wrapper

The SDK provides wrapper methods around Lyft's REST APIs - this can be helpful when you want to build a more custom integration with the Lyft platform vs making HTTP requests directly.

The SDK uses Square's Retrofit 2 networking library. For each Lyft API endpoint, there is a corresponding Java method. The return type is a Call object which can be executed synchronously or asynchronously. See LyftApi.java for all the API methods.

LyftApi lyftPublicApi = new LyftApiFactory(apiConfig).getLyftApi();
Call<EtaEstimateResponse> etaCall = lyftPublicApi.getEtas(37.7766048, -122.3943576, "lyft");

Asynchronous:

etaCall.enqueue(new Callback<EtaEstimateResponse>() {
    @Override
    public void onResponse(Call<EtaEstimateResponse> call, Response<EtaEstimateResponse> response) {
        EtaEstimateResponse etaEstimateResponse = response.body();
        Eta eta = etaEstimateResponse.eta_estimates.get(0);
    }

    @Override
    public void onFailure(Call<EtaEstimateResponse> call, Throwable t) {
        Log.d("MyApp", t.toString());
    }
});

Synchronous:

EtaEstimateResponse etaEstimateResponse = etaCall.execute().body();
Eta eta = etaEstimateResponse.eta_estimates.get(0);

RxJava Observables

If you already use RxJava (your app must have it as a dependency), then you can obtain an Observable instead of a Call object. Simply use LyftApiRx instead of LyftApi.

LyftPublicApiRx lyftPublicApiRx = new LyftApiFactory(apiConfig).getLyftPublicApiRx();
Observable<EtaEstimateResponse> etaObservable = lyftPublicApiRx.getEtas(37.7766048, -122.3943576, "lyft");

ProGuard

If you are directly using the Lyft Wrapper API without using the Lyft Button, then you may need to add the the ProGuard rules for Retrofit. Please see proguard-rules.pro. This only applies if you are using ProGuard.

Deeplinking

The SDK provides direct deeplinking to the Lyft app for those developers who prefer to handle their own custom deeplinking vs relying on the Lyft Button.. The deeplink module of the SDK includes this logic and makes it easy to launch the Lyft app.

DeepLinkParams deepLinkParams = new DeepLinkParams.Builder()
        .setClientId("your_client_id")
        .setRideType(RideTypeEnum.SHARED)
        .setPickupLocation(37.7766048, -122.3943576)
        .setDropoffLocation(37.759234, -122.4135125)
        .build();

DeepLink.launchLyftApp(getContext(), deepLinkParams);

Sample Activities

Checkout the sample activites which are included in the SDK, in the sample-app module:

  • SampleBasicActivity: Includes minimal code to set up the Lyft Button.
  • SampleLocationAwareActivity: Gets the device's current GPS location and calls the /v1/ridetypes endpoint to get a list of the available ride types in the area (i.e. Lyft Line, Lyft Plus, etc). The user is able to select an available ride type via a dropdown. The Lyft Button then displays the current ETA and cost of that ride type to a specified destination.

You can specify which activity to launch in the sample-app's AndroidManifest.xml.

Support

If you're looking for help configuring or using the SDK, or if you have general questions related to our APIs, the Lyft Developer Platform team provides support through our forum as well as on Stack Overflow (using the lyft-api tag)

Reporting security vulnerabilities

If you've found a vulnerability or a potential vulnerability in the Lyft Android SDK, please let us know at [email protected]. We'll send a confirmation email to acknowledge your report, and we'll send an additional email when we've identified the issue positively or negatively.

lyft-android-sdk's People

Contributors

acityinohio avatar awaht avatar eveliotc avatar istalev avatar pardom avatar slowhill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lyft-android-sdk's Issues

Crash: LyftButton#displayCost referring to CostEstimate#estimated_cost_cents_min which is null starting Aug 25, 2021

We're getting a crash in the SeatGeek app due to the LyftButton failing to set the cost on the button as a result its API request for cost estimates, with this field (and presumably others it can't reach) being null or omitted from the response.

Stack trace:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
       at com.lyft.lyftbutton.LyftButton.displayCost(LyftButton.java:191)
       at com.lyft.lyftbutton.LyftButton.access$300(LyftButton.java:21)
       at com.lyft.lyftbutton.LyftButton$2.onSuccess(LyftButton.java:160)
       at com.lyft.lyftbutton.LyftButtonCallManager$4.onResponse(LyftButtonCallManager.java:184)
       at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.lambda$onResponse$0(DefaultCallAdapterFactory.java:89)
       at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.lambda$onResponse$0$DefaultCallAdapterFactory$ExecutorCallbackCall$1(DefaultCallAdapterFactory.java:3)
       at retrofit2.-$$Lambda$DefaultCallAdapterFactory$ExecutorCallbackCall$1$hVGjmafRi6VitDIrPNdoFizVAdk.run(-.java:3)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8595)

LyftButton Showing Without ETA/Cost

I ran your provided SampleBasicActivity and the LyftButton shows up but without ETA/Cost information, do I have to turn on some property specifically for ETA/Cost to appear?

Remove dependency on org.jetbrains:annotations-java5

There are several other annotations packages that do not cause packaging conflicts when used with standard jetbrains annotations. For example, you could use the more standard org.jetbrains:annotations or the androidx.annotation:annotation packages.

Example of packaging error seen when using this SDK with a build environment that also uses the org.jetbrains:annotations package:

   > Duplicate class org.intellij.lang.annotations.Flow found in modules jetified-annotations-16.0.1 (org.jetbrains:annotations:16.0.1) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)

Get current ride status

In my android application, I have integrated lyft sdk. I am not booking the ride from application but user will book ride from Lyft application and my application should be able to know what is the ETA of assigned driver arrival ? Which api I should use ?

Deeplink parameter makes Lyft app crash

If I specify only pickup[address] the Lyft app crashes with this error:

06-18 23:06:50.786 27039-27039/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: me.lyft.android, PID: 27039
    java.lang.RuntimeException: Unable to resume activity {me.lyft.android/me.lyft.android.ui.MainActivity}: java.lang.NullPointerException
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1388)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.NullPointerException
        at com.lyft.common.Objects.c(SourceFile:71)
        at me.lyft.android.ui.RideTypesDeepLinkRoute.forwardGeocode(SourceFile:178)
        at me.lyft.android.ui.RideTypesDeepLinkRoute.route(SourceFile:97)
        at com.lyft.android.deeplinks.GenericDeepLinkRouter.routeAction(SourceFile:63)
        at com.lyft.android.deeplinks.GenericDeepLinkRouter.routeDeepLink(SourceFile:18)
        at com.lyft.android.deeplinks.DeepLinkManager.a(SourceFile:68)
        at com.lyft.android.deeplinks.DeepLinkManager.a(SourceFile:22)
        at me.lyft.android.ui.MainActivity.checkForDeepLink(SourceFile:496)
        at me.lyft.android.ui.MainActivity.onResume(SourceFile:326)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258)
        at android.app.Activity.performResume(Activity.java:6327)

Here is the log on my app (just before the crash):

I/Taxi: redirect to lyft://ridetype?id=lyft&pickup[address]=via borgo palazzo 1, Bergamo&destination[latitude]=45.467237&destination[longitude]=9.189705
I/ActivityManager: START u0 {act=android.intent.action.VIEW dat=lyft://ridetype?id=lyft&pickup[latitude]=via borgo palazzo 1, Bergamo&destination[latitude]=45.467237&destination[longitude]=9.189705 flg=0x10000000 cmp=me.lyft.android/.ui.MainActivity} from uid 10085 on display 0

I know it's not strictly related to this SDK but I didn't know where to open this elsewhere.

Lyft Android SDK integration issue

I am integrating Lyft android SDK in my android app, using instruction given in below page

https://github.com/lyft/lyft-android-sdk

But I am getting below error while running app on mobile device:-

FAILURE: Build failed with an exception.

•What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDevDebug'.

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

•Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

•Get more help at https://help.gradle.org

BUILD FAILED in 3m 33s

I added multiDexEnabled true in default config of app gradle to resolve this issue but it doesn't work.

I am using Android Studio 3.0.1 and gradle 4.1 version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.