activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_centerInParent="true"
android:textColor="@color/purple_700"
android:textSize="15sp"/>
<ImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="Receive Picture"/>
</RelativeLayout>
MainActivity.java import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
shareList();
}
private void shareList() {
Intent intent=getIntent();
String recieve=intent.getAction();
String type=intent.getType();
if (recieve.equals(Intent.ACTION_SEND))
{
if (type.startsWith("text/"))
{
String text=intent.getStringExtra(Intent.EXTRA_TEXT);
if (text!=null){
receiveText.setText(text);
picture.setVisibility(View.GONE);
}
}
else if (type.startsWith("image/")){
Uri uri=(Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM);
Uri file;
if (uri!=null){
file=uri;
receiveText.setVisibility(View.GONE);
picture.setImageURI(uri);
}
}
}else if (intent.equals(Intent.ACTION_MAIN))
{
}
}
}
Now enter the code below in the expression.This is also useful for you
- How to Create Image Slider using ViewPager in android studio
- How to create Swipeable Videos Like TikTok Using ViewPager2 in andriod studio
- how to get all audio files in android programmatically
- How to use SearchView in andriod studio
- How to check internet Connection in androd studio
- How to Create Bottom Sheet in android studio
- How to Refresh a list Using RecyclerView in Android Studio
- How to create Welcome Splash Screen with animation in android studio
- How to create menu and sub menu in android studio
- How to create a list item with RecyclerView in Android Studio
- BottomNavigationView android example
- How to create Text to Speech app in android studio
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sharelistproject">
<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/Theme.ShareListProject">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
</application>
</manifest>
Step 2.This way, you do not have to do anything else, instead of the ShareList method in MainActivity, you will have to create a new method that will be different from the shareList method.MainActivity.java package com.avdigits.sharelistproject;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView receiveText;
private ImageView picture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
appList();
}
private void appList() {
Intent intent=getIntent();
String reciece=intent.getAction();
String type=intent.getType();
if ("android.intent.action.SEND".equals(reciece)&& type !=null &&"text/plain".equals(type)){
Log.println(Log.ASSERT,"shareText",intent.getStringExtra("android.intent.extra.TEXT"));
}
} Mainfest
And the display will be slightly different from the previous oneMainfest <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.avdigits.sharelistproject">
<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/Theme.ShareListProject">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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>
</activity>
</application>
</manifest>
A screenshot is given below so that you can see how the share method will work.
This ScreenShot share image link:
Here show Receive link on TextViewHere Share ImageHere Show Receive Image on ImageVIewhope that this article will be very useful for you. Thank you...
0 Comments
Please do not enter any spam link in the comment box
Emoji