RK Android14 在计算器内输入特定字符跳转到其他应用

文章目录

需求

在计算器内输入特定字符,跳转到其他应用

解决

路径:/packages/apps/ExactCalculator/src/com/android/calculator2/Calculator.java

xml 复制代码
diff --git a/packages/apps/ExactCalculator/src/com/android/calculator2/Calculator.java b/packages/apps/ExactCalculator/src/com/android/calculator2/Calculator.java
index 60ce3da..bc5b993 100644 (file)
--- a/packages/apps/ExactCalculator/src/com/android/calculator2/Calculator.java
+++ b/packages/apps/ExactCalculator/src/com/android/calculator2/Calculator.java
@@ -71,6 +71,13 @@ import android.view.animation.AccelerateDecelerateInterpolator;
 import android.widget.HorizontalScrollView;
 import android.widget.TextView;
 import android.widget.Toolbar;
+import android.widget.Toast;
+
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.ComponentName;
+import java.util.List;
+import android.content.Context;
 
 import com.android.calculator2.CalculatorFormula.OnTextSizeChangeListener;
 
@@ -232,6 +239,10 @@ public class Calculator extends Activity
 
         @Override
         public void onTextChanged(CharSequence charSequence, int start, int count, int after) {
+                       if (charSequence.toString().equals("****")) {//特定字符
+                startActivity(getAppOpenIntentByPackageName(Calculator.this, "com.应用的包名"));
+                onClear();
+            }
         }
 
         @Override
@@ -243,6 +254,30 @@ public class Calculator extends Activity
             }
         }
     };
+       
+       public Intent getAppOpenIntentByPackageName(Context context, String packageName) {
+         String mainAct = null;
+         PackageManager pkgMag = context.getPackageManager();
+         Intent intent = new Intent(Intent.ACTION_MAIN);
+         intent.addCategory(Intent.CATEGORY_LAUNCHER);
+         intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
+
+         List<ResolveInfo> list = pkgMag.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES);
+         for (int i = 0; i < list.size(); i++) {
+             ResolveInfo info = list.get(i);
+             if (info.activityInfo.packageName.equals(packageName)) {
+                 mainAct = info.activityInfo.name;
+                 break;
+             }
+         }
+
+         if (TextUtils.isEmpty(mainAct)) {
+             return null;
+         }
+
+         intent.setComponent(new ComponentName(packageName, mainAct));
+         return intent;
+    }
相关推荐
fivestar20091 小时前
android studio中看错误问题
android·ide·android studio
小林熬夜学编程1 小时前
【MySQL】第十五弹---全面解析事务:定义、起源、版本支持与提交方式
android·linux·服务器·开发语言·数据库·mysql
&有梦想的咸鱼&1 小时前
Android Glide 缓存模块源码深度解析
android·缓存·glide
Gracker2 小时前
Android Weekly #202510
android·android studio
张风捷特烈2 小时前
Trae&Flutter | 助力 TolyUI 模块管理与发布
android·flutter·trae
恋猫de小郭3 小时前
再聊 Flutter Riverpod ,注解模式下的 Riverpod 有什么特别之处,还有发展方向
android·前端·flutter
*星星之火*7 小时前
【GPT入门】第5课 思维链的提出与案例
android·gpt
EasyCVR7 小时前
EasyRTC嵌入式视频通话SDK的跨平台适配,构建web浏览器、Linux、ARM、安卓等终端的低延迟音视频通信
android·arm开发·网络协议·tcp/ip·音视频·webrtc
张拭心10 小时前
2024 总结,我的停滞与觉醒
android·前端