PackageManager表示设备没有FEATURE_MIDI

时间:2018-02-04 15:52:53

标签: android midi

如何编写Android应用程序以接收Yamaha YDP-113电子钢琴的MIDI事件?

当我强制它时,我收到运行时错误:

FATAL EXCEPTION: main
Process: com.example.android.miditest, PID: 19022
java.lang.NoClassDefFoundError: android.media.midi.MidiManager

hasSystemFeature()方法返回false:

    if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) {
        // do MIDI stuff
        Log.d("MainActivity-onCreate", "has MIDI feature");

        TextView info = (TextView) findViewById(R.id.info_text_view);
        info.setText("MIDI found!");

        MidiManager m = (MidiManager) getSystemService(Context.MIDI_SERVICE);
    }
    else {
        Log.d("MainActivity-onCreate", "cannot find MIDI feature");

        TextView info = (TextView) findViewById(R.id.info_text_view);
        info.setText("Sorry, no MIDI");
    }

这是我的清单:

<uses-feature android:name="android.software.midi" android:required="true"/>
<uses-feature android:name="android.hardware.usb.host"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

我确信这一定是可能的,因为我在AppsTransport上安装了“USB Midi Keyboard”,在Google Play商店中有100,000次下载。当我在Yamaha YDP-113上弹奏音符时,该应用程序会显示我按下的钢琴键盘键,甚至可以发出声音!

其他开发人员使用什么,允许他们制作适用于我的键盘,MIDI-USB线和三星平板电脑的应用?我需要在手机上安装一些东西吗?或者我需要告诉gradle一些包或下载?

1 个答案:

答案 0 :(得分:1)

MidiManager仅适用于Android 6+。 和相关功能类在以前的版本中不存在,因此如果您在旧设备上运行该应用程序,则会出现错误。

如果您想支持比Android 6更旧的设备,您将不得不使用某种专有SDK或第三方库。

快速网络搜索建议kshoji/USB-MIDI-Driver可以为您提供帮助。

请注意,如果您指定

<uses-feature android:name="android.software.midi" android:required="true"/>
  

对于不支持MIDI API的旧设备,该应用不会出现在Play商店中。

来源:https://developer.android.com/reference/android/media/midi/package-summary.html

您可能想删除该行。

相关问题