如何获取与我的应用共享数据的应用

时间:2019-04-06 20:57:07

标签: android kotlin

我正在构建一个可以与其他应用共享文本(链接等)的应用。

是否可以获取与我的应用共享数据的应用的名称?

我已经发现refer.host巫婆给了我共享应用程序的URI,但是URI不同( com.reddit.frontpage com.google.android.youtube )使得解析困难。

1 个答案:

答案 0 :(得分:0)

将此代码添加到清单中

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >

        //Add this line
        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="*/*" />
        </intent-filter>
        //---------------

    </activity>
</application>

现在在MainActivity中添加此代码以获取其他应用的共享数据

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Get intent, action and MIME type
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    // You would then use these three variable to figure out who has sent you an Intent and what they want you to do!
    // See here for further instruction: https://developer.android.com/training/sharing/receive.html
    // https://developer.android.com/guide/topics/manifest/action-element.html
    // https://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT

}
}

希望这对您有帮助!

谢谢。