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.
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.
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.
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.
Related
I'm using Titanium, my app supports tablets and phones. For phones I need to use PORTRAIT orientation anche for tablets LANDSCAPE.
I tried to configure android:screenOrientation="nosensor" in tiapp.xml importing all activities from AndroidManifest.xml and orientationModes : [Ti.UI.LANDSCAPE_LEFT] in window configuration in tablet case, but I have no results. All orientations are active.
Anyone can help me?
This should be pretty forward with following points:
Since you need to change orientations at runtime, you cannot control it from tiapp.xml unless you create separate builds for phones and tablets which I believe is not the case.
Leave tiapp.xml as default and do not set any orientation there.
Use below snippet for handling it inside app.tss file.
"Window[if=Alloy.isTablet]" : {
orientationModes : [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]
}
"Window[if=Alloy.isHandheld]" : {
orientationModes: [Ti.UI.UPSIDE_PORTRAIT, Ti.UI.PORTRAIT]
}
This solution will work only if you create Window controllers using XML, not by using Classic JS.
Double check your code to not to set orientations anywhere else to avoid any issues.
Background
Android 7.1 now has a new feature called "AppShortcut" . On the docs, they explain how to create static ones and dynamic ones, and they even have a sample app.
The problem
I tried out the sample, yet I've noticed that when I click on the static app-shortcut, it shows me a toast "app isn't installed".
Looking at the code, I've found a suspicious configuration (in "shortcuts.xml" file) :
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
<shortcut
android:shortcutId="add_website"
android:icon="#drawable/add"
android:shortcutShortLabel="#string/add_new_website_short"
android:shortcutLongLabel="#string/add_new_website"
>
<intent
android:action="com.example.android.appshortcuts.ADD_WEBSITE"
android:targetPackage="com.example.android.appshortcuts"
android:targetClass="com.example.android.appshortcuts.Main"
/>
</shortcut>
</shortcuts>
It doesn't look good, because nothing in the app has this intent action of "ADD_WEBSITE" .
The dynamic shortcuts work fine btw (can be added via the normal launch of MainActivity).
What I tried
So I thought this should be changed. I tried to create a new activity and change this configuration to match the activity (action and targetCalss), but for some reason I still got the same toast .
The question
What could be wrong in the code? What should be changed to fix it?
It's strange, but you can fix this by changing
android:targetPackage = "com.example.android.shortcutsample"
(same as applicationid) or
applicationId "com.example.android.appshortcuts" (same as package name).
Because your "com.example.android.appshortcuts.Main" don't has this action
com.example.android.appshortcuts.ADD_WEBSITE
You can change this action to
android.intent.action.VIEW
I'm adapting an existing phone application for tablets. The problem is that there are some small differences in the UI between the phone and the tablet.
For example, on the phone, there is a landing page and then a login page with a cancel button that goes back too the landing page.
On the tablet, the login fragment is on the landing page and the cancel button is removed. This means that I've made a check to see if the device is a tablet and if it is, I dunno find the view of the cancel button.
This seems hacky to me and i was wondering if there was a better way to do this. Thanks.
Tablet or phone ?
First of all you should know on which device you are. An elegant way (in my opinion) is to declare a resource in config.xml :
values/config.xml
<bool name="isTablet">false</bool>
values-sw600dp/config.xml
<bool name="isTablet">true</bool>
Then extends Application and keep the type of device running the app :
public static boolean IS_TABLET = false;
public void onCreate() {
super.onCreate();
MyApp.IS_TABLET = getResources().getBoolean(R.bool.isTablet);
}
Handling differents view
To handle differents view use the differents folders in /res
/layout for phone view
/layout-sw600dp for 7" tablet (you can just use this folder if there is no difference between 7 et 10")
/layout-sw720dp for 10" tablet
Handling code
Two solutions here :
1- The change between views are minor : keep the same activity/fragment and add some condition like
if(MyAPP.IS_TABLET) {
// DO something on tablet
} else {
// Do something on phone
}
2- If tablet and phone are very different create a new activity/fragment with a suffixe like :
HomeActvity => HomeActivityTablet
And add a condition on the loading of this particular view.
You can also works with differents namespace , depending on what give you best architecture.
Exemple
Have a look on the Google IO app's source code
I have a simple Android app (built with Mono for Android), which has a problem with it's icon.
The icon is correct in Launcher and in Task Switcher, but
In Manage Apps and in Task Manager it's displayed a generic Android icon
I've checked the various density resources and the manifest and they all look correct.
(I'm seeing this on a Galaxy S phone and on a Nexus 7)
Most likely you set the icon property for your activities within AndroidManifest.xml, but did not set it for the application.
It occurs to me, that the app icon is somehow being cached in the app manager, so that deinstalling and reinstalling the app does not always change the icon properly. Rebooting the device could help.
Also i found this post very useful: adding application ids in gradle usually solves the problem.
Open "AndroidMenifest.xml" in the Package Explorer and click on the "Application" tab at the bottom. Look at the "icon" field and enter the location for your icon ( Ex: #drawable/iconimage). Next, go into the "AndroidManifest.xml" tab and look for android:icon=, adding the location to that as well (Ex: android:icon="#drawable/iconimage)
Make sure you have the same icon name in both locations!
Oleg and Collin are both right but for completeness - in a Mono app the icon can be set with attributes on the Application object (if you have one):
[Application(Label = "MyAppName", Icon = "#drawable/icon")]
class MyApp: Application
{ ...
i wrote a custom syncadapter, which also added a custom field to the rawcontacts. Exactly how it is done in the SampleSyncAdapter or in this example with the last.fm-App. And it is working fine on the emulator.
The xml-file, which declares my custom field:
<ContactsSource xmlns:android="http://schemas.android.com/apk/res/android">
<ContactsDataKind
android:mimeType="vnd.com.google.cursor.item/vnd.alien.mimetype"
android:icon="#drawable/icon"
android:summaryColumn="data2"
android:detailColumn="data3"
android:detailSocialSummary="true" />
</ContactsSource>
The code to add the custom field to the data-table of the contactscontract-provider:
mContentUri = Data.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
Builder mID = ContentProviderOperation.newInsert(mContentUri)
.withValue(Data.RAW_CONTACT_ID, getRawContactId())
.withValue(Data.MIMETYPE, "vnd.com.google.cursor.item/vnd.alien.mimetype")
.withValue(Data.DATA1, mContactInformations.get("mID"))
.withValue(Data.DATA2, mContext.getString(R.string.profile_text))
.withValue(Data.DATA3, mContext.getString(R.string.profile_id)+" "+mContactInformations.get("mID"));
But when I run them on my HTC Desire with HTC Sense installed, I can't see this custom field anymore?!? Has anyone experienced the same problem?
Any hint to get my custom field visible is highly appreciated!
Cheers Ali3n
The default contact viewers do not show custom fields.
There are some 3rd party apps that do show custom fields, a free one (but ad supported) is here
Unfortunately I did not found a real solution for that. But two things reduce the problem:
This problem did only appear on my old HTC Desire. On my sisters HTC Sensation the custom-field shows up as expected (nice fail from HTC in the first try oO)
Even better is, that the intent that would be started via this custom-field also shows up in the QuickContactBadge, which is used by the native HTC Contacts-App even on my HTC Desires Sense. Therefore the user can invoke my activity via the QuickContactBadge on old Senses versions and in new versions he also has the ability to use the custom-field.