Skip to content

Commit

Permalink
config sender id
Browse files Browse the repository at this point in the history
  • Loading branch information
dkgupta2501 committed May 2, 2018
1 parent 76f4cbc commit 1ad57b2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 48 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
9 changes: 2 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

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

// Retrofit
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup:otto:1.3.8'
implementation 'com.google.code.gson:gson:2.6.2'


}
21 changes: 19 additions & 2 deletions app/src/main/java/com/mobtexting/sms/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.mobtexting.Mobtexting;
import com.mobtexting.MobtextingInterface;
import com.mobtexting.ModelError;
import com.mobtexting.ServerResponse;


public class MainActivity extends AppCompatActivity{

public class MainActivity extends AppCompatActivity implements MobtextingInterface{
private Mobtexting mobtexting;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mobtexting=new Mobtexting(this);
mobtexting.sendSMS("This is a test","7250705072","Mobtext",this);
}

@Override
public void onResponse(ServerResponse serverResponse) {
Log.d("response",serverResponse.getStatus()+" "+serverResponse.getDescription());
}

@Override
public void onError(ModelError modelError) {
Log.d("response",modelError.getStatus()+" "+modelError.getDescription());
}
}
82 changes: 43 additions & 39 deletions mobtextingsms/src/main/java/com/mobtexting/Mobtexting.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,67 @@ public class Mobtexting {
private static final String TAG = "Communicator";
private static final String SERVER_URL = "http://api.mobtexting.com";
private Retrofit retrofit;
private String api_key1;
private String api_key1,sender_id;
private Context context;

public Mobtexting(Context context){
this.context=context;
}

public void sendSMS(String message, String mobile_no, String senderId, final MobtextingInterface mobtextingInterface) {
public void sendSMS(String message, String mobile_no, final MobtextingInterface mobtextingInterface) {
try {
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
Bundle bundle = ai.metaData;
api_key1= bundle.getString("mobtexting.api_key");
sender_id= bundle.getString("mobtexting.sender_id");
}catch (Exception e){
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."));
return;
}
if(api_key1!=null&&!api_key1.equals("")) {

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);

retrofit = new Retrofit.Builder()
.client(httpClient.build())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(SERVER_URL)
.build();

Interface service = retrofit.create(Interface.class);

Call<ServerResponse> call = service.post(api_key1, message, mobile_no, senderId);

call.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {
// response.isSuccessful() is true if the response code is 2xx
if (response.isSuccessful()) {
Log.e(TAG, response.body().toString());
mobtextingInterface.onResponse(response.body());
} else {
try {
Converter<ResponseBody, ModelError> errorConverter = retrofit.responseBodyConverter(ModelError.class, new Annotation[0]);
ModelError error = errorConverter.convert(response.errorBody());
mobtextingInterface.onError(error);
} catch (IOException e) {
e.printStackTrace();
mobtextingInterface.onError(new ModelError("500", "Something Went Wrong!", "Check your internet connection!/parsing Json exception"));
if(sender_id!=null&&!sender_id.equals("")) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);

retrofit = new Retrofit.Builder()
.client(httpClient.build())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(SERVER_URL)
.build();

Interface service = retrofit.create(Interface.class);

Call<ServerResponse> call = service.post(api_key1, message, mobile_no, sender_id);

call.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {
// response.isSuccessful() is true if the response code is 2xx
if (response.isSuccessful()) {
Log.e(TAG, response.body().toString());
mobtextingInterface.onResponse(response.body());
} else {
try {
Converter<ResponseBody, ModelError> errorConverter = retrofit.responseBodyConverter(ModelError.class, new Annotation[0]);
ModelError error = errorConverter.convert(response.errorBody());
mobtextingInterface.onError(error);
} catch (IOException e) {
e.printStackTrace();
mobtextingInterface.onError(new ModelError("500", "Something Went Wrong!", "Check your internet connection!/parsing Json exception"));
}
}
}
}

@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
mobtextingInterface.onError(new ModelError("500", "No Internet", "Check your internet connection!"));
}
});
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
mobtextingInterface.onError(new ModelError("500", "No Internet", "Check your internet connection!"));
}
});
}else{
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."));
}
}else{
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."));
}
Expand Down

0 comments on commit 1ad57b2

Please sign in to comment.