SMS Gateway with API Nexmo


Hello Sobat, Hari ini saya akan memberikan tutorial membuat aplikasi sms gateway menggunakan API Nexmo hanya saja penyedia sms gateway ini berbayar tapi sobat jangan kawatir karena layanan nexmo memberikan gratis sms sebesar 2 euro jadi sobat gratis sms, berbeda di artikel sebelumnya sms gateway menggunakan zenziva jadi hampir sama dengan nexmon hanya berbeda API saja, Jadi untuk membuat aplikasi ini sobat tinggal lihat tutorialnya di artikel sebelumnya, untuk lebih jelasnya lihat vidio berikut.



Artikel Sebelumnya
Lihat artikel sebelumnya untuk membuat aplikasi ini hanya saja ada bagian yang diubah, artikel sebelumnya disini

Register Nexmo
Jika sudah daftar akan terlihat seperti gambar dibawah, simpan key dan secret danmasukan pada class MainActivity.java




Source Code
Ganti di bagian class ActionSMS.java dan DataService.java

  • ActionSMS.java
/* 
 * Copyright (c) 2016. Tanwir. All Rights Reserver. 
 * <p> 
 * Save to the extent permitted by law, you may not use,copy,modify, 
 * distribute or create derivative works of this material or any part 
 * of it without the prior written consent of Tanwir. 
 * <p> 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software. 
 */ 
 
package com.codetr.tanwir.actionsend.model; 
 
/** 
 * Created by tanwir on 27/07/2017. 
 */ 
public class ActionSMS { 
 
    private String api_key; 
    private String api_secret; 
    private String to; 
    private String from; 
    private String text; 
 
    public String getApi_key() { 
        return api_key; 
    } 
 
    public void setApi_key(String api_key) { 
        this.api_key = api_key; 
    } 
 
    public String getApi_secret() { 
        return api_secret; 
    } 
 
    public void setApi_secret(String api_secret) { 
        this.api_secret = api_secret; 
    } 
 
    public String getTo() { 
        return to; 
    } 
 
    public void setTo(String to) { 
        this.to = to; 
    } 
 
    public String getFrom() { 
        return from; 
    } 
 
    public void setFrom(String from) { 
        this.from = from; 
    } 
 
    public String getText() { 
        return text; 
    } 
 
    public void setText(String text) { 
        this.text = text; 
    } 
}

  • DataService.java

/* 
 * Copyright (c) 2016. Tanwir. All Rights Reserver. 
 * <p> 
 * Save to the extent permitted by law, you may not use,copy,modify, 
 * distribute or create derivative works of this material or any part 
 * of it without the prior written consent of Tanwir. 
 * <p> 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software. 
 */ 
 
package com.codetr.tanwir.actionsend.network; 
 
import com.codetr.tanwir.actionsend.model.ActionSMS; 
 
import java.util.List; 
 
import retrofit2.Call; 
import retrofit2.http.GET; 
import retrofit2.http.Path; 
import retrofit2.http.Query; 
 
/** 
 * Created by tanwir on 27/07/2017. 
 */ 
public interface DataService { 
 
    @GET("json?") 
    Call<List<ActionSMS>> SendAction( 
            @Query("api_key") String api_key, 
            @Query("api_secret") String api_secret, 
            @Query("to") String to, 
            @Query("from") String from, 
            @Query("text") String text 
    ); 
}

  • Dibagian MainActivity.java gati parameter sesuai dengan dataservice dan masukan key nexmonya.
/* 
 * Copyright (c) 2016. Tanwir. All Rights Reserver. 
 * <p> 
 * Save to the extent permitted by law, you may not use,copy,modify, 
 * distribute or create derivative works of this material or any part 
 * of it without the prior written consent of Tanwir. 
 * <p> 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software. 
 */ 
 
 
package com.codetr.tanwir.actionsend; 
 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.Toast; 
 
import com.codetr.tanwir.actionsend.model.ActionSMS; 
import com.codetr.tanwir.actionsend.network.DataProvider; 
import com.codetr.tanwir.actionsend.network.DataService; 
 
import java.util.List; 
 
import retrofit2.Call; 
import retrofit2.Callback; 
import retrofit2.Response; 
 
/** 
 * Created by tanwir on 27/07/2017. 
 */ 
public class MainActivity extends AppCompatActivity { 
 
    public static DataService nService; 
    private ActionSMS number; 
    private EditText message, numberphone; 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        DataProvider provider = new DataProvider(); 
        nService = provider.getTService(); 
    } 
 
    public void btnSend(View v) { 
        Toast.makeText(MainActivity.this, "Send message", Toast.LENGTH_SHORT).show(); 
        numberphone = (EditText) findViewById(R.id.editText); 
        message = (EditText) findViewById(R.id.editText2); 
        Call<List<ActionSMS>> call = nService.SendAction("key here", "secret here", 
                numberphone.getText().toString(), "CODETR",message.getText().toString()); 
        call.enqueue(new Callback<List<ActionSMS>>() { 
                         @Override 
                         public void onResponse(Call<List<ActionSMS>> call, Response<List<ActionSMS>> response) { 
                         } 
 
                         @Override 
                         public void onFailure(Call<List<ActionSMS>> call, Throwable t) { 
                         } 
                     } 
        ); 
    } 
}

Hasil Result
Hasil UI dan untuk hasil sms terkirim lihat vidio tutorial




Sekian artikel dari saya semoga bermanfaat. 

Comments

Popular posts from this blog

PRIVACY POLICY - APLICATION BELMANDIYSAH

PRIVACY POLICY BELMANDIYSAH

Menampilkan Data Menggunakan RecyclerView (Retrofit) Part 1