我正在为车载设备(Andriod 5.1.1)中的Xposed编写模块。
我无法将声音加载到SoundPool中。 Andriod Studio找到文件(当您单击Yu时,文件R.raw.back开始播放。带有Activity的测试程序可以正常工作。
我将文件back.ogg放置在res \ raw文件夹和文件夹资产中。两次下载均失败。另外,创建带有图片的自定义吐司时会出错
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
XC_MethodHook onCreate = new XC_MethodHook() {
@SuppressLint({ "sendToast" })
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Log.d(BackView.TAG, "onCreate");
microntekServer = (Service) param.thisObject;
context = (Context) param.thisObject;
try {
AudioAttributes audioAttrib = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_GAME)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
sp = new SoundPool.Builder().setAudioAttributes(audioAttrib).setMaxStreams(MAX_STREAMS).build();
sp.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
soundLoad = true;
Log.d(TAG, "BackId=" + sampleId + ", status=" + status);
}
});
try {
AssetFileDescriptor afd = context.getAssets().openFd("back.ogg");
Log.d(TAG, "open");
soundIdBack = sp.load(afd, 1); <- 1 expample
Log.d(TAG, "OK");
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
soundIdBack = sp.load(context, R.raw.back, 1); <- 2 expample
Log.d(TAG, "sp load");
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
};
if (lpparam.packageName.equals(SERVICE_PACKAGE_NAME)) {
Utils.setTag(TAG);
Utils.readXposedMap();
Log.d(TAG, SERVICE_PACKAGE_NAME + " hook START");
Utils.findAndHookMethodCatch("android.microntek.service.MicrontekServer", lpparam.classLoader, "onCreate",
onCreate);
Log.d(TAG, SERVICE_PACKAGE_NAME + " hook OK");
}
}
错误加载文件示例1:back.ogg错误加载文件示例2: 尝试调用接口方法'java.lang.String 空对象引用上的java.lang.CharSequence.toString()'