英文:
Android - How to implicit intent from one app of my own to choose another 2 apps of my own?
问题
I have two apps of my own that are clones of each other just with different names, and a 3rd app that switches between these two. By clicking on a button from the 3rd app, I want to open the app chooser and go directly to the 2nd activity, not the main one.
I added this intent filter to the original two apps to jump to the 2nd activity:
<activity
android:name=".MainActivity2"
android:exported="false" >
<intent-filter>
<action android:name="com.action.ex3.register" />
<data android:mimeType="text/plain"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Then, in the 3rd client app, I added this to the button:
findViewById<Button>(R.id.reg_btn).setOnClickListener {
val intent = Intent()
intent.action = "com.action.ex3.register" // Action for what intent called for
startActivityForResult(intent, 2)
}
Note: I know that startActivityForResult
is deprecated, but the lecturer still wants this method.
英文:
I have two apps of my own that are clone of each other just with different names. and a 3rd app that jumps between those two. by clicking on a button from 3rd app i wanna to open up app chooser and just between the 2 and jump immediately to 2nd activity not the main one.
I added this intent filter to the original two apps so it jumps to the 2nd activity
<activity
android:name=".MainActivity2"
android:exported="false" >
<intent-filter>
<action android:name="com.action.ex3.register" />
<data android:mimeType="text/plain"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Then on 3rd client app i added this to the button
findViewById<Button>(R.id.reg_btn).setOnClickListener {
val intent = Intent()
intent.setAction("com.action.ex3.register") // Action for what intent called for
startActivityForResult(intent,2)
note: I know that startActivityforResult is deprecated, but the lecturer still wants this method
答案1
得分: 2
请使用以下代码与您的包名称启动该应用:
val launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.abc");
startActivity(launchIntent);
英文:
Use the below code with your package name to launch that app :
val launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.abc");
startActivity( launchIntent );
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论