2 years ago
#71020
Zeeshan khan
I want to open webpages within android app?
I have created an application and data of user is loaded via firebase recycler adapter. It have data of users and each user have a link in their profile which redirect to a webpage. Everything is working fine the user is redirected to the webpage via the default browser. My question is how can I restrict the app to open the links/urls within itself. I don't want the links to be opened in the default browser. Below is my code
MyViewholder
class MyViewHolder extends RecyclerView.ViewHolder {
TextView geglink, userName, userAbout;
View v;
public MyViewHolder(@NonNull @NotNull View itemView) {
super(itemView);
geglink = (TextView) itemView.findViewById(R.id.rcvGigLink);
userName = (TextView) itemView.findViewById(R.id.rcvName);
userAbout = (TextView) itemView.findViewById(R.id.rcvAbout);
v = itemView;
DashboardActivity
RecyclerView recyclerView;
FirebaseRecyclerOptions<ModelClass> options;
FirebaseRecyclerAdapter<ModelClass, MyViewHolder> adapter;
DatabaseReference dRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
dRef = FirebaseDatabase.getInstance().getReference().child("Users");
recyclerView = findViewById(R.id.dashboardRCV);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
LoadData();
}
private void LoadData() {
options = new FirebaseRecyclerOptions.Builder<ModelClass>()
.setQuery(dRef, ModelClass.class)
.build();
adapter = new FirebaseRecyclerAdapter<ModelClass, MyViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNull ModelClass model) {
holder.geglink.setText(model.getGig());
holder.userName.setText(model.getName());
holder.userAbout.setText(model.getAbout());
holder.v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = model.getGig();
if (!url.startsWith("http://") && !url.startsWith("https://")){
url = "https://" + url;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
}
}
});
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_layout, parent, false);
return new MyViewHolder(view);
}
};
adapter.startListening();
recyclerView.setAdapter(adapter);
}
}
ModelClass
public class ModelClass {
String gig, name, about;
public String getGig() {
return gig;
}
public void setGig(String gig) {
this.gig = gig;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAbout() {
return about;
}
public void setAbout(String about) {
this.about = about;
}
public ModelClass(String gig, String name, String about) {
this.gig = gig;
this.name = name;
this.about = about;
}
public ModelClass() {
}
}
Thanks in advance
android
android-recyclerview
android-webview
0 Answers
Your Answer