millo-L / react-native-kakao-share-link

리액트 네이티브 카카오 링크 오픈 소스
MIT License
30 stars 24 forks source link

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? #17

Closed jook-bob2 closed 1 year ago

jook-bob2 commented 1 year ago

안드로이드에서 오류 발생하면서 앱이 Shut down 됩니다. 해결 방법 아시는 분 계신가요? ㅠㅠ

D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.reselloapp, PID: 28956 android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? at android.app.ContextImpl.startActivity(ContextImpl.java:1080) at android.app.ContextImpl.startActivity(ContextImpl.java:1056) at android.content.ContextWrapper.startActivity(ContextWrapper.java:411) at android.content.ContextWrapper.startActivity(ContextWrapper.java:411) at com.kakao.sdk.common.util.KakaoCustomTabsClient$openWithDefault$connection$1.onCustomTabsServiceConnected(KakaoCustomTabsClient.kt:48) at androidx.browser.customtabs.CustomTabsServiceConnection.onServiceConnected(CustomTabsServiceConnection.java:33) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2077) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2110) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

[버전 정보] "react": "18.1.0", "react-native": "0.70.5", "react-native-kakao-share-link": "^1.0.6"

buildToolsVersion = "31.0.0" minSdkVersion = 21 compileSdkVersion = 31 targetSdkVersion = 31 kotlinVersion = "1.7.20"

jook-bob2 commented 1 year ago

앱이 설치되지 않았을 경우 발생하는 문제 였습니다. 그래서 카카오톡 설치 여부 체크 후 open 하도록 진행했습니다.

const checkUrl =kakao{${env.KAKAO_APP_KEY}}://kakaolink?key1=value1&key2=value2&key3=value3` const installed = await Linking.canOpenURL(checkUrl) console.log('Kakaotalk installed ? ', installed)

if (!installed) {
    const alterUrl =
        Platform.OS === 'android'
            ? 'market://details?id=com.kakao.talk'
            : 'itms-apps://itunes.apple.com/app/id362057947'
    await Linking.openURL(alterUrl)
} else {
    try {
        const response = await KakaoShareLink.sendFeed({
            content: {
                title: 'title',
                imageUrl: 'http://t1.daumcdn.net/friends/prod/editor/dc8b3d02-a15a-4afa-a88b-989cf2a50476.jpg',
                link: {
                    mobileWebUrl: 'https://developers.kakao.com/',
                    webUrl: 'https://developers.kakao.com/',
                    // androidExecutionParams: [
                    //  {
                    //      key: 'key1',
                    //      value: 'value1',
                    //  },
                    // ],
                    // iosExecutionParams: [
                    //  {
                    //      key: 'key1',
                    //      value: 'value1',
                    //  },
                    // ],
                },
                description: 'description',
            },
            buttons: [
                {
                    title: '앱에서 보기',
                    link: {
                        mobileWebUrl: 'https://developers.kakao.com/',
                        webUrl: 'https://developers.kakao.com/',
                        // androidExecutionParams: [{ key: 'key1', value: 'value1' }],
                        // iosExecutionParams: [
                        //  { key: 'key1', value: 'value1' },
                        //  { key: 'key2', value: 'value2' },
                        // ],
                    },
                },
            ],
        })
        console.log('response ', response)
    } catch (e) {
        console.error(e)
    }
}

`

jook-bob2 commented 1 year ago

앱이 설치되지 않았을 경우 발생하는 문제 였습니다. 그래서 카카오톡 설치 여부 체크 후

const checkUrl =kakao{${env.KAKAO_APP_KEY}}://kakaolink?key1=value1&key2=value2&key3=value3` const installed = await Linking.canOpenURL(checkUrl) console.log('Kakaotalk installed ? ', installed)

    if (!installed) {
    const alterUrl =
        Platform.OS === 'android'
            ? 'market://details?id=com.kakao.talk'
            : 'itms-apps://itunes.apple.com/app/id362057947'
    await Linking.openURL(alterUrl)
} else {
    try {
        const response = await KakaoShareLink.sendFeed({
            content: {
                title: 'title',
                imageUrl: 'http://t1.daumcdn.net/friends/prod/editor/dc8b3d02-a15a-4afa-a88b-989cf2a50476.jpg',
                link: {
                    mobileWebUrl: 'https://developers.kakao.com/',
                    webUrl: 'https://developers.kakao.com/',
                    // androidExecutionParams: [
                    //  {
                    //      key: 'key1',
                    //      value: 'value1',
                    //  },
                    // ],
                    // iosExecutionParams: [
                    //  {
                    //      key: 'key1',
                    //      value: 'value1',
                    //  },
                    // ],
                },
                description: 'description',
            },
            buttons: [
                {
                    title: '앱에서 보기',
                    link: {
                        mobileWebUrl: 'https://developers.kakao.com/',
                        webUrl: 'https://developers.kakao.com/',
                        // androidExecutionParams: [{ key: 'key1', value: 'value1' }],
                        // iosExecutionParams: [
                        //  { key: 'key1', value: 'value1' },
                        //  { key: 'key2', value: 'value2' },
                        // ],
                    },
                },
            ],
        })
        console.log('response ', response)
    } catch (e) {
        console.error(e)
    }
}

`