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;
+    }
相关推荐
还是奇怪2 小时前
Linux - 安全排查 3
android·linux·安全
Android采码蜂2 小时前
BLASTBufferQueue03-BufferQueueConsumer核心操作
android
Android采码蜂3 小时前
BLASTBufferQueue02-BufferQueueProducer核心操作
android
2501_915921433 小时前
没有Mac如何完成iOS 上架:iOS App 上架App Store流程
android·ios·小程序·https·uni-app·iphone·webview
码农明明4 小时前
Google Play 应用上架二三事
android·google
红橙Darren7 小时前
手写操作系统 - 环境搭建
android·微信·操作系统
_一条咸鱼_7 小时前
Android Runtime直接内存管理原理深度剖析(73)
android·面试·android jetpack
你听得到117 小时前
揭秘Flutter图片编辑器核心技术:从状态驱动架构到高保真图像处理
android·前端·flutter
wilinz7 小时前
Flutter Android 端接入百度地图踩坑记录
android·flutter
小袁拒绝摆烂10 小时前
SQL开窗函数
android·sql·性能优化