@@ -24,63 +24,67 @@ public class Mobtexting {
2424 private static final String TAG = "Communicator" ;
2525 private static final String SERVER_URL = "http://api.mobtexting.com" ;
2626 private Retrofit retrofit ;
27- private String api_key1 ;
27+ private String api_key1 , sender_id ;
2828 private Context context ;
2929
3030 public Mobtexting (Context context ){
3131 this .context =context ;
3232 }
3333
34- public void sendSMS (String message , String mobile_no , String senderId , final MobtextingInterface mobtextingInterface ) {
34+ public void sendSMS (String message , String mobile_no , final MobtextingInterface mobtextingInterface ) {
3535 try {
3636 ApplicationInfo ai = context .getPackageManager ().getApplicationInfo (context .getPackageName (), PackageManager .GET_META_DATA );
3737 Bundle bundle = ai .metaData ;
3838 api_key1 = bundle .getString ("mobtexting.api_key" );
39+ sender_id = bundle .getString ("mobtexting.sender_id" );
3940 }catch (Exception e ){
4041 mobtextingInterface .onError (new ModelError ("100" , "API key" , "Dear developer. Don't forget to configure <meta-data android:name=\" mobtexting.api_key\" android:value=\" testValue\" /> in your AndroidManifest.xml file." ));
4142 return ;
4243 }
4344 if (api_key1 !=null &&!api_key1 .equals ("" )) {
44-
45- HttpLoggingInterceptor logging = new HttpLoggingInterceptor ();
46- logging .setLevel (HttpLoggingInterceptor .Level .BODY );
47- OkHttpClient .Builder httpClient = new OkHttpClient .Builder ();
48- httpClient .addInterceptor (logging );
49-
50- retrofit = new Retrofit .Builder ()
51- .client (httpClient .build ())
52- .addConverterFactory (GsonConverterFactory .create ())
53- .baseUrl (SERVER_URL )
54- .build ();
55-
56- Interface service = retrofit .create (Interface .class );
57-
58- Call <ServerResponse > call = service .post (api_key1 , message , mobile_no , senderId );
59-
60- call .enqueue (new Callback <ServerResponse >() {
61- @ Override
62- public void onResponse (Call <ServerResponse > call , Response <ServerResponse > response ) {
63- // response.isSuccessful() is true if the response code is 2xx
64- if (response .isSuccessful ()) {
65- Log .e (TAG , response .body ().toString ());
66- mobtextingInterface .onResponse (response .body ());
67- } else {
68- try {
69- Converter <ResponseBody , ModelError > errorConverter = retrofit .responseBodyConverter (ModelError .class , new Annotation [0 ]);
70- ModelError error = errorConverter .convert (response .errorBody ());
71- mobtextingInterface .onError (error );
72- } catch (IOException e ) {
73- e .printStackTrace ();
74- mobtextingInterface .onError (new ModelError ("500" , "Something Went Wrong!" , "Check your internet connection!/parsing Json exception" ));
45+ if (sender_id !=null &&!sender_id .equals ("" )) {
46+ HttpLoggingInterceptor logging = new HttpLoggingInterceptor ();
47+ logging .setLevel (HttpLoggingInterceptor .Level .BODY );
48+ OkHttpClient .Builder httpClient = new OkHttpClient .Builder ();
49+ httpClient .addInterceptor (logging );
50+
51+ retrofit = new Retrofit .Builder ()
52+ .client (httpClient .build ())
53+ .addConverterFactory (GsonConverterFactory .create ())
54+ .baseUrl (SERVER_URL )
55+ .build ();
56+
57+ Interface service = retrofit .create (Interface .class );
58+
59+ Call <ServerResponse > call = service .post (api_key1 , message , mobile_no , sender_id );
60+
61+ call .enqueue (new Callback <ServerResponse >() {
62+ @ Override
63+ public void onResponse (Call <ServerResponse > call , Response <ServerResponse > response ) {
64+ // response.isSuccessful() is true if the response code is 2xx
65+ if (response .isSuccessful ()) {
66+ Log .e (TAG , response .body ().toString ());
67+ mobtextingInterface .onResponse (response .body ());
68+ } else {
69+ try {
70+ Converter <ResponseBody , ModelError > errorConverter = retrofit .responseBodyConverter (ModelError .class , new Annotation [0 ]);
71+ ModelError error = errorConverter .convert (response .errorBody ());
72+ mobtextingInterface .onError (error );
73+ } catch (IOException e ) {
74+ e .printStackTrace ();
75+ mobtextingInterface .onError (new ModelError ("500" , "Something Went Wrong!" , "Check your internet connection!/parsing Json exception" ));
76+ }
7577 }
7678 }
77- }
7879
79- @ Override
80- public void onFailure (Call <ServerResponse > call , Throwable t ) {
81- mobtextingInterface .onError (new ModelError ("500" , "No Internet" , "Check your internet connection!" ));
82- }
83- });
80+ @ Override
81+ public void onFailure (Call <ServerResponse > call , Throwable t ) {
82+ mobtextingInterface .onError (new ModelError ("500" , "No Internet" , "Check your internet connection!" ));
83+ }
84+ });
85+ }else {
86+ mobtextingInterface .onError (new ModelError ("100" , "Sender ID" , "Dear developer. Don't forget to configure <meta-data android:name=\" mobtexting.sender_id\" android:value=\" testValue\" /> in your AndroidManifest.xml file." ));
87+ }
8488 }else {
8589 mobtextingInterface .onError (new ModelError ("100" , "API key" , "Dear developer. Don't forget to configure <meta-data android:name=\" mobtexting.api_key\" android:value=\" testValue\" /> in your AndroidManifest.xml file." ));
8690 }
0 commit comments