只有当手机采用USB线连接到电脑启动Android应用 [英] Android app only starts if phone connected to computer using usb cable
问题描述
我有奇怪的问题。
我公司开发的Android应用程序,并使用USB电缆部署到Android手机。
应用程序启动时仅手机用连接线连接到电脑。开机后,我可以断开电缆和应用程序仍运行正常。
所以看起来,对于应用程序来启动,它需要连接电脑。
任何想法,为什么?
下面是我的Android清单。
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.test
安卓的installLocation =自动
机器人:=的versionName0.5.14
安卓版code =33
>
<采用-SDK安卓的minSdkVersion =19机器人:targetSdkVersion =19/>
<支持屏安卓xlargeScreens =真
机器人:largeScreens =真
机器人:normalScreens =真
机器人:smallScreens =真/>
<使用特征的android:NAME =android.hardware.camera.autofocus/>
<使用特征的android:NAME =android.hardware.camera.flash机器人:所需=FALSE/>
<使用特征的android:NAME =android.hardware.camera/>
<使用特征的android:NAME =android.hardware.screen.landscape/> <应用机器人:图标=@绘制/湾
机器人:标签=@字符串/ APP_NAME>
<活动机器人:名字=。CaptureActivity
机器人:screenOrientation =风景
机器人:configChanges =方向| keyboardHidden |屏幕尺寸
机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen
机器人:windowSoftInputMode =stateAlwaysHidden
>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/>
<类机器人:名字=android.intent.category.LAUNCHER/>
<作用机器人:名字=com.google.android.glass.action.VOICE_TRIGGER/>
&所述; /意图滤光器>
&所述;元数据
机器人:名字=com.google.android.glass.VoiceTrigger
机器人:资源=@ XML / voice_trigger_start/>
< /活性GT;
<活动机器人:名字=。HelpActivity
机器人:screenOrientation =用户>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.VIEW/>
<类机器人:名字=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT; <活动机器人:名字=preferencesActivity/>
< /用途>
<使用许可权的android:NAME =android.permission.CAMERA/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE>< /使用许可权>
<使用许可权的android:NAME =android.permission.READ_PHONE_STATE>< /使用许可权>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用许可权
机器人:名字=com.google.android.glass.permission.DEVELOPMENT/>
< /清单>
为了调试我们的应用程序的最早code,我们使用添加到 android.os.Debug的电话。了waitForDebugger()
这将让我们的应用程序等待一个调试器附加。
有中,我们把那个电话该块中的活动的生命周期方法,如情况的onCreate()
。在这种情况下,如果设备没有连接,机器人无法连接到一个调试器和kepps永远等待。
因此,寻找该呼叫在您的活动的生命周期,如果发现将其删除。
I am having strange issue.
I developed android application and deployed to android phone using usb cable.
App starts up only if phone is connected to computer using cable. After starting up, I can disconnect the cable and app still runs fine.
So seems like, for the app to boot up, it requires computer connection.
Any ideas why?
Below is my android manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:installLocation="auto"
android:versionName="0.5.14"
android:versionCode="33"
>
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19"/>
<supports-screens android:xlargeScreens="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.screen.landscape"/>
<application android:icon="@drawable/bay"
android:label="@string/app_name">
<activity android:name=".CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger_start" />
</activity>
<activity android:name=".HelpActivity"
android:screenOrientation="user">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".PreferencesActivity" />
</application>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="com.google.android.glass.permission.DEVELOPMENT" />
</manifest>
In order to debug the earliest code of our apps, we use to add a call to android.os.Debug.waitForDebugger()
which will keep our app waiting for a debugger attach.
There are situations in which we put that call in methods that block the activity's life cycle, such as onCreate()
. In these cases, if the device is not connected, android can't attach to a debugger and kepps waiting forever.
So look for that call in your activity life cycle and remove it if found.
这篇关于只有当手机采用USB线连接到电脑启动Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!