需要对React本机sendIntent()进行说明

whhtz7ly  于 2022-11-30  发布在  React
关注(0)|答案(1)|浏览(170)

在react native中,我们可以用这个来打开一个特定的吗?这里extra有什么用

import React, { useCallback } from "react";
import { Alert, Button, Linking, StyleSheet, View } from "react-native";

const SendIntentButton = ({ action, extras, children }) => {
  const handlePress = useCallback(async () => {
    try {
      await Linking.sendIntent(action, extras);
    } catch (e) {
      Alert.alert(e.message);
    }
  }, [action, extras]);

  return <Button title={children} onPress={handlePress} />;
};

const App = () => {
  return (
    <View style={styles.container}>
      <SendIntentButton action="android.intent.action.POWER_USAGE_SUMMARY">
        Power Usage Summary
      </SendIntentButton>
      <SendIntentButton
        action="android.settings.APP_NOTIFICATION_SETTINGS"
        extras={[
          { "android.provider.extra.APP_PACKAGE": "com.facebook.katana" },
        ]}
      >
        App Notification Settings
      </SendIntentButton>
    </View>
  );
};

const styles = StyleSheet.create({
  container: { flex: 1, justifyContent: "center", alignItems: "center" },
});

export default App;

尝试理解android中的意图

tzcvj98z

tzcvj98z1#

在Android上,这将在设置中打开通知。extras提供了您要编辑通知设置的应用程序。有关此属性的更多信息,请参阅Android文档。
通常,这些额外内容应包括应用的标识符。

相关问题