我有一项服务API
,用于检索数据,并且我设法获取了数据,但是它仍然是API
格式。
我想在发出的通知中显示API
数据,我需要解决此问题的方法...
public class ReminderBoardcast extends BroadcastReceiver {
InterfaceApi mApiService;
String username;
final String usr = "nanda";
List<NotifModel> arraymodel = new ArrayList<>();
Notif_Get adapter;
int total1;
public void onReceive(Context context, Intent intent){
username = usr;
daftar();
}
private void daftar() {
new dapatdata().execute();
}
private class dapatdata extends AsyncTask<Void,Void,Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... voids) {
mApiService = UtilsApi.getApiSerivce();
mApiService.getkelompok(username)
.enqueue(new Callback<List<NotifModel>>() {
@Override
public void onResponse(Call<List<NotifModel>> call, Response<List<NotifModel>> response) {
if (response.isSuccessful()){
try {
if (response == null){
System.out.println("DATA NULL");
}else {
System.out.println("DATA ADA");
List<NotifModel> models = response.body();
arraymodel.addAll(models);
adapter = new Notif_Get(arraymodel, ReminderBoardcast.this);
adapter.notifyDataSetChanged();
System.out.println("TOTAL DATA: "+adapter.getItemCount());
int total = adapter.getItemCount();
}
}catch (Exception e){
System.out.println("EROR");
}
}else {
System.out.println("TIDAK SUKSES");
}
}
@Override
public void onFailure(Call<List<NotifModel>> call, Throwable t) {
}
});
return null;
}
public void jalankan(Context context, Intent intent){
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "notifyLemubit")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("INFO CUSTOMER")
.setContentText("Halo, this is notification")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
notificationManagerCompat.notify(200, builder.build());
}
}
}
在jalankan()
中,它是用于通知的代码,而在daftar()
中,它是用于获取API
的代码
android studio logcat中的输出:enter image description here