Reputation: 1
I have tried removing the if condition but didn't work, also it's inside the fragment so no context issue.
button = view.findViewById(R.id.button);
url = view.findViewById(R.id.Url);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s= url.getText().toString();
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(s));
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(intent);
}
else{
url.setText("Error");
}
}
});
Upvotes: 0
Views: 150
Reputation: 23154
It's not getActivity().getPackageManager()
that is null
.
It's intent.resolveActivity
that returns null
And this simply means that there doesn't exist an activity that can handle the Uri
that you provided. Be sure to write your uri correct
Upvotes: 1