Skip to content

Commit 1ad57b2

Browse files
committed
config sender id
1 parent 76f4cbc commit 1ad57b2

4 files changed

Lines changed: 64 additions & 48 deletions

File tree

0 Bytes
Binary file not shown.

app/build.gradle

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,9 @@ dependencies {
2626
androidTestImplementation 'com.android.support.test:runner:1.0.2'
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
2828

29-
// implementation 'com.github.mobtexting:mobtexting-android-sdk:ea601104d3'
29+
implementation 'com.github.mobtexting:mobtexting-android-sdk:76f4cbcdd4'
3030
implementation 'com.msg91.sendotp.library:library:3.1'
3131

32-
// Retrofit
33-
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.0'
34-
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
35-
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
36-
implementation 'com.squareup:otto:1.3.8'
37-
implementation 'com.google.code.gson:gson:2.6.2'
32+
3833

3934
}

app/src/main/java/com/mobtexting/sms/MainActivity.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@
22

33
import android.support.v7.app.AppCompatActivity;
44
import android.os.Bundle;
5+
import android.util.Log;
56

7+
import com.mobtexting.Mobtexting;
8+
import com.mobtexting.MobtextingInterface;
9+
import com.mobtexting.ModelError;
10+
import com.mobtexting.ServerResponse;
611

712

8-
public class MainActivity extends AppCompatActivity{
9-
13+
public class MainActivity extends AppCompatActivity implements MobtextingInterface{
14+
private Mobtexting mobtexting;
1015
@Override
1116
protected void onCreate(Bundle savedInstanceState) {
1217
super.onCreate(savedInstanceState);
1318
setContentView(R.layout.activity_main);
19+
20+
mobtexting=new Mobtexting(this);
21+
mobtexting.sendSMS("This is a test","7250705072","Mobtext",this);
1422
}
1523

24+
@Override
25+
public void onResponse(ServerResponse serverResponse) {
26+
Log.d("response",serverResponse.getStatus()+" "+serverResponse.getDescription());
27+
}
28+
29+
@Override
30+
public void onError(ModelError modelError) {
31+
Log.d("response",modelError.getStatus()+" "+modelError.getDescription());
32+
}
1633
}

mobtextingsms/src/main/java/com/mobtexting/Mobtexting.java

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)