开发者

How can I to handle the "share via" dialog request from other app?

I added the intent-filter to ApplicationManifest.xml to take my app to "Share via" Dialog:

<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>

How can I handle the request from another app.

1 Is it possible to differentiate between 开发者_JS百科directly app-start and sharing start?

2 How to get access to sharing data?


In onCreate you can call getIntent() to see if there is any data in the bundle. Use the getData() method to retrieve a Uri or one of the get...Extra methods to retrieve any other expected data.

void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.id.main);
    ...
    Intent i = getIntent();
    Uri data = i.getUri(); 
    if(data != null) {
    // do something interesting
    }
    /* or */
    String text = i.getStringExtra(Intent.EXTRA_TEXT);
    / * do something interesting with the text */
}


regarding question 1: in direct app-start case, the intent action would not be SEND.

for question 2 see my comment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜