●實作練習:預期畫面
=>當在其他app中看到要分享的文字、圖片、影像..等,點分享可以跳出自己的app分享我們自己的app中
=>圖中將fb的圖片分享到我們的app--"ImplicitIntentAndShareContent"中
●程式--AndroidManifest.html
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!--定義分享的資料型態-->
<data android:mimeType="image/*" />
<!--如果自己寫了一個APP也要能分享就要在Manifest
加上action android:name="ACTION_SEND",
當使用者使用分享功能時,自己的APP就會出現在可以選擇分享的APP清單上-->
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
●程式--java code
MainActivity.java
private ImageView mShowImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mShowImage = findViewById(R.id.showImg);
//在其他app按分享時可以看到自己的app 並將檔案分享到自己的app上
if (getIntent() != null && getIntent().getExtras() != null) {
//Intent.EXTRA_STREAM:
//URI holding a stream of data associated with the Intent,
//used with ACTION_SEND to supply the data being sent.
String uri = getIntent().getExtras().get(Intent.EXTRA_STREAM).toString();
mShowImage.setImageURI(Uri.parse(uri));
}
}
●程式參考(GitHub):Implicit Intent / Share Content
文章標籤
全站熱搜
