setTesting(boolean) from the type AdRequest is deprecated
Admob testing on emulator issue.
Android Eclipse code warning:
setTesting(boolean) from the type AdRequest is deprecated
Solution:
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
Android Eclipse code warning:
setTesting(boolean) from the type AdRequest is deprecated
Solution:
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
AdView adView = new AdView(this, AdSize.BANNER, "a14d9..........");//MY_AD_UNIT_ID
AdRequest adRequest = new AdRequest();
adRequest.setTesting(true); // deprecated
adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // OK
adView.loadAd(adRequest);
396LW NO topic_id
AD
Další témata ....(Topics)
public class ApokusActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
canvas.drawColor(Color.YELLOW);
paint.setFilterBitmap(true);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.flower_blue);
int targetWidth = bitmapOrg.getWidth() * 2;
int targetHeight = bitmapOrg.getHeight() * 2;
Bitmap bmp = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888);
RectF rectf = new RectF(0, 0, targetWidth, targetHeight);
Canvas c = new Canvas(bmp);
Path path = new Path();
path.addRect(rectf, Path.Direction.CW);
c.clipPath(path);
c.drawBitmap( bitmapOrg, new Rect(0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight()),
new Rect(0, 0, targetWidth, targetHeight), paint);
Matrix matrix = new Matrix();
matrix.postScale(1f, 1f);
Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, targetWidth, targetHeight, matrix, true);
int h = bitmapOrg.getHeight();
canvas.drawBitmap(bitmapOrg, 10,10, paint);
canvas.drawBitmap(resizedBitmap, 10,10 + h + 10, paint);
}
}
}
Example from SDK C:\Program Files\Android\android-sdk-windows\samples\android-10\ApiDemos\src\com\example\android\apis\text\Link.java
Source: //developer.android.com/resources/browser.html?tag=sample
License: //www.apache.org/licenses/LICENSE-2.0
1.) Automatically linkifies using android:autoLink="all"
2.) Link text by setMovementMethod
3.) Link as html code using Html.fromHtml()
4.) Link string by SpannableString
Source: //developer.android.com/resources/browser.html?tag=sample
License: //www.apache.org/licenses/LICENSE-2.0
1.) Automatically linkifies using android:autoLink="all"
// res/values/strings.xml
<string name="link_text_auto"><b>text1:</b> This is some text. In
this text are some things that are actionable. For instance,
you can click on //www.google.com and it will launch the
web browser. You can click on google.com too. And, if you
click on (415) 555-1212 it should dial the phone.
</string>
// main.xml
<!-- text1 automatically linkifies things like URLs and phone numbers. -->
<TextView xmlns:android="//schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
android:text="@string/link_text_auto"
/>
2.) Link text by setMovementMethod
// MainActivity.java onCreate
/*Be warned that if you want a TextView with a key listener or movement method not to be focusable, or if you want a TextView without a key listener or movement method to be focusable, you must call setFocusable(boolean) again after calling this to get the focusability back the way you want it. */
TextView t2 = (TextView) findViewById(R.id.text2);
t2.setMovementMethod(LinkMovementMethod.getInstance());
// main.xml
<!-- text2 uses a string resource containing explicit <a> tags to
specify links. -->
<TextView xmlns:android="//schemas.android.com/apk/res/android"
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/link_text_manual"
/>
//strings.xml
<string name="link_text_manual"><b>text2:</b> This is some other
text, with a <a href="//www.google.com">link</a> specified
via an <a> tag. Use a "tel:" URL
to <a href="tel:4155551212">dial a phone number</a>.
</string>
3.) Link as html code using Html.fromHtml()
// MainActivity.java onCreate
TextView t3 = (TextView) findViewById(R.id.text3);
t3.setText(
Html.fromHtml(
"<b>text3:</b> Text with a " +
"<a href="//www.google.com">link</a> " +
"created in the Java source code using HTML."));
t3.setMovementMethod(LinkMovementMethod.getInstance());
4.) Link string by SpannableString
SpannableString ss = new SpannableString(
"text4: Click here to dial the phone.");
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView t4 = (TextView) findViewById(R.id.text4);
t4.setText(ss);
t4.setMovementMethod(LinkMovementMethod.getInstance());
Problemi is in e.getMessage() what can return null and Log.e (String tag, String msg) will throws an new exception !!!!
Problem and solution:
LogCat:
Or you can using this code:
Problem and solution:
try {
int [] i = {1};
int z = i[5];
} catch (ArrayIndexOutOfBoundsException e) {
String s = e.toString(); // s == java.lang.ArrayIndexOutOfBoundsException
// try to testing String s for null value
if(s != null)
Log.e("bla", s);
else
Log.e("bla", "My error text 1");
String s2 = e.getMessage(); // s2 == null !!!!!!!
// you need to testing String s2 for null value , or you get FATAL EXCEPTION: main
// and application will be crashed
String s2 = e.getMessage(); // s2 == null !!!!!!!
if(s2 != null)
Log.e("bla2", e.getMessage());
else
Log.e("bla2", "My error text 2");
// this is OK
e.printStackTrace();
}
LogCat:
E/bla(855): java.lang.ArrayIndexOutOfBoundsException
E/bla2(855): My error text 2
W/System.err(855): java.lang.ArrayIndexOutOfBoundsException
W/System.err(855): at cz.okhelp.motion._MotionActivity.onTouchEvent(_MotionActivity.java:54)
W/System.err(855): at android.app.Activity.dispatchTouchEvent(Activity.java:2099)
W/System.err(855): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
W/System.err(855): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
W/System.err(855): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
W/System.err(855): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(855): at android.os.Looper.loop(Looper.java:123)
W/System.err(855): at android.app.ActivityThread.main(ActivityThread.java:3683)
W/System.err(855): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(855): at java.lang.reflect.Method.invoke(Method.java:507)
W/System.err(855): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
W/System.err(855): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
W/System.err(855): at dalvik.system.NativeStart.main(Native Method)
Or you can using this code:
try {
int [] i = {1};
int z = i[5];
} catch (Exception e) {
StringBuilder sb = new StringBuilder().append(e.getClass().getSimpleName());
if (e.getMessage() != null) {
sb.append("
");
sb.append(e.getMessage());
}
Log.e("err", sb.toString()); // E/err(336): ArrayIndexOutOfBoundsException
// this code write out all message
Log.e("myError", "methodName", e);
}
// E/myError(371): methodName
// E/myError(371): java.lang.ArrayIndexOutOfBoundsException
// E/myError(371): at cz.okhelp.motion._MotionActivity.onTouchEvent(_MotionActivity.java:54)
// E/myError(371): at android.app.Activity.dispatchTouchEvent(Activity.java:2099)
// E/myError(371): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
// E/myError(371): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
// E/myError(371): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
// E/myError(371): at android.os.Handler.dispatchMessage(Handler.java:99)
// E/myError(371): at android.os.Looper.loop(Looper.java:123)
// E/myError(371): at android.app.ActivityThread.main(ActivityThread.java:3683)
// E/myError(371): at java.lang.reflect.Method.invokeNative(Native Method)
// E/myError(371): at java.lang.reflect.Method.invoke(Method.java:507)
// E/myError(371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
// E/myError(371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
// E/myError(371): at dalvik.system.NativeStart.main(Native Method)
Google Android button example source code for developers.
// get handle
Button myButton;
myButton = (Button)findViewById(R.id.idMyButton);
//set focus
myButton.requestFocus();
// set background image
myButton.setBackgroundResource(R.drawable.backImage);
// or
myButton.setBackgroundDrawable(getResources().getDrawable( R.drawable.someImage));
// set visibility
myButton.setVisibility(View.INVISIBLE); // VISIBLE
///////// SET LISTENER
Button myButton =(Button)findViewById(R.id.button1);
myButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "AHOJ",
Toast.LENGTH_LONG).show();
}
});
// or set onClickListener
myButton.setOnClickListener(myListener);
//end onCreate .....
private OnClickListener myListener = new OnClickListener() {
public void onClick(View v) {
}
}
Convert number int to string Android Java example source code.
int n = 0;
try {
n = Integer.parseInt("21"));
} catch(NumberFormatException e) {
System.out.println("Could not parse " + e);
}
// int to string
String s = String.valueOf(24);
Editace: 2013-05-25 11:40:11
Počet článků v kategorii: 396
Url:settestingboolean-from-the-type-adrequest-is-deprecated