File tree Expand file tree Collapse file tree 5 files changed +19
-4
lines changed
java/jp/studyplus/android/sdk/example
StudyplusAndroidSDK/src/main/java/jp/studyplus/android/sdk/service Expand file tree Collapse file tree 5 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,13 @@ ApiRequest request = StudyRecordPostRequest.of(
60
60
.setDurationSeconds(2 * 60 )
61
61
.build()
62
62
);
63
- StudyplusApi . getClient(context). send(request);
63
+
64
+ try {
65
+ StudyplusApi . getClient(context). send(request);
66
+ } catch (AccessTokenNotFound e) {
67
+ e. printStackTrace();
68
+ Toast . makeText(context, " Access token not exists" , Toast . LENGTH_SHORT ). show();
69
+ }
64
70
```
65
71
66
72
### More
Original file line number Diff line number Diff line change 17
17
import jp .studyplus .android .sdk .service .api .StudyplusApi ;
18
18
import jp .studyplus .android .sdk .service .api .response .ErrorResponse ;
19
19
import jp .studyplus .android .sdk .service .api .response .SuccessfulResponse ;
20
+ import jp .studyplus .android .sdk .service .auth .AccessTokenNotFound ;
20
21
import jp .studyplus .android .sdk .service .auth .AuthTransit ;
21
22
import jp .studyplus .android .sdk .service .auth .CertificationStore ;
22
23
import jp .studyplus .android .sdk .service .studyrecord .StudyRecordBuilder ;
@@ -58,7 +59,13 @@ public void onClick(View v) {
58
59
.setDurationSeconds (2 * 60 )
59
60
.build ());
60
61
61
- StudyplusApi .getClient (context ).send (request .with (this ));
62
+ try {
63
+ StudyplusApi .getClient (context ).send (request .with (this ));
64
+ } catch (AccessTokenNotFound e ) {
65
+ e .printStackTrace ();
66
+ Toast .makeText (context , R .string . sample_certification_no_access_token , Toast .LENGTH_SHORT )
67
+ .show ();
68
+ }
62
69
}
63
70
64
71
@ Subscribe
Original file line number Diff line number Diff line change 4
4
<string name =" app_name" >SDK Example</string >
5
5
<string name =" hello_world" >Hello world!!!</string >
6
6
7
+ <string name =" sample_certification_no_access_token" >アクセストークンがありません。先に認証をしてください。</string >
7
8
<string name =" sample_certification_studyplus_not_found" >Studyplus 2.14.0 以上のインストールが必要です。</string >
8
9
</resources >
Original file line number Diff line number Diff line change 2
2
3
3
import android .content .Context ;
4
4
5
+ import jp .studyplus .android .sdk .service .auth .AccessTokenNotFound ;
5
6
import jp .studyplus .android .sdk .service .auth .CertificationStore ;
6
7
7
8
10
11
*/
11
12
public class StudyplusApi {
12
13
13
- public static ApiClient getClient (Context context ){
14
+ public static ApiClient getClient (Context context ) throws AccessTokenNotFound {
14
15
ApiCertification certification = CertificationStore .create (context ).getDefault ();
15
16
return new ApiClient (certification );
16
17
}
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ private Optional<String> findAccessToken(){
46
46
return Optional .fromNullable (preferences .getString (KEY_ACCESS_TOKEN , null ));
47
47
}
48
48
49
- public ApiCertification getDefault (){
49
+ public ApiCertification getDefault () throws AccessTokenNotFound {
50
50
Optional <String > token = findAccessToken ();
51
51
if (!token .isPresent ()){
52
52
throw new AccessTokenNotFound ();
You can’t perform that action at this time.
0 commit comments