Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 82

android genie
Aspiring developer
Profile
Posts: 3
Reg: Mar 12, 2013
Mobile
30
03/12/13 02:16 PM (12 years ago)

Admob for relativeLayout not working

Where do I place Admob in this Android relativeLayout / manifest / onCreate source code ........................RelativeLayout................................... <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/buttonFlashlight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:text="Torch-ON" /> </RelativeLayout> ....................Manifest............................................. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.prggur.com" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name="com.prgguru.com.SimpleNotificationAppActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> ....................................onCreate............................. .
 
Sandeep
Android Fan
Profile
Posts: 1260
Reg: Feb 01, 2012
Miraj, India
25,250
like
03/12/13 08:16 PM (12 years ago)
Which plugin layout file is this? I think its the flashlight plugin layout file that you want to put ads in to it. Well then try the following code in this layout file and see if it works. I have had not time to test it myself but it should work. <?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/containerView" android:background="@android:color/transparent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/subContainer" android:layout_height="fill_parent" android:layout_width="fill_parent" android:gravity="center_horizontal" android:orientation="vertical"> <Button android:id="@+id/buttonFlashlight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:text="Torch-ON" /> </LinearLayout> <com.google.ads.AdView xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" ads:adSize="SMART_BANNER" ads:adUnitId="YOUR_ADMOB_PUBLISHER_ID" ads:loadAdOnCreate="true" > </com.google.ads.AdView> </RelativeLayout> And later you put the following code in the manifest file before the closing of the </application> tag- <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
 
android genie
Aspiring developer
Profile
Posts: 3
Reg: Mar 12, 2013
Mobile
30
like
03/14/13 01:34 PM (12 years ago)
"thanks a lot" I fixed a few errors taking side note advice from eclipse but now whenever i run the app it crashes.. In the Main.xml file I get a yellow line error under this line "android:text="Torch-ON" />" stating "[I18N] Hardcoded string "Torch-ON", should use @string resource." Also in manifest on line "<application" I get the error message "Should explicitly set android:allowBackup to true or false (it's true by default, and that can have some security implications for the application's data)" I have tried everything that I know of and still cant figure out how to correct these problems. I will provide the "onCreate" below also .............HERE IS THE MAIN.XML......................................... <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adSize="BANNER" ads:adUnitId="myidnumber" ads:loadAdOnCreate="true" > </com.google.ads.AdView> <Button android:id="@+id/buttonFlashlight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:text="Torch-ON" /> </RelativeLayout> ..................HERE IS THE MANIFEST................................... <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.prggur.com" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:maxSdkVersion="10" android:targetSdkVersion="17"/> <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name="com.prgguru.com.SimpleNotificationAppActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />” </application> </manifest> ...........................onCreate....................................... package com.prgguru.com; import android.app.Activity; import android.content.Context; import android.content.pm.PackageManager; import android.hardware.Camera; import android.hardware.Camera.Parameters; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; import com.prggur.com.R; public class SimpleNotificationAppActivity extends Activity { private boolean isFlashOn = false; private Camera camera; private Button button; @Override protected void onStop() { super.onStop(); if (camera != null) { camera.release(); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button) findViewById(R.id.buttonFlashlight); Context context = this; PackageManager pm = context.getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { Log.e("err", "Device has no camera!"); Toast.makeText(getApplicationContext(), "Your device doesn't have camera!", Toast.LENGTH_SHORT).show(); return; } camera = Camera.open(); final Parameters p = camera.getParameters(); button.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { if (isFlashOn) { Log.i("info", "torch is turned off!"); p.setFlashMode(Parameters.FLASH_MODE_OFF); camera.setParameters(p); isFlashOn = false; button.setText("Torch-ON"); } else { Log.i("info", "torch is turned on!"); p.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(p); isFlashOn = true; button.setText("Torch-OFF"); } } }); } }
 
android genie
Aspiring developer
Profile
Posts: 3
Reg: Mar 12, 2013
Mobile
30
like
03/14/13 04:36 PM (12 years ago)
"thanks a lot" I fixed a few errors taking side note advice from eclipse but now whenever i run the app it crashes.. In the Main.xml file I get a yellow line error under this line "android:text="Torch-ON" />" stating "[I18N] Hardcoded string "Torch-ON", should use @string resource." Also in manifest on line "<application" I get the error message "Should explicitly set android:allowBackup to true or false (it's true by default, and that can have some security implications for the application's data)" I have tried everything that I know of and still cant figure out how to correct these problems. I will provide the "onCreate" below also
 
Sandeep
Android Fan
Profile
Posts: 1260
Reg: Feb 01, 2012
Miraj, India
25,250
like
03/14/13 06:06 PM (12 years ago)
Well you can ignore the yellow error marks. They are not fatal anyway. But in case you want to remove the error and by far the correct method to create a layout file is to use strings for the text options. So, open strings.xml and add another new string in it like below- <string name="torch_on">Torch On</string> and in your layout file in place of android:text="Torch-ON" put this- @string/torch_on You can find the strings file in res--->values folder in your project file. Now the error in the manifest file put the following code in the application tag at start - android:allowBackup="true" now your main activity will look like this in the manifest file- <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:allowBackup="true" > <activity android:name="com.prgguru.com.SimpleNotificationAppActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" />
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.