Phoney questions

IanMc

Well-Known Member
Licensed User
Longtime User
I don't know if these questions have been answered elsewhere in the forums, they are such a vast database of (brilliant) information that I find it sometimes overwhealmingly hard to zero in on just that bit of info that I need. So hope you don't mind if they've been asked before.

1) Android tablets are very popular now and we all want our apps to work on as big a range of devices as possible so what happens when we start doing things like including the 'Phone' library? Or doing things with the Phone library such as the imaginably common practice of wanting just one or several activities to be forced into landscape mode while others such as settings we might want in portrait mode. What happens when you do:
B4X:
Dim p as Phone

'and then

p.SetScreenOrientation(0)
on a tablet?

2) Do tablets have bluetooth? I'd imagine they might for headphones etc.

3) Are there any obvious pitfalls that we should steer clear of when writing apps that we want to work on as wide a range of devices (including tablets) as possible?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Tablets are not really different than other devices. There is no problem with using the Phone library (except of DeviceId which will return an empty string on tablets that don't have a telephone).
2. Yes.
3. The main issue is the UI which needs to support all kinds of devices.
See the third link in my signature for more information.
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
Thanks!

(except of DeviceId which will return an empty string on tablets that don't have a telephone)

Would this be a reliable way of testing for phone functions in a device? That the DeviceId function returns an empty string?

So I could test for phone functions and if they are not present then I can use this to decide not to attempt to send/receive an SMS, dial a number etc?

B4X:
If p.DeviceId = "" Then
log("Sorry Dave, I'm afraid I can't do that")
End If

I am beginning to realise that choosing A4B is one of the best choices I have made in quite a while. The advantages of using a development environment that has specifically been coded for the android OS are becoming apparent. The fact that it has the word 'basic' in it should not put anyone off as it is a very powerful language and seems to be very well suited to android, it's all code in the end whether it's called CSharp, Java or BASIC and a lot of people struggling with trying to shoehorn java through eclipse would be wise to try B4A as the learning curve is a lot more gentle and B4A is backed up by this really cool community plus B4A just keeps getting better and better with no end to that in sight.

Cheers!
:sign0098:

P.S. I nicked your 'About' screen design ;)
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Thank you for this feedback :)

There are better ways to check whether telephony features are available.

1. You can check PhoneId.GetLine1Number and see whether the device has a phone number.
2. You can limit your app to devices with telephony services by adding this code to the manifest editor:
B4X:
AddManifestText(<uses-feature android:name="android.hardware.telephony" />

3. You can use reflection and check this feature at runtime:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Log(HasFeature("android.hardware.telephony"))
End Sub

Sub HasFeature(feature As String) As Boolean
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod("getPackageManager")
   Return r.RunMethod2("hasSystemFeature", feature, "java.lang.String")
End Sub
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
How cool!

B4X:
Log("It is " & HasFeature("android.hardware.telephony") & " that this device has a telephone")

It is true that this device has a telephone
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Just a word of caution, some devices MIGHT return they do have a phone when in reality they don't, especially some "no brand" or "clone" devices, so as Erel suggested, it is better to add that line to the manifest to limit the devices.
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
some devices MIGHT return they do have a phone when in reality they don't

The BIG FAT LIARS! :D

Also this doesn't work in Android 1.6 at least my emulator is complaining:

Error occurred

An error has occurred in sub:
main_hasfeature(java line: 307)
java.lang.
NoSuchMethodException:
hasSystemFeature
Continue?
Yes No

No biggie, I don't want to limit my app just to devices that have telephony features but I want it to be able to send/receive SMS if the device has the capability, I'm sure a little tinkering will find me the best method otherwise I'll just have to say 'if you get an error then you can't use that feature' as the above error is not lethal, when I click on yes it runs the app and everything else so far seems to work great in 1.6

I just thought, are there virtual devices for tablets that we can load into our virtual device manager?

added:
I may have found the answer to my own question in this forum:
http://stackoverflow.com/questions/...tion-for-a-7-inch-tablet-in-android-sdk-2-3-3

Notice that Joel says:
now keep in mind ... if you're targeting 2.3.3, that is in fact, a phone operating system. 3.0 (honeycomb) is the first android OS to target the tablet scenario, and 4.0 unifies their tablet and phone operating system into a single OS

It would be great to be able to load up ROMs in our emulators so that they ... well, 'emulate' a tablet better. There might be one like:
Android 3.1 - API Level 12 Tablet (no phone)
etc.
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
'if you get an error then you can't use that feature'
If you attempt to make a phone call on a device that don't have a phone you will get an error like "Mobile network not available" on a message box or open the "phone book", so it won't crash your app, but if you attempt to send an SMS then it will crash but you can prevent that by using TRY...CATCH.
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
Ah right, so I could just use Try Catch when attempting to implement an SMS function. I could do that.

Hey, I found this btw. installing Jellybean image in the virtual device:
HOW TO: Install Android 4.1 SDK and Try Jelly Bean (JB) Now on Computer [Full Guide / Tutorial] | Team Android
That article is quite old as July is lightyears away in 'Android years' :)

Ah, oops I see that if I go to create a new android virtual device I have these options already:

Android 1.6 - API Level 4
Google APIs (Google Inc.) - API Level 4
Android 2.1 - API Level 7
Android 2.2 - API Level 8
Google APIs (Google Inc.) - API Level 8
Android 2.3.3 - API Level 10
Android 3.1 - API Level 12
Android 4.0 - API Level 14
Android 4.1.2 - API Level 16

I think for me I'll try to aim at Android 2.2 API Level 8, or maybe lower if my app doesn't require anything that the lower versions haven't got.

Interesting to see the difference in the MsgBox in API 4 compared to API 8

I think it's a good idea to have a good naming convention when creating a new virtual device. Mine are labelled like this:
API_4_Android1.6
API_8_Android2.2
API_10_Android2.3.3
API_12_Android3.1
API_14_Android4.0

Then when I start one from the AVD Manager I always click on 'Scale display to real size' and put 7 in the Screen Size (in): textbox (where there is usually 3) and this makes it a good size for my monitors.

I choose the action to be able to launch from snapshot when I create one and the first time I launch it I Wipe user data, then the virtual device starts really quickly with the option to Launch from snapshot chosen.

My actual device by the way, my phone, is an HTC HD2 with a Windows Phone 6.5 ROM but then I run a version of Android right from the SD card :)
Currently running the MIUI ROM version 2.3.30 it is Android version 2.3.7 (Android 2.3.3 with extras) and runs really quick and smooth and works perfectly for development with A4B.
 
Last edited:
Upvote 0
Top