About iFLYTEK SpeechSynthesizer.createSynthesizer(this, this); equal to null

Regarding the issue of iFLYTEK SpeechSynthesizer.createSynthesizer(this, this); equal to null,

1. Make sure your so library is added correctly android studio needs to create the jniLibs folder by yourself 

2. Whether your project uses Umeng push or a push or other third parties. These third parties have some processes. When your app starts, the onCreate method of Application will be called twice, but the initialization of iFLYTEK can only be initialized once. If you continue to initialize, SpeechSynthesizer.createSynthesizer(this, this); equals to null. At this time, you need to determine whether it is the current process of the current application to initialize

 Solution

String processName = getProcessName(this, android.os.Process.myPid());
		if(processName != null){
			boolean defaultProcess = processName.equals("com.xxx.oc");
			if(defaultProcess) {
				//Initialize the current application
				     SpeechUtility.createUtility(this, "appid=5a76eae2");//Initialize iFLYTEK voice
                mTts = SpeechSynthesizer.createSynthesizer(this, this);
			}
		}

			}


	public static String getProcessName(Context cxt, int pid) {
		ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
		List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
		if (runningApps == null) {
			return null;
		}
		for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
			if (procInfo.pid == pid) {
				return procInfo.processName;
			}
		}
		return null;
	}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326005741&siteId=291194637