首页 \ 问答 \ 无法为活动加载语音触发器(Unable to load voice trigger for activity)

无法为活动加载语音触发器(Unable to load voice trigger for activity)

Android清单:

<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
....
<activity
            android:name=".MainActivity"
            android:label="@string/app_name" 
            android:icon="@drawable/ic_launcher" >                      

            <intent-filter>                                
                <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />               
            </intent-filter>
            <meta-data 
                android:name="com.google.angroid.glass.VoiceTrigger"
                android:resource="@xml/voice_trigger" />

            <intent-filter>
                <action android:name="android.speech.action.RECOGNIZE_SPEECH" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>                            
        </activity>

voice_trigger.xml(... \ res \ xml)

<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/glass_voice_trigger" />

strings.xml中

<string name="glass_voice_trigger">control</string>

每当我运行我的代码时,VoiceTriggers会记录它无法为我的主要活动构建语音触发器(抛出VoiceTriggerBuildingException),因为找不到语音触发器的配置文件。

有没有其他人遇到过这个问题?


Android manifest:

<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
....
<activity
            android:name=".MainActivity"
            android:label="@string/app_name" 
            android:icon="@drawable/ic_launcher" >                      

            <intent-filter>                                
                <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />               
            </intent-filter>
            <meta-data 
                android:name="com.google.angroid.glass.VoiceTrigger"
                android:resource="@xml/voice_trigger" />

            <intent-filter>
                <action android:name="android.speech.action.RECOGNIZE_SPEECH" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>                            
        </activity>

voice_trigger.xml (...\res\xml)

<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/glass_voice_trigger" />

strings.xml

<string name="glass_voice_trigger">control</string>

Whenever I run my code, VoiceTriggers logs that it was unable to build the voice trigger for my main activity (throws VoiceTriggerBuildingException) because the config file for the voice trigger was not found.

Did anyone else run across this problem?


原文:https://stackoverflow.com/questions/26749912
更新时间:2023-06-10 20:06

最满意答案

您必须将模型作为参数传递给处理程序。

controller.js

$scope.nam = guillaume;
$scope.firstchange = function(nam){
    $scope.displayed = {'display':'block'};
    console.log(nam);

};

home.html的

<input ng-change="firstchange(nam)" ng-model="nam" class="param-right"></input><p>Prénom</p>

You have to pass the model as a parameter to your handler.

controller.js

$scope.nam = guillaume;
$scope.firstchange = function(nam){
    $scope.displayed = {'display':'block'};
    console.log(nam);

};

home.html

<input ng-change="firstchange(nam)" ng-model="nam" class="param-right"></input><p>Prénom</p>

相关问答

更多
  • 他们不一样,很清楚。 一个仅用于控制器; 另一个是输入元素的指令。 但即使在他们的应用程序,他们有所不同 当您使用$watch ,将在每个摘要循环中评估观察表达式,如果有更改,则调用处理程序。 使用ng-change ,会响应于事件显式调用处理程序。 使用$watch ,更改可以来自任何地方:用户操作,控制器功能,服务 - 都将触发处理程序。 使用ng-change ,更改仅限于用户对特定输入元素的操作。 值得注意的是, ng-change 仅与ng-model结合使用 - 换句话说, ng-change表 ...
  • AngularJS 1.3+ 由于AngularJS 1.3,您可以使用debounce属性ngModelOptions来实现非常简单,而不必使用$timeout 。 这里有一个例子: HTML:

  • 您可以使用$scope.$watch 。 监视传递给指令的模型,并在触发更改时启用保存按钮,例如: .directive('enableSave', function() { return { require: 'ngModel', restrict: 'A', link: function(scope, elm, attr, ngModel) { scope.$watch('modeltowatch', function(newvalue,oldvalue){ ...
  • 您需要延迟来获取$scope.form的更新值,因此可以通过使用$timeout来实现 http://jsfiddle.net/loen22/w7dpx57f/ $scope.checkRadios = function(){ $timeout(function () { console.log($scope.form.$valid); }); } You need a delay to get the updated value of the $scope.form, so it is ...
  • 你可以使用ng-model并在ng-change回调中访问它,或者直接传递它。