0

How do we use Android intent filters only for smartPhones and not for tablets? I have a single apk for both smartphones and tablets. Would it be possible to have something specific only for the phones?

Expected behaviour - My app is already installed on a android device. URL intent fired from browser or another app running on the same device, which even my app is listening for (intent filters URL scehemes). Now, my app should open only if the device is a smartphone. For other scenarios(in 7 inch and 10 inch tablets), the behaviour should be as if the application didn't exist in the device.

B.B.
  • 924
  • 2
  • 11
  • 28
  • you can check dimensions of deivce using display matrics class and then you can put your intent accordingly. – Rohit Goswami Feb 02 '16 at 10:04
  • My application is listening to the intent. I want my application to listen to the intent only when it is installed on a smartphone. – B.B. Feb 02 '16 at 12:13
  • you have to listen to the intent due to the intent filter. You can not avoid that at all. What you can possibly do that: avoid the url handling when it is a tablet and forward it to someone else. – Amit K. Saha Feb 03 '16 at 19:13
  • 1
    Docymentation says - An intent filter is an instance of the IntentFilter class. However, since the Android system must know about the capabilities of a component before it can launch that component, intent filters are generally not set up in Java code, but in the application's manifest file (AndroidManifest.xml) as elements. (The one exception would be filters for broadcast receivers that are registered dynamically by calling Context.registerReceiver(); they are directly created as IntentFilter objects.) – Amit K. Saha Feb 03 '16 at 19:16
  • We know the limitation of IntentFilters. I am looking for a work around. Multi APK support would be one of the last options. – B.B. Feb 04 '16 at 09:36

1 Answers1

1

in your android manifest file -

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-feature android:name="android.hardware.telephony" android:required="false" />

allows that to be optional so you can still download it on wifi devices (e.g. tablets)

and then in your code if the device has telephony service for further operation -

if(Context.getSystemService(Context.TELEPHONY_SERVICE)!=null){
 // it has telephony service so either a smartphone or 3g enabled tablet
}else{
// wifi tablet, no need for further operation
}

Alternatively you can do like following -

PackageManager pm = context.getPackageManager();

if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)){
   // it has telephony service so either a smartphone or 3g enabled tablet
}else{
  // wifi tablet, no need for further operation
}
Amit K. Saha
  • 5,871
  • 2
  • 27
  • 35
  • The application is allowed to be downloaded on all devices. The application should not respond to a specific URL intent, incase it is on a tablet. – B.B. Feb 02 '16 at 12:15
  • Telephony is a good way to test whether the device is a tablet or not. Thats why posted it. You can not add anything device specific condition with your intent filter in android. – Amit K. Saha Feb 02 '16 at 18:53
  • Telephony is indeed a good way to test, but it is not very reliable due to various vendors providing telephony facility to tablets also. – B.B. Feb 04 '16 at 09:33