السلام عليكم
انا في خطواتي الاولي في الاندرويد واتمنى ان اجد مساعدتكم.
لدي برنامج بسيط لعرض قناه اليوتيوب في ويب فيو
البرنامج به 2 اكتيفيتي
الاول مجرد زر يذهب على الثاني
الثاني به ويب فيو يحمل لينك اليوتيوب وبه اعلان امازون
المشكله ان اعلان امازون لا يظهر في الاكتيفتي اطلاقا.. واذا ضغط على زر back يظهر اكتيفيتي فارغ وبه الاعلان.
هل هناك حل للمشكله بحيث يظهر الاعلان؟
واذا لم يكن ممكن كيف احذف الاعلان بحيث لا يظهر هذه الاكتيفتي الفارغ. اريد اذا ضغط زر باك يعود للاكتيفيتي الاول مباشره.
ارفق هنا كود الاكتيفيتي الثاني.
ولكم جزيل الشكر
package com.sameh.sameh;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.amazon.device.ads.AdError;
import com.amazon.device.ads.AdLayout;
import com.amazon.device.ads.AdListener;
import com.amazon.device.ads.AdProperties;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.AdTargetingOptions;
import com.com.ganahtech.freeaudiobooks.R;
public class MainActivity extends Activity implements AdListener {
WebView webbrowse;
ProgressDialog dialog;
private AdLayout adView; // The ad view used to load and display the ad.
private static final String APP_KEY = "88a762f1f04c401e91e2b1eeefa7f853"; // Sample Application Key. Replace this variable with your Application Key
private static final String LOG_TAG = "MainActivity";
public void initialzing() {
webbrowse = (WebView) findViewById(R.id.webbrowser);
webbrowse.getSettings().setUseWideViewPort(true);
webbrowse.getSettings().setLoadWithOverviewMode(true);
webbrowse.getSettings().setJavaScriptEnabled(true);
webbrowse.getSettings().setBuiltInZoomControls(true);
webbrowse.getSettings().setPluginsEnabled(true);
webbrowse.loadUrl("http://www.youtube.com/user/LoveAllah328/videos");
webbrowse.setWebViewClient(new WebViewClient(){@ Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("youtube")){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
else
{
return false;
}
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
// For debugging purposes enable logging, but disable for production builds
AdRegistration.enableLogging(false);
// For debugging purposes flag all ad requests as tests, but set to false for production builds
AdRegistration.enableTesting(false);
adView = (AdLayout)findViewById(R.id.ad_view);
adView.setListener(this);
try {
AdRegistration.setAppKey(APP_KEY);
} catch (Exception e) {
Log.e(LOG_TAG, "Exception thrown: " + e.toString());
return;
}
// Calling load ad in the Activity's onCreate method allows a new ad to be loaded
// when the application starts and also when the device is rotated.
LoadAd();
initialzing();
}
@Override
public void onBackPressed() {
if (webbrowse.canGoBack())
webbrowse.goBack();
else {
finish();
}
}
/**
* Load a new ad.
*/
public void LoadAd() {
// Load the ad with the appropriate ad targeting options.
AdTargetingOptions adOptions = new AdTargetingOptions();
adView.loadAd(adOptions);
}
/**
* This event is called after a rich media ads has collapsed from an expanded state.
*/
@Override
public void onAdCollapsed(AdLayout view) {
Log.d(LOG_TAG, "Ad collapsed.");
}
/**
* This event is called if an ad fails to load.
*/
@Override
public void onAdFailedToLoad(AdLayout view, AdError error) {
Log.w(LOG_TAG, "Ad failed to load. Code: " + error.getCode() + ", Message: " + error.getMessage());
}
/**
* This event is called once an ad loads successfully.
*/
@Override
public void onAdLoaded(AdLayout view, AdProperties adProperties) {
Log.d(LOG_TAG, adProperties.getAdType().toString() + " Ad loaded successfully.");
}
/**
* This event is called after a rich media ad expands.
*/
@Override
public void onAdExpanded(AdLayout view) {
Log.d(LOG_TAG, "Ad expanded.");
}
}
