Reputation: 1486
I am developing an app that targets for tablets only not for phones.
Is this code is enough to acheive my goal? Is there any way to test it or google play sorts it's by itself and present to users?
Below is the code I have tried. But I don't know how to test it?
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<supports-screens
android:largeScreens="true"
android:normalScreens="false"
android:smallScreens="false"
android:requiresSmallestWidthDp="600"
android:xlargeScreens="true" />
Is android:anyDensity="true"
should be given along with support screen tag? Or just leave that attribute. I want to work my application on all range of tablets.
Any help in this case is highly appreciable. Thanks in advance.
Upvotes: 1
Views: 3446
Reputation: 2714
You can use a trick here...
1) Create an startup activity, which only verifies screen size in its on create an starts actual activity in success scenario. like,
// In onCreate of startup activity
if (isTablet()) {
startActivity(new Intent(StartupActivity.this, MainActivity.class));
this.finish(); // don't forget to kill startup activity after starting main activity.
} else {
setContentView(R.layout.startup);
}
This is the critical point. In else case you should set layout to this activity which ideally can have a label with you message like "Device not supported." and a button to close application.
2) Ideally, you should place all your string resources in res/values-large/strings.xml if you want to support only tablets. So here is the trick, Just add following item in your string resources...
<string name="is_supported_screen">true</string>
And now create a new string resource file at res/values/strings.xml which will contain the same string item but with false value like...
<string name="is_supported_screen">false</string>
NOTE: make sure this string resource file must contain atleast all the resources used in StarupActivity e.g. activity title, device not supported message, close app button text etc.
3) Finally write a method in your StartupActivity like,
private boolean isTablet() {
if (Boolean.parseBoolean(context.getResources().getString(R.string.is_supported_screen))) {
return true;
} else {
return false;
}
}
And its done...:)
Actually what happens here is, for devices with large screens like tablets, will load string resource from res/values-large/strings.xml and will found true
and in the case of other device, android will load resources from res/values/strings.xml and it will found false
int the method isTablet()
for value of R.string.is_supported_screen
.
And finally, Your main activity will be started if app is installed in tablet and will show message of device not supported will be displayed.
I would like to emphasize that this is a trick, so you need to follow all the steps carefully. Any mistake and you will not get desired results.
Upvotes: 0
Reputation: 6319
Seems oke, should work as far as I know.
Think about what you define as a tablet. What makes your app less suitable for a 6" phone, than for a 7" tablet?
You can't really test this until you upload it in the Google play Store. These filters in the manifest.xml are used by the Google Play Store, not actually when installing an app. They just make sure somebody doesn't find the app on his tablet and the install button won't work on the website.
You could test it by just uploading your APK but not publishing I think. It will give you a list of devices that are supported with the current settings.
Upvotes: 1
Reputation: 2113
whatever you given that is correct u have to test it on tablets it will load and for mobile phones it will not launch.
and go into the android market publisher page.
1.Make sure your app is uploaded.
2.Click on your app name.
3.Scroll down to where it says 'Show devices'.
4.Click that and you can exclude all mobile phones from downloading your app.
Failing that you can set some parameters in your manifest for screen size etc, but this is less reliable.
Upvotes: 1