0

我想覆盖 android 中的 RecognizerIntent 视图。为此,我尝试在 Android 中扩展 RecognizerIntent 类,如下所示:

package com.example.myapp;

import android.content.Context; 
import android.speech.RecognizerIntent;

public class RecInt extends RecognizerIntent {

    public RecInt(Context c) {
        super(c);
//if I don't call super here, there is an error 'There is no default constructor available in RecognizerIntent'
    } 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recint);
    }
}

但我得到了错误

RecognizerIntent() 在 android.speech.RecognizerIntent 中不公开,无法从外部包访问。

有什么办法我仍然可以扩展非公共课程吗?

我想这样做以便何时RecInt开始

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
startActivityForResult(intent,100);

中的视图setContentView(R.layout.activity_recint)显示,而不是RecognizerIntent视图。

4

1 回答 1

1

RecognizerIntent() 不是公开的

构造函数不是公开的。班级是公开的

您可以扩展课程,但不能调用super. 目前尚不清楚您为什么要这样做,或者给出一个上下文。它似乎没有提供该构造函数

另外,该类不是 Activity ,因此所有 onCreate 代码都是错误的

于 2016-11-04T01:33:50.430 回答