Skip to content

Commit

Permalink
Merge pull request #98 from android/yaraki/share-receiver
Browse files Browse the repository at this point in the history
Share: Receive data from other apps
  • Loading branch information
yaraki authored Sep 20, 2023
2 parents 584c86c + 5f0093e commit 9d12bca
Show file tree
Hide file tree
Showing 12 changed files with 530 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .idea/runConfigurations/app.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion samples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Available Samples

- [](user-interface/predictiveback/src/main/java/com/example/platform/ui/predictiveback/PBHostingActivity.kt):

- [App Widgets](user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/AppWidgets.kt):
Showcases how to pin widget within the app. Check the launcher widget menu for all the app widgets samples
- [Call Notification Sample](connectivity/callnotification/src/main/java/com/example/platform/connectivity/callnotification/CallNotificationSample.kt):
Expand Down Expand Up @@ -80,9 +82,10 @@ Select images/videos in a privacy-friendly way using the photo picker
Basic usage of Picture-in-Picture mode showcasing a stopwatch
- [Picture in Picture (PiP) - Video playback](user-interface/picture-in-picture/src/main/java/com/example/android/pip/PiPMovieActivity.kt):
Basic usage of Picture-in-Picture mode showcasing video playback
- [Predictive Back](user-interface/predictiveback/src/main/java/com/example/platform/ui/predictiveback/PBHostingActivity.kt):
- [Quick Settings](user-interface/quicksettings/src/main/java/com/example/platform/ui/quicksettings/QuickSettings.kt):
Add your custom tile to the Quick Settings.
- [Receive data shared by other apps](user-interface/share/src/main/java/com/example/platform/ui/share/receiver/ShareReceiverActivity.kt):
Receive texts and images from other apps.
- [Scan with BLE Intent](connectivity/bluetooth/ble/src/main/java/com/example/platform/connectivity/bluetooth/ble/BLEScanIntentSample.kt):
This samples shows how to use the BLE intent to scan for devices
- [Screenshot Detection](privacy/transparency/src/main/java/com/example/platform/privacy/transparency/ScreenshotDetection.kt):
Expand Down
51 changes: 51 additions & 0 deletions samples/user-interface/share/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,61 @@
android:exported="false"
android:grantUriPermissions="true" />

<!-- This BroadcastReceiver handles results of the sharesheet. -->
<receiver
android:name=".sender.ShareResultReceiver"
android:exported="false" />

<activity
android:name=".receiver.ShareReceiverActivity"
android:exported="true"
android:label="@string/receive_share">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!--
Handle ACTION_SEND intents to receive data shared by other apps.
-->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />

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

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

<!--
The app should handle Intent that's dispatched when one of our dynamic shortcuts is
clicked. This is typically done with ACTION_VIEW intents with content URI for the
clicked item.
-->
<intent-filter>
<action android:name="android.intent.action.VIEW" />

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

<data
android:host="platform.example.com"
android:pathPattern="/receiver/*"
android:scheme="https" />
</intent-filter>

<!--
This XML describes what our dynamic shortcuts support.
-->
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/sharing_shortcuts" />

</activity>

</application>

</manifest>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.platform.ui.share.receiver

import android.net.Uri
import androidx.core.net.toUri

private const val shortcutIdPrefix = "contact-"

data class Contact(
val id: Long,
val name: String,
val filename: String,
) {
companion object

val shortcutId: String
get() = "$shortcutIdPrefix$id"

val contentUri: Uri
get() = "https://platform.example.com/receiver/contact/$id".toUri()
}

val Contact.Companion.All: List<Contact>
get() = listOf(
Contact(id = 1L, name = "Cat", filename = "contact/cat.jpg"),
Contact(id = 2L, name = "Dog", filename = "contact/dog.jpg"),
Contact(id = 3L, name = "Parrot", filename = "contact/parrot.jpg"),
Contact(id = 4L, name = "Sheep", filename = "contact/sheep.jpg"),
)

fun Contact.Companion.fromShortcutId(shortcutId: String): Contact? {
if (!shortcutId.startsWith(shortcutIdPrefix)) return null
val id = shortcutId.substring(shortcutIdPrefix.length).toLongOrNull() ?: return null
return All.find { it.id == id }
}
Loading

0 comments on commit 9d12bca

Please sign in to comment.