Answer the question
In order to leave comments, you need to log in
How to call Android not from an Activity?
In the RecyclerAdapter class, I handle the button click:
final Button buttonCall = (Button)dialog.findViewById(R.id.buttonCall);
buttonCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Intent callIntent = new Intent(context, MainActivity.class);
callIntent.setAction(Intent.ACTION_CALL);
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setData(Uri.parse("tel:"+911));
context.startActivity(callIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(context, "Error" + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
Context
private final Context context;
public RecyclerAdapter(List<Item> items, Activity activity, Context context) {
this.items = items;
this.activity = activity;
this.context = context;
}
recyclerAdapter = new RecyclerAdapter(itemArrayList, this, getApplicationContext());
Answer the question
In order to leave comments, you need to log in
For calls, the application context is not suitable, you need to use the activity context.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question