Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – How to detect when third party app’s dialog box appears in React native?

Posted on November 11, 2022 By

Solution 1 :

By onActivityResult we can detect the activity of third party apps fired by your app.

You’ll need to listen to onActivityResult if you want to get results from an activity you started with startActivityForResult. To do this, you must extend BaseActivityEventListener or implement ActivityEventListener.

http://reactnative.dev/docs/native-modules-android#getting-activity-result-from-startactivityforresult

Problem :

My app sends stickers to WhatsaApp and it shows a dialog box. How to wait for the user action on the dialog box and perform action after the dialog box gone.

export default function CreateScreen({route, navigation}){
    const [PreviewImages, setPreviewImages] = React.useState([]);
    const [isAnimated, setAnimated] = React.useState(false);
    const [PackName, setPackName] = React.useState(Date.now().toString());
    const [AuthorName, setAuthorName] = React.useState('');
    const [Version, setVersion] = React.useState(1);

    const context = React.useContext(AppContext);

    React.useLayoutEffect(() => {
        navigation.setOptions({
          headerRight: () => (
            <Button onPress={send} title="Create" color="#00ff00"/>
          ),
        });
    });
      

    const removePreview=(x)=>{
        setPreviewImages(PreviewImages.filter((i,index)=>index!==x));
    }

    const src = 'file://'+RNFS.DownloadDirectoryPath+'/'+'file10.jpg';
    const dest = 'file://'+RNFS.DownloadDirectoryPath+'/'+'file10_1.jpg';



    const send =async()=>{

        log('sending...')

        try{
        
            const packData = {
                authorName:AuthorName,
                packName:PackName,
                isAnimated:isAnimated,
                version:Version,
                previewImages:PreviewImages,
            }

            let jsonData = await DecoratePack(packData)


            await RNWhatsAppStickers.prepare(jsonData)
            .then(res=>res.slice(1))
            .then(str=>JSON.parse(str))
            .then(obj=>{
                log('pack ',obj['identifier'])
                return RNWhatsAppStickers.send(obj['identifier'],obj['identifier'])
            })
            .then(r2=>log(r2))
            .catch(err=>Alert.alert('Could not create pack',err.toString()))
            
        }catch(e){
            Alert.alert('Problem with pack',e.toString())
        }
        
        
    }


   
    return(
        <View style={root.main}>
            <Screen1/>
        </View>
    );
}

If I set the create button to navigate back to home screen after creatnig pack then whatsapp dialoge box will appear on home screen. It is kind of ok but dialog box is appeared to tell there is issue in pack or pack name already exist then it will be annoying for user to go to the create screen again.

Thanks for your help

READ  [FIXED] android - setCancelable(false) on Alert dialog does not work, when back button is clicked
Powered by Inline Related Posts
Android Tags:android, react-native, whatsapp, whatsapp-stickers

Post navigation

Previous Post: [FIXED] android – Overlapping items in RelativeLayout with ImageView and TextView
Next Post: [FIXED] android – Unable to instantiate application com.company.app.MainApplication: java.lang.ClassNotFoundException React Native Expo

Related Posts

[FIXED] java – How can I write my JSON data to external Storage Android
[FIXED] android – Can we runn mobile app tests in headless appium on a Physical Device (Non emulator)? Android
[FIXED] What is Android mini_emulator image? Android
[FIXED] java – Android Radio Button Bug Android
[FIXED] I want to send a string from an android device to a windows machine over wifi with c#. Is this possible? Android
[FIXED] android studio – Loading Emulator take forever Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is a good substitute for condensed milk?
  • ¿Como el cuerpo te avisa cuando te va a dar un infarto?
  • What is the luxury brand of Jaguar?
  • Who is Big poppa baseball player?
  • What material are foam runners?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme