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;
+    }
相关推荐
智算菩萨1 小时前
MP3音频编码原理深度解析与Python全参数调优实战:从心理声学模型到LAME编码器精细控制
android·python·音视频
studyForMokey3 小时前
【Android面试】Activity生命周期专题
android·面试·职场和发展
chehaoman3 小时前
MySQL的索引
android·数据库·mysql
恋猫de小郭6 小时前
React Native 鸿蒙 2026 路线发布,为什么它的适配成本那么高?
android·前端·react native
studyForMokey7 小时前
【Android面试】窗口机制专题
android·面试·职场和发展
用户013201436038 小时前
Android 资源管理与常用布局详解|基础入门
android
陆业聪8 小时前
从 OpenClaw 到 Android:Harness Engineering 是怎么让 Agent 变得可用的
android·人工智能·ai编程
stevenzqzq10 小时前
颜色透明度转换技术文档(Android/Compose)
android
巴黎没有摩天轮Li11 小时前
Android JVMTI 接入流程
android
2501_9159090612 小时前
iOS 抓包不越狱,代理抓包 和 数据线直连抓包两种实现方式
android·ios·小程序·https·uni-app·iphone·webview