简体   繁体   English

Android-仅侦听用于启动我的应用程序的特定URL意图,仅适用于手机,不适用于平板电脑

[英]Android - Listen to a specific URL intent used to launch my app only for phones, not for tablets

How do we use Android intent filters only for smartPhones and not for tablets? 我们如何仅将Android意向过滤器用于智能电话而不用于平板电脑? I have a single apk for both smartphones and tablets. 我有一个针对智能手机和平板电脑的apk。 Would it be possible to have something specific only for the phones? 是否可以只为手机配备某些特定物品?

Expected behaviour - My app is already installed on a android device. 预期的行为-我的应用已安装在Android设备上。 URL intent fired from browser or another app running on the same device, which even my app is listening for (intent filters URL scehemes). 从浏览器或在同一设备上运行的另一个应用程序触发的URL意向,甚至我的应用程序也在侦听(意向过滤器URL场景)。 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. 对于其他情况(在7英寸和10英寸平板电脑中),其行为应类似于设备中不存在该应用程序。

in your android manifest file - 在您的Android清单文件中-

<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 (eg tablets) 允许它是可选的,因此您仍然可以将其下载到wifi设备(例如平板电脑)上

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM