Mrs. Mittlieder
- Ask a question
- 2 Replies
My phone is saying and that I have a virus in my cell phone and I need advice, directions how to fix it.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.


public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
if (savedInstanceState == null) {
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().replace(R.id.main_fragment, MainFragment.newInstance()).commitNow();
fm.beginTransaction().replace(R.id.ad_fragment, AdMobFragment.newInstance()).commitNow();
}
}
}
public class MainFragment extends Fragment {
private MainViewModel mViewModel;
public static MainFragment newInstance() {
return new MainFragment();
}
/* @Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.main_fragment, container, false);
}
*/
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mViewModel = new ViewModelProvider(this).get(MainViewModel.class);
// TODO: Use the ViewModel
}
}
public class AdMobFragment extends Fragment {
private FragmentAdMobBinding binding;
public static AdMobFragment newInstance() {
return new AdMobFragment();
}
//Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("534153A818F863B61501C7071FB0D8BA"))
private void setContainerHeight(FragmentActivity view, int id, int dp) {
ConstraintLayout layout = view.findViewById(id);
ViewGroup.LayoutParams layoutParams = layout.getLayoutParams();
layoutParams.height = dp;
layout.setLayoutParams(layoutParams);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
binding = FragmentAdMobBinding.inflate(inflater, container, false);
FragmentActivity activity = getActivity();
MobileAds.initialize(activity, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(@NonNull InitializationStatus initializationStatus) {}
});
//AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
AdView adView = activity.findViewById(R.id.ad_view);
AdSize adSize;
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
adSize = AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(activity, (int) (displayMetrics.widthPixels/displayMetrics.density));
setContainerHeight(activity, R.id.ad_fragment, adSize.getHeight());
// setContainerHeight(activity, R.id.main_fragment, -adSize.getHeight());
adView.setAdSize(adSize);
//adView.loadAd(adRequest);
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
AdView adView = binding.adView;
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#FF00FF00"
tools:context=".ui.main.MainFragment">
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Main Fragment"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#FFFF0000"
android:id="@+id/ad_fragment"
tools:context=".ui.main.AdMobFragment">
<!-- view for AdMob Banner Ad -->
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ad_fragment"
tools:context=".ui.main.AdMobFragment">
<!--Change to ButtonImage with default ad-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="why?"
app:layout_constraintBottom_toTopOf="@id/ad_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- view for AdMob Banner Ad -->
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>