我在 android 中开发了一个有界服务应用程序,以通过 USB 串行端口从血糖仪设备获取数据。我在另一个应用程序中开发了另一个活动,从那里我启动服务以在活动屏幕中获取数据。
当我尝试在我的设备上安装活动应用程序时出现以下错误
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager:
java.lang.SecurityException: Permission Denial: starting Intent {
act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
flg=0x10000000 cmp=com.tcs.cto.omronglucoseui/.OmronGlucoseUIActivity }
from null (pid=12170, uid=2000) requires android.hardware.usb.host
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
android.os.Parcel.readException(Parcel.java:1465)
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
android.os.Parcel.readException(Parcel.java:1419)
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
android.app.ActivityManagerProxy.startActivityAsUser(
ActivityManagerNative.ja va:2367)
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
com.android.commands.am.Am.runStart(Am.java:680)
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
com.android.commands.am.Am.onRun(Am.java:270)
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
com.android.commands.am.Am.main(Am.java:76)
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
com.android.internal.os.RuntimeInit.main(RuntimeInit.java:301)
[2015-01-16 13:16:27 - OmronGlucoseUI] ActivityManager: at
dalvik.system.NativeStart.main(Native Method)
我在我的活动和服务应用程序的清单文件中声明了以下权限。
这是我的服务应用程序的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tcs.cto.omronglucoseservice"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.tcs.cto.omronglucoseservice.OmronGlucoseActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".GlucoseService"
android:enabled="true"
android:exported="true"
android:permission="android.hardware.usb.host"
android:stopWithTask="false" >
<intent-filter>
<action android:name="com.tcs.cto.omronglucoseservice.GlucoseService" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</service>
</application>
这是我的 Activity 应用程序的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tcs.cto.omronglucoseui"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature android:name="android.hardware.usb.host" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.tcs.cto.omronglucoseui.OmronGlucoseUIActivity"
android:label="@string/app_name"
android:permission="android.hardware.usb.host">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity>
</application>
我已经添加了
android:permission="android.hardware.usb.host">
在我的两个应用程序中。
当我首先安装服务应用程序时,它正在安装但后来我尝试安装活动应用程序,它抛出错误
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.tcs.cto.omronglucoseui/.OmronGlucoseUIActivity } from null (pid=12170, uid=2000) requires android.hardware.usb.host
尝试调用时出现以下错误(在 logcat 中)
bindService(intent,serviceconnection,Context.BIND_AUTO_CREATE)
从活动
java.lang.SecurityException: Not allowed to start service Intent { act=com.tcs.cto.omronglucoseservice.GlucoseService } without permission android.hardware.usb.host
我没有从本网站的现有问题中得到任何解决方案。
对此问题的任何答案表示赞赏。