受欢迎的博客标签

Android|Android Studio|-App share Linking

Published

Here(https://developer.android.com/training/sharing/receive) is the documentation on how to setup an Android application as a sharing target and the sample below uses that as a reference.

 

Table of Content

Part 1:Android SDK: Implement a Share Intent app with Android Studio Step by step 

 

iphone: Galaxy S21 series

Step 1: Create a new project in Android Studio

go to File ⇒ New Project and fill all required details to create a new project.

You will use android studio to create an Android application and name it as My Application.

Step 2:Make your app appear in the share menu

To make your app appear in the share menu,Modify AndroidManifest.xml to add <intent-filter> to define rules for your intent to invoke custom activity.

You will use <intent-filter> element in the manifest file to list down actions, categories and data types associated with any activity, service, or broadcast receiver.

you will need add additional code like below:

AndroidManifest.xml file

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name" 
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true" 
    android:theme="@style/AppTheme">

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

    </application> 

Intent Filters

Android OS uses filters to pinpoint the set of Activities, Services, and Broadcast receivers that can handle the Intent with help of specified set of action, categories, data scheme associated with an Intent.

Once this activity is defined along with above mentioned filters, other activities will be able to invoke this activity using either the android.intent.action.VIEW, or using the com.example.My Application.LAUNCH action provided their category is android.intent.category.DEFAULT.

You need to keep activity tag Inside Application tag & need to specify activity name to

 


 
 make your app appear in the share menu but the data you will share to it will not be saved anywhere, for that you will need additional code.

 

Useful links

An Android Intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.

The intent itself, an Intent object, is a passive data structure holding an abstract description of an operation to be performed.

https://www.tutorialspoint.com/android/android_intents_filters.htm

Android app share to other app step by step

https://code.tutsplus.com/tutorials/android-sdk-implement-a-share-intent--mobile-8433