Skip to main content

Rest API data get post:


        Retrofit retrofit = new Retrofit
.Builder()
.baseUrl(Constant.base_url)
.addConverterFactory(GsonConverterFactory.create())
.build();


retrofitClient = retrofit.create(RetrofitClient.class);

Call<OurMainDataClass> call = retrofitClient.getData(Constant.api_token);

call.enqueue(new Callback<OurMainDataClass>() {
@Override
public void onResponse(Call<OurMainDataClass> call, Response<OurMainDataClass> response) {

if (response.isSuccessful())
{
allcontinentslist=response.body().getData();

continents_adapter=new Continents_Adapter(MainActivity.this,MainActivity.this,allcontinentslist);
// recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
recyclerView.setAdapter(continents_adapter);
continents_adapter.notifyDataSetChanged();

for (Continents continents:allcontinentslist)
{
Log.d("resource",continents.getResource());
Log.d("id",String.valueOf(continents.getId()));
Log.d("name",continents.getName());
Log.d("updated_at",continents.getUpdated_at());

}


}

}

@Override
public void onFailure(Call<OurMainDataClass> call, Throwable t) {

Log.d("failed","not data fetch");
}
});

package ruhulbdapp.com.blogspot;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;

public interface RetrofitClient {

@GET("continents")
Call<OurMainDataClass> getData(@Query("api_token") String token);

}

Post request---------------------------------------

Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://jsonplaceholder.typicode.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();

lastLoginObject = new LastLoginObject("dateTime|UNIX", "172.242.228.245");
dataObjectClass = new dataObjectClass("555", "internetEmail", "personGender", "name", lastLoginObject);

MainObjectClass mainObjectClass = new MainObjectClass("MPSfLPolMP80AQJpPc5cYQ",dataObjectClass);
OurRetrofitClient ourRetrofitClient = retrofit.create(OurRetrofitClient.class);
Call<MainResponseObjectClass> res = ourRetrofitClient.GetPostValue(mainObjectClass);

res.enqueue(new Callback<MainResponseObjectClass>() {
@Override
public void onResponse(Call<MainResponseObjectClass> call, Response<MainResponseObjectClass> response) {

String email = response.body().getEmail();
String Name = response.body().getName();
String Gender = response.body().getGender();
String Id = response.body().getId();
LastLoginObject object = response.body().getLast_login();

String time = object.getDate_time();
String ip = object.getIp4();

Log.d("name",Name);
Log.d("email",email);
Log.d("email",email);
Log.d("Id",Id);
Log.d("time",time);
Log.d("ip",ip);

}

@Override
public void onFailure(Call<MainResponseObjectClass> call, Throwable t) {
Log.d("response","fail");
}
});

OurRetrofitClient------------------------------

@POST("q")
Call<MainResponseObjectClass> GetPostValue(@Body MainObjectClass mainObjectClass);




























Comments

Popular posts from this blog

 var val  deference in kotlin  fun main () { var Android_Programing_language : String = "java" println ( "android official programing language: " + Android_Programing_language ) Android_Programing_language = "Kotline" println ( "2019 google announced android official programing language: " + Android_Programing_language ) val Android_MultiPlatform_language : String = "Dart" println ( "multiple device run : " + Android_MultiPlatform_language ) /* Android_MultiPlatform_language="" /* note: var--------------valu changable note: val--------------valu not changable (final) */ */ }
 Firebase Cloud Messaging With  push notification with Image  public class ImageDownload extends AsyncTask < String , Void , Bitmap >{ @Override protected Bitmap doInBackground ( String ... strings ) { InputStream inputStream ; try { URL url = new URL( strings [ 0 ]) ; try { HttpURLConnection connection = ( HttpURLConnection ) url .openConnection() ; connection .connect() ; inputStream = connection .getInputStream() ; return BitmapFactory . decodeStream ( inputStream ) ; } catch ( IOException e ) { e .printStackTrace() ; } } catch ( MalformedURLException e ) { e .printStackTrace() ; } return null; } @Override protected void onPostExecute ( Bitmap bitmap ) { ShowNotification( bitmap ) ; } }
 Android Notification show  public static void shownotification ( Context context , int id , String title , String Content , Intent intent ) { PendingIntent pendingIntent= null; if ( intent != null ) { pendingIntent= PendingIntent . getActivities ( context , id , new Intent[]{ intent } , PendingIntent . FLAG_UPDATE_CURRENT ) ; String NOTIIFCATION_CHANNEL_ID = "UClone android" ; NotificationManager notificationManager = ( NotificationManager ) context .getSystemService( Context . NOTIFICATION_SERVICE ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . O ) { NotificationChannel notificationChannel = new NotificationChannel( NOTIIFCATION_CHANNEL_ID , "" , NotificationManager . IMPORTANCE_HIGH ) ; notificationChannel .setDescription( "" ) ; notificationChannel .enableLights( true ) ; notificationChannel .setLightColor( Color . RED ) ; no...