简体   繁体   English

如何从 Android 中的另一个应用程序启动 Activity 30

[英]How to launch an Activity from another Application in Android 30

I have been using the following code to open my other app from within my app.我一直在使用以下代码从我的应用程序中打开我的其他应用程序。 This code works upto Android 29 devices but this code does not work in Android 30 devices.此代码适用于 Android 29 个设备,但此代码不适用于 Android 30 个设备。 Can somebody please help me make it work for Android 30 as well.有人可以帮我使它也适用于 Android 30。 Thanks谢谢

    case R.id.btAudio:

        Intent launchIntent = getPackageManager().getLaunchIntentForPackage(getString("com.android.audioapp"));
        Intent uin = new Intent(MainActivity.this, AudioInstall.class);
        if (launchIntent != null) {
            startActivity(launchIntent);
        } else {
            startActivity(uin);
        }
        this.finish();
        break;

Android 11 added restrictions regarding the visibility of other apps. Android 11 添加了有关其他应用程序可见性的限制。 Apps that have targetSdk set to >= 30 can't interact with and open other apps without specifying this in the manifest.targetSdk设置为 >= 30 的应用程序无法与其他应用程序交互并打开其他应用程序,除非在清单中指定此项。

To specify that your app interacts with another specific app, you need to add a <queries> element to your manifest file:要指定您的应用与另一个特定应用交互,您需要在清单文件中添加一个<queries>元素:

<manifest package="com.example.game">
    <queries>
        <package android:name="com.android.audioapp" />
    </queries>
    ...
</manifest>

The link below contains other examples in case you need to specify a broader range of apps which you want to interact with.如果您需要指定要与之交互的更广泛的应用程序,下面的链接包含其他示例。

Source: https://developer.android.com/training/basics/intents/package-visibility资料来源: https://developer.android.com/training/basics/intents/package-visibility

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM