i am building an android lib with AdMob to use on kony platform. The lib works great for a android phone or for tablets which are in portrait mode by default, but the Ad doesn't display on the galaxy Tab 10.1 (which is a in landscape by default).
i get this error :
Not enough space to show ad. Needs 1280x90 dp, but only has 800x1207 dp.
it seems that Admob get the size in landscape mode instead of the portrait size. (to be clear, portrait being 800x1207 and landscape 1280x800 when a write about it) and i am not sure where does the issue com from
my application is portrait mode only and i use this code to create my banner :
public View onCreateView(Context context) {
adView = new PublisherAdView(context);
adView.setAdUnitId(MY_AD_UNIT_ID);
adView.setAdSizes(AdSize.SMART_BANNER);
/*LayoutParams lparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
adView.setLayoutParams(lparams);*/
PublisherAdRequest.Builder publisherAdRequestBuilder = new PublisherAdRequest.Builder();
// Optionally populate the ad request builder.
publisherAdRequestBuilder.addTestDevice("XXXXXXX");
adView.loadAd(publisherAdRequestBuilder.build());
return adView;
}
onCreateView is call by the kony platform to display the Ad and I don't really know what's happen on this side. This code works fine for any android phone and tablet which are in portrait mode by default.
i can also display an Ad on the galaxy 10.1 if I change SMART_BANNER by Leaderboard but it's not centered on the Kony app and not as convenient as the smart banner.
I don't know android a lot and might have forgot to check something basic.
is there anything i could try to get the correct size before to investigate if it comes from Kony?
Thanks
Please check your layout for any padding. It just works if you remove any default padding.
Cheers!
Related
I am trying to change photos in android studio by clicking on my button.
When I put code for changing the photo in my MainActivity.java I keep getting this type of error messages and it says :
Cannot resolve symbol "image"
image.setImageResource(R.drawable.xxx);
I am watching Udemy course for android development and I have done everything same like the professor on that video.
I have tried to restart android studio.
I have tried to make new project.
I have tried to clear invalidate caches and restart.
public void changeImage(View view)
{
ImageView bitcoin = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
}
I hope there is actual error with android studio,because code is clone of the video that I am watching.
You are binding your layout's ImageView in Java file with bitcoin variable and you are trying to set an image on an unknown variable 'image'(maybe it's not defined in the class). So you have to set as below.
ImageView bitcoin = findViewById(R.id.bitcoin);
bitcoin.setImageResource(R.drawable.xxx);
Set Your Code Like this
ImageView image = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
change your this line
image.setImageResource(R.drawable.xxx)
to this one:
bitcoin.setImageResource(R.drawable.xxx)
I have a requirement that I have to take a screenshot of the current window in android.
This is the code am using,
View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
View screenView = rootView.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
by using this I could get the application screen shot, but the status bar contents are missing (bluetooth icon, battery status etc).
How can I take a screenshot of the current Android phone window programmatically (including status bar contents)?
Is it possible?
On Android 5.0+, use the media projection APIs to take a screenshot of the device screen. See this sample app, as the process is somewhat involved.
On older Android devices, there is no support for programmatic screenshots of the device screen.
I have created Android layout resource files for landcape mode for all different screen sizes such as, small, large, medium and extra large , however, when I run the app it does not work in landscape mode as half of the buttons, images are missing from the screen.
I have also included the below line in the android Manifest file.
android:configChanges="keyboardHidden|orientation|screenSize"
Please advice how I can make andriod aware of when to use the landscape and portrait mode.
This is happening because you have added android:configChanges="keyboardHidden|orientation|screenSize"
in your manifest which means the orientation changes will not occur hence your landscape layout never gets initialised. By default the android behaviour is that when the mobile is rotated the current activity is destroyed and new one is created.
Remove that line and try
In the java file of an activity this is how you can recognize if you are in a Landscape mode or portrait mode.
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
//do something
} else {
//do something
}
okay I am giving an example.....i had a imageview in my layout. when I go to portrait mode it is set one image. and when I go to landscape mode it changes to another image.
ImageView headerimage= (ImageView) findViewById( R.id.headerimage);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
headerimage.setBackgroundResource(R.drawable.splash_icon_landscape);
} else {
headerimage.setBackgroundResource (R.drawable.splash_icon_portrait);
}
How to open an application inside another application within the latters boundaries in android? ie., similar to what iframe does in HTML.
You basically can't. It goes against the rules of Android. The most you can do is open a web page as part of an app. This is done using the webView. You can control the boundaries of the screen by setting the bounds of the webview in the xml file for the Webview.
public class WebViewFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
public WebViewFragment() {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View mainView = inflater.inflate(R.layout.fragment_facebook,
container, false);
WebView webView = (WebView) mainView.findViewById(R.id.webView1);
webView.setWebViewClient(new MyWebViewClient());
webView.getSettings().setSupportZoom(false);
webView.getSettings()
.setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.loadUrl(""); //URL needs to be entered in this line
return mainView;
}
}
Hope this helps :)
This is not possible because of security reasons. Previous versions of Android allowed this with System-grade permissions (ones that most developers will never get to use), but it was rarely used and is not in the SDK anymore as far as I know.
Some manufacturers implement additional functionalities like Samsung's Mini Apps (if I remember the name correctly) which may be opened in a floating window above other apps. You can also draw your own app over another using a service (like Facebook messenger does). But there is no way to force a third party app to do any of these things.
However, every time you open an application from your application, the process of the new one will have the invoker's process assigned as parent. This allows you, to some extend, check if this other app was opened from your app.
Also, your app will not die when opening a new one, but will simply be "below it". If you need some kind of data from the other app, you may start it forResult. This way the other app will "know" you are expecting a defined result from it, so it will process some data and pass it back to your app (which will reappear after the other one is finished preparing the result).
It could be possible if use the android property
android:launchMode="singleTask while declaring your activity in the AndroidManifest.xml (inside the activity element).
If you so so, if you minimize your app and launch it again (from background or from app icon from the list of apps), it would still show you the new app.
I am not sure if the result would be as per your desired effect.
I want to make an activity that can be opened above ANY app.
Normally, even when the activity is set as dialog, when you switch to my app, you see my app, and in the background you see the launcher:
BUT, I want the app will go above any app like this: (made in photoshop):
I did see this question Creating a system overlay window (always on top), but in ICS there is no functionallity to the layout.
Furthermore, I want to give a dialog box from my app without minimizing the other app...
there are plenty of apps that show a floating view on top of everything like : airbrowser , LilyPad , Stick it , AirTerm , Smart Taskbar , aircalc ...
anyway , in order to achieve this feature , you must have a special permission called "android.permission.SYSTEM_ALERT_WINDOW" , and use something like that:
final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
final View view=findViewById(R.id.my_floating_view);
final ViewGroup parent=(ViewGroup)view.getParent();
if(parent!=null)
parent.removeView(view);
param.format=PixelFormat.RGBA_8888;
param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity=Gravity.TOP|Gravity.LEFT;
param.width=parent!=null?LayoutParams.WRAP_CONTENT:view.getLayoutParams().width;
param.height=parent!=null?LayoutParams.WRAP_CONTENT:view.getLayoutParams().height;
final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(view,param);
// TODO handle overlapping title bar and/or action bar
// TODO you must add logic to remove the view
// TODO you must use a special permission to use this method :android.permission.SYSTEM_ALERT_WINDOW
// TODO if you wish to let the view stay when leaving the app, make sure you have a foreground service running.
I'm one of the developers of the Tooleap SDK, and we also dealt with this issue.
Basically, you don't need to use the SYSTEM_ALERT_WINDOW to display an activity on top of another one. You can just display a regular "shrinked" Activity with a transparent background.
To make a "shrinked Activity, change the activity window layout params of height and width:
WindowManager.LayoutParams params = getWindow().getAttributes();
params.x = ...;
params.y = ...;
params.width = ...;
params.height = ...;
this.getWindow().setAttributes(params);
To make a transparent background add to your activity definition in the manifest file:
android:theme="#android:style/Theme.Translucent"
That way, you can create the illusion of a floating activity:
Note that only the foreground activity will be resumed, while the background one is paused. But for most apps this shouldn't be an issue.
Now all that remains is when to launch the floating activity.
Here is an example of a "floating" calculator app using a regular activity. Note that the activity below the calculator belongs to another app.