How to change the location of the emergence of AdMob interstitial to start the application Admob interstitial appears when you click on the camera icon This is contrary to the policies of Admob I want to make it appear within the application a way that is contrary to the policies of Admob
This is my GameOverscreen code.
package com.package.name;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import picture.profile.logo.football.R;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
public class LauncherActivity extends Activity{
private static final int CAMERA_PIC_REQUEST = 2;
private static final int SELECT_PICTURE = 1;
public static final int MEDIA_TYPE_IMAGE = 1;
public static int imageFrom = 0;
protected static Uri outputFileUri = null;
public static String selectedImagePath;
private Uri fileUri;
// directory name to store captured images and videos
private static final String IMAGE_DIRECTORY_NAME = "Hello Camera";
ImageView btnstart,img_more,img_rate,img_camera;
private AdView mAdView;
private InterstitialAd mInterstitial;
TextView txtname;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
btnstart=(ImageView)findViewById(R.id.start);
img_camera=(ImageView)findViewById(R.id.img_camera);
img_more=(ImageView)findViewById(R.id.img_more);
img_rate=(ImageView)findViewById(R.id.img_rate);
txtname=(TextView)findViewById(R.id.txt_appname);
Typeface font = Typeface.createFromAsset(getAssets(), "molten.ttf");
txtname.setTypeface(font);
mAdView = (AdView) findViewById(R.id.adViewad);
mAdView.loadAd(new AdRequest.Builder().build());
mInterstitial = new InterstitialAd(LauncherActivity.this);
mInterstitial.setAdUnitId(getResources().getString(R.string.admob_intertestial_id));
mInterstitial.loadAd(new AdRequest.Builder().build());
mInterstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
if (mInterstitial.isLoaded()) {
mInterstitial.show();
}
}
});
btnstart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.putExtra("imagePath", selectedImagePath);
startActivityForResult(i, SELECT_PICTURE);
}
});
img_camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_PIC_REQUEST);
}
});
img_rate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final String appName = getPackageName();//your application package name i.e play store application url
try {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id="
+ appName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id="
+ appName)));
}
}
});
img_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse(getString(R.string.play_more_apps))));
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_PICTURE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
int k=0;
if (selectedImage != null)
{
try
{
k = getFileSize(selectedImage);
}
catch (Exception exception)
{
Toast.makeText(LauncherActivity.this, "unsupported media file", Toast.LENGTH_SHORT).show();
return;
}
}
if (selectedImage != null && k != 0)
{
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
selectedImagePath = cursor.getString(columnIndex);
cursor.close();
Log.e("path", selectedImagePath);
startActivity(new Intent(this,ShapeSecondActivity.class).putExtra("imagePath", selectedImagePath));
}
else
{
Toast.makeText(LauncherActivity.this, "unsupported media file",Toast.LENGTH_SHORT).show();
}
}
if (requestCode == CAMERA_PIC_REQUEST) {
if (resultCode == RESULT_OK) {
// successfully captured the image
// display it in image view
selectedImagePath=fileUri.getPath();
startActivity(new Intent(this,ShapeSecondActivity.class).putExtra("imagePath", selectedImagePath));
} else if (resultCode == RESULT_CANCELED) {
// user cancelled Image capture
Toast.makeText(getApplicationContext(),
"User cancelled image capture", Toast.LENGTH_SHORT)
.show();
} else {
// failed to capture image
Toast.makeText(getApplicationContext(),
"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public Uri getOutputMediaFileUri(int type) {
return Uri.fromFile(getOutputMediaFile(type));
}
/*
* returning image / video
*/
private static File getOutputMediaFile(int type) {
// External sdcard location
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
IMAGE_DIRECTORY_NAME);
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
+ IMAGE_DIRECTORY_NAME + " directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
} else {
return null;
}
return mediaFile;
}
private int getFileSize(Uri uri)
{
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
int i = cursor.getColumnIndex("_size");
cursor.close();
return i;
}
}
Thank You
Your interstitial ad is showing right after the app launches and it's against AdMob policy.
If I understand correctly, you want to show the interstitial when the user clicks the camera icon. Then, remove this from your onCreate()
:
mInterstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
if (mInterstitial.isLoaded()) {
mInterstitial.show();
}
}
});
And change your img_camera
click listener to this:
img_camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_PIC_REQUEST);
if (mInterstitial.isLoaded()) {
mInterstitial.show();
}
}
});