Android – How to implicit intent from one app of my own to choose another 2 apps of my own?

huangapple go评论50阅读模式
英文:

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

&lt;activity
            android:name=&quot;.MainActivity2&quot;
            android:exported=&quot;false&quot; &gt;
            &lt;intent-filter&gt;
                &lt;action android:name=&quot;com.action.ex3.register&quot; /&gt;
                &lt;data android:mimeType=&quot;text/plain&quot;/&gt;
                &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
            &lt;/intent-filter&gt;

Then on 3rd client app i added this to the button

 findViewById&lt;Button&gt;(R.id.reg_btn).setOnClickListener {
            val intent = Intent()
           intent.setAction(&quot;com.action.ex3.register&quot;) // 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(&quot;com.example.abc&quot;);
startActivity( launchIntent );

huangapple
  • 本文由 发表于 2023年3月31日 04:41:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892831.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定