# AndroidAppFrame **Repository Path**: afeng124/android-app-frame ## Basic Information - **Project Name**: AndroidAppFrame - **Description**: Android App Frame,使用AndroidX非Jetpack+Kotlin。 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2024-07-23 - **Last Updated**: 2025-06-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AndroidAppFrame #### 介绍 Android App Frame,使用AndroidX非Jetpack+Kotlin。支持中英文切换。 #### 软件架构 Java + AndroidX (MVC) #### 截图 ![输入图片说明](images/mainui.png) ![输入图片说明](images/sub.png) **使用了科大讯飞语言+,TTS语音合成引擎,需要单独安装** 。 链接: https://pan.baidu.com/s/1NW-pPE1cLhgrfLS_QZAybw?pwd=64ja 提取码: 64ja 复制这段内容后打开百度网盘手机App,操作更方便哦 ``` package com.nianda.smartclient; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.os.Bundle; import android.os.RemoteException; import com.google.android.material.bottomnavigation.BottomNavigationView; import androidx.appcompat.app.AppCompatActivity; import androidx.navigation.NavController; import androidx.navigation.Navigation; import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.NavigationUI; import com.iflytek.speech.ErrorCode; import com.iflytek.speech.ISpeechModule; import com.iflytek.speech.InitListener; import com.iflytek.speech.SpeechSynthesizer; import com.iflytek.speech.SpeechUtility; import com.iflytek.speech.SynthesizerListener; import com.nianda.smartclient.databinding.ActivityMainBinding; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private ActivityMainBinding binding; protected SharedPreferences sp = null; private static MainActivity instance = null; private SpeechSynthesizer mTts; private boolean isPlaySound = false; private ArrayList ttsList = new ArrayList(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = ActivityMainBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); BottomNavigationView navView = findViewById(R.id.nav_view); AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder( R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications) .build(); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main); NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); NavigationUI.setupWithNavController(binding.navView, navController); instance = this; initVoiceService(); } public static MainActivity getInstance() { return instance; } public void SpeakVoice(String text) { if (mTts != null && !isPlaySound) { mTts.startSpeaking(text, mTtsListener); } else { ttsList.add(text); } } /** * 初期化监听。 */ private InitListener mTtsInitListener = new InitListener() { @Override public void onInit(ISpeechModule arg0, int code) { if (code == ErrorCode.SUCCESS) { mTts.startSpeaking("TTS语音合成引擎初始化成功。", mTtsListener); } } }; /** * 合成回调监听。 */ private SynthesizerListener mTtsListener = new SynthesizerListener.Stub() { @Override public void onBufferProgress(int progress) throws RemoteException { } @Override public void onCompleted(int code) throws RemoteException { isPlaySound = false; if (ttsList.size() > 0) { String text = ttsList.get(0); getInstance().SpeakVoice(text); ttsList.remove(0); } } @Override public void onSpeakBegin() throws RemoteException { isPlaySound = true; } @Override public void onSpeakPaused() throws RemoteException { } @Override public void onSpeakProgress(int progress) throws RemoteException { } @Override public void onSpeakResumed() throws RemoteException { } }; private void initVoiceService() { if (checkSpeechServiceInstall()) { // 引擎初始化 SpeechUtility.getUtility(this).setAppid("53c776aa"); mTts = new SpeechSynthesizer(this, mTtsInitListener); } else mTts = null; } /** * 检测科大讯飞语音+引擎是否安装 * * @return */ private boolean checkSpeechServiceInstall() { String packageName = "com.iflytek.speechcloud"; List packages = getPackageManager() .getInstalledPackages(0); for (int i = 0; i < packages.size(); i++) { PackageInfo packageInfo = packages.get(i); if (packageInfo.packageName.equals(packageName)) { return true; } else { continue; } } return false; } } ```