Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android: Receiving Data from the Send Intent,將自己的app注冊系統分享

Android: Receiving Data from the Send Intent,將自己的app注冊系統分享

編輯:關於Android編程

當用戶在系統相冊,點擊分享時,能通過我們自己的app,分享該圖片。

1.注冊

主要是在AndroidManifest.xml中,對activity注冊Intent-filter,如:

 

        
    

2.處理:

 

在Activity中,獲取Intent中的文本和圖片等。

 

void onCreate (Bundle savedInstanceState) {
    ...
    // Get intent, action and MIME type
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (text/plain.equals(type)) {
            handleSendText(intent); // Handle text being sent
        } else if (type.startsWith(image/)) {
            handleSendImage(intent); // Handle single image being sent
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        if (type.startsWith(image/)) {
            handleSendMultipleImages(intent); // Handle multiple images being sent
        }
    } else {
        // Handle other intents, such as being started from the home screen
    }
    ...
}

void handleSendText(Intent intent) {
    String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (sharedText != null) {
        // Update UI to reflect text being shared
    }
}

void handleSendImage(Intent intent) {
    Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
    if (imageUri != null) {
        // Update UI to reflect image being shared
    }
}

void handleSendMultipleImages(Intent intent) {
    ArrayList imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
    if (imageUris != null) {
        // Update UI to reflect multiple images being shared
    }
}

更多閱讀:

 

簡單舉例: http://code.tutsplus.com/tutorials/android-sdk-receiving-data-from-the-send-intent--mobile-14878

更多交流,Android開發聯盟QQ群:272209595

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved