如果设备中未安装truecaller,我们可以使用Truecaller SDK吗

时间:2018-12-06 05:10:31

标签: java android

如果我尝试使用以下代码,则我可以使用Truecaller的SDK,并在安装了truecaller的情况下获取用户的个人资料。

//has_truecaller = TrueSDK.getInstance().isUsable(); //doesnt work before init() methof
TrueSdkScope trueScope;
TrueSdkScope.Builder sdkBuilder = new TrueSdkScope.Builder(this, sdkCallback)
            .consentMode(TrueSdkScope.CONSENT_MODE_POPUP )
            .consentTitleOption( TrueSdkScope.SDK_CONSENT_TITLE_VERIFY )
            .footerType( TrueSdkScope.FOOTER_TYPE_SKIP );

if(has_truecaller) {
        trueScope = sdkBuilder.sdkOptions( TrueSdkScope.SDK_OPTION_WITH_OTP ).build();
}else{
        //TODO get mobile number
        BaseActivity.USER_MOBILE_NUMBER = "12345677";
        trueScope = sdkBuilder.sdkOptions( TrueSdkScope.SDK_OPTION_WITH_OTP ).build();
    }
TrueSDK.init(trueScope); 

但是,如果我从设备中删除Truecaller,则会出现以下错误:

2-06 10:38:45.437 25694-25694/com.project.xyz.userclientapp E/AndroidRuntime: FATAL EXCEPTION: main
 Process: com.project.xyz.userclientapp, PID: 25694 java.lang.NoClassDefFoundError:
 Failed resolution of: Lretrofit2/converter/gson/GsonConverterFactory;
 at com.truecaller.android.sdk.b.c.a(Unknown Source:9)
 at com.truecaller.android.sdk.clients.a.<init>(Unknown Source:10)
 at com.truecaller.android.sdk.a.<init>(Unknown Source:46)
 at com.truecaller.android.sdk.a.a(Unknown Source:2)
 at com.truecaller.android.sdk.TrueSDK.init(Unknown Source:5)
 at com.project.xyz.userclientapp.login.LoginActivity.setupTrueSdk(LoginActivity.java:49)
 at com.project.xyz.userclientapp.login.LoginActivity.onCreate(LoginActivity.java:30)
 at android.app.Activity.performCreate(Activity.java:7149)
 at android.app.Activity.performCreate(Activity.java:7140)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
 at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
 at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
 at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
 at android.os.Handler.dispatchMessage(Handler.java:106)
 at android.os.Looper.loop(Looper.java:193)
 at android.app.ActivityThread.main(ActivityThread.java:6863)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

1 个答案:

答案 0 :(得分:0)

您可以使用以下行来检查设备上是否存在Truecaller应用程序- TrueSDK.getInstance().isUsable()

在检查之前,您确实需要使用init()方法初始化SDK。根据是否安装了Truecaller,它将返回布尔值true / false。

此外,您共享的日志是由于缺少android项目中的库依赖关系。您可以尝试在gradle中添加以下依赖项吗?这应该有助于解决错误-

compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4' compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'