Skip to content

Commit b988f83

Browse files
committed
Bringing 3rd party app to the foreground after Yoti share completion.
- Added comment in Readme file. - Implemented it in Sample app 2. ED-718
1 parent 0acc4a0 commit b988f83

File tree

7 files changed

+64
-8
lines changed

7 files changed

+64
-8
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ We have included both config below :
135135
```
136136
[See this code in one of our sample apps](./sample-app/src/main/java/com/yoti/mobile/android/sdk/sampleapp/ShareAttributesResultBroadcastReceiver.java)
137137

138+
Once you have received the intent from the Yoti app you should start one of your activities so that
139+
your app goes back to the foreground and the user can continue with the flow within your app.
140+
141+
[Check our Sample-app2 to see an example of how this can be done.](./sample-app-2/src/main/java/com/yoti/mobile/android/sampleapp2/recievers/ShareAttributesResultBroadcastReceiver.java)
142+
138143

139144
You will now need to specify your Client SDK ID and Scenario ID from your application dashboard.
140145
The SDK can be initialised like this:

sample-app-2/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
android:supportsRtl="true"
1414
android:theme="@style/AppTheme">
1515

16-
<activity android:name="com.yoti.mobile.android.sampleapp2.MainActivity">
16+
<activity
17+
android:name="com.yoti.mobile.android.sampleapp2.MainActivity"
18+
android:launchMode="singleInstance">
1719
<intent-filter>
1820
<action android:name="android.intent.action.MAIN" />
1921

sample-app-2/src/main/java/com/yoti/mobile/android/sampleapp2/MainActivity.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.yoti.mobile.android.sampleapp2;
22

3+
import android.content.Intent;
34
import android.support.v7.app.AppCompatActivity;
45
import android.os.Bundle;
56
import android.view.View;
@@ -10,16 +11,26 @@
1011
import com.yoti.mobile.android.sdk.exceptions.YotiSDKException;
1112
import com.yoti.sampleapp2.R;
1213

14+
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.PROFILE_EXTRA;
15+
1316
public class MainActivity extends AppCompatActivity {
1417

18+
public static final String LOADING_STATUS = "com.yoti.mobile.android.sampleapp2.LOADING_STATUS";
19+
20+
private YotiSDKButton yotiSDKButton;
21+
private ProgressBar progress;
22+
private TextView message;
23+
1524
@Override
1625
protected void onCreate(Bundle savedInstanceState) {
1726
super.onCreate(savedInstanceState);
1827
setContentView(R.layout.activity_main);
1928

20-
final YotiSDKButton yotiSDKButton = findViewById(R.id.yoti_button);
21-
final ProgressBar progress = findViewById(R.id.progress);
22-
final TextView message = findViewById(R.id.text);
29+
yotiSDKButton = findViewById(R.id.yoti_button);
30+
progress = findViewById(R.id.progress);
31+
message = findViewById(R.id.text);
32+
33+
processExtraData(getIntent());
2334

2435
yotiSDKButton.setOnYotiScenarioListener(new YotiSDKButton.OnYotiButtonClickListener() {
2536
@Override
@@ -38,6 +49,31 @@ public void onStartScenarioError(YotiSDKException cause) {
3849
});
3950
}
4051

41-
}
52+
@Override
53+
protected void onNewIntent(Intent intent) {
54+
super.onNewIntent(intent);
55+
setIntent(intent);
56+
processExtraData(intent);
57+
}
58+
59+
private void processExtraData(Intent intent) {
60+
61+
if (intent.getBooleanExtra(LOADING_STATUS, false)) {
62+
//Set up UI loading status
63+
yotiSDKButton.setVisibility(View.GONE);
64+
progress.setVisibility(View.VISIBLE);
65+
message.setText(R.string.loc_loading_message);
4266

67+
} else if (intent.getBooleanExtra(PROFILE_EXTRA, false)) {
68+
//Start activity that presents the profile
69+
Intent profileIntent = new Intent(this, ProfileActivity.class);
70+
profileIntent.putExtras(intent.getExtras());
71+
startActivity(profileIntent);
4372

73+
// Restore UI
74+
yotiSDKButton.setVisibility(View.VISIBLE);
75+
progress.setVisibility(View.GONE);
76+
message.setText("");
77+
}
78+
}
79+
}

sample-app-2/src/main/java/com/yoti/mobile/android/sampleapp2/ProfileActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class ProfileActivity extends AppCompatActivity {
1919
public static final String ADDRESS_EXTRA = "com.yoti.services.ADDRESS_EXTRA";
2020
public static final String MOBILE_EXTRA = "com.yoti.services.MOBILE_EXTRA";
2121
public static final String GENDER_EXTRA = "com.yoti.services.GENDER_EXTRA";
22+
public static final String PROFILE_EXTRA = "com.yoti.services.PROFILE_EXTRA";
2223

2324
@Override
2425
protected void onCreate(Bundle savedInstanceState) {

sample-app-2/src/main/java/com/yoti/mobile/android/sampleapp2/recievers/ShareAttributesResultBroadcastReceiver.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.yoti.mobile.android.sampleapp2.recievers;
22

33

4+
import android.content.Context;
45
import android.content.Intent;
56

67
import com.yoti.mobile.android.sampleapp2.MainActivity;
@@ -19,8 +20,16 @@ public class ShareAttributesResultBroadcastReceiver extends AbstractShareAttribu
1920
public static final String EXTRA_CANCELLED_BY_USER = "com.yoti.mobile.android.sdk.EXTRA_CANCELLED_BY_USER";
2021

2122
@Override
22-
public boolean onCallbackReceived(String useCaseId, String callbackRoot, String token, String fullUrl) {
23+
public void onReceive(Context context, Intent intent) {
24+
super.onReceive(context, intent);
25+
//Start our activity so the app comes back to the foreground
26+
Intent myActivityIntent = new Intent(mContext, MainActivity.class);
27+
myActivityIntent.putExtra(MainActivity.LOADING_STATUS, true);
28+
mContext.startActivity(myActivityIntent);
29+
}
2330

31+
@Override
32+
public boolean onCallbackReceived(String useCaseId, String callbackRoot, String token, String fullUrl) {
2433
CallbackIntentService.startActionRetrieveProfile(this.mContext, useCaseId, callbackRoot, token, fullUrl);
2534

2635
return true;

sample-app-2/src/main/java/com/yoti/mobile/android/sampleapp2/services/CallbackIntentService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import com.google.gson.Gson;
99
import com.google.gson.GsonBuilder;
10-
import com.yoti.mobile.android.sampleapp2.ProfileActivity;
10+
import com.yoti.mobile.android.sampleapp2.MainActivity;
1111
import com.yoti.mobile.android.sampleapp2.model.Profile;
1212

1313
import java.io.ByteArrayOutputStream;
@@ -24,6 +24,7 @@
2424
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.IMAGE_EXTRA;
2525
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.MOBILE_EXTRA;
2626
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.NAME_EXTRA;
27+
import static com.yoti.mobile.android.sampleapp2.ProfileActivity.PROFILE_EXTRA;
2728

2829
/**
2930
* An {@link IntentService} subclass for handling the call to the backend.
@@ -92,14 +93,15 @@ private void handleActionRetrieveProfile(String callbackUrl, String token, Strin
9293
Gson g = new GsonBuilder().create();
9394
Profile profile = g.fromJson(new String(response), Profile.class);
9495

95-
Intent intent = new Intent(this, ProfileActivity.class);
96+
Intent intent = new Intent(this, MainActivity.class);
9697
intent.putExtra(NAME_EXTRA, profile.getGivenNames() + " " + profile.getFamilyName());
9798
intent.putExtra(EMAIL_EXTRA, profile.getEmailAddress());
9899
intent.putExtra(IMAGE_EXTRA, profile.getSelfie());
99100
intent.putExtra(DOB_EXTRA, profile.getDateOfBirth());
100101
intent.putExtra(ADDRESS_EXTRA, profile.getPostalAddress());
101102
intent.putExtra(MOBILE_EXTRA, profile.getMobNum());
102103
intent.putExtra(GENDER_EXTRA, profile.getGender());
104+
intent.putExtra(PROFILE_EXTRA, true);
103105
startActivity(intent);
104106

105107
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<resources>
22
<string name="app_name">Yoti Android-SDK-Demo</string>
33
<string name="loc_error_unknow">Something went wrong :(</string>
4+
<string name="loc_loading_message">Retrieving your data...</string>
45
</resources>

0 commit comments

Comments
 (0)