2017-07-19 87 views
1

在我的反应本机应用程序中,我想与特定应用程序共享文本消息,例如WhatsApp或短信应用程序,而不必先与所有社交应用程序对话。在单个应用程序中反应本地共享

例如,如果我按下share按钮并直接调用whatsapp。

我试过使用react-native-share但它似乎不工作了。

回答

0

对于Android,该阵营机共享模块使用默认ACTION_SEND Android的意图:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 

为了有不同的行为,你需要或者写自己的RN插件,会跟你想要的应用程序它(如果这种功能可用)或在npm上找到类似的插件。

我假设你的插件应该做这样的事情:

Intent sendIntent = new Intent(); 
sendIntent.setAction(Intent.ACTION_SEND); 
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); 
sendIntent.setType("text/plain"); 
startActivity(sendIntent); 
sendIntent.setPackage("com.whatsapp"); 
+0

感谢@Yury。我搜索的NPM插件没有avail.Let我实现这个并提出反馈意见 – charles

2

您可以使用Linking它给你的通用接口与传入和传出的应用程序进行交互链接

例如:

import React, { Component } from 'react'; 
import { Linking, Button } from 'react-native'; 

export class App extends Component { 
    render() { 
    return <Button 
       onPress={() => { 
       let url = 'whatsapp://send?text=Hola Mundo'; 
       Linking.openURL(url).then((data) => { 
        console.log('open whatsapp') 
       }).catch(() => { 
        console.log('App not installed') 
       }); 
       }} 
       title="Whatsapp" 
       color="#4FBE3C"/>; 
    } 
} 
相关问题