Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <intent-filter>
- <action android:name="android.intent.action.SEND" />
- <category android:name="android.intent.category.DEFAULT" />
- <data android:mimeType="text/*"/>
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.SEND" />
- <category android:name="android.intent.category.DEFAULT" />
- <data android:mimeType="image/*"/>
- </intent-filter>
- //
- <?xml version="1.0" encoding="utf-8"?>
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <TextView
- android:gravity="center_horizontal"
- app:layout_constraintTop_toTopOf="parent"
- android:id="@+id/idTvAbout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/strTvAbout"/>
- <TextView
- app:layout_constraintTop_toBottomOf="@id/idTvAbout"
- android:id="@+id/idTvCapturedText"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- />
- </androidx.constraintlayout.widget.ConstraintLayout>
- //
- package com.joythis.android.pdm2textcapturer;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- Context mContext;
- TextView mTvAbout, mTvCapturedText;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- init();
- }//onCreate
- void init(){
- mContext = this;
- mTvAbout = findViewById(R.id.idTvAbout);
- mTvCapturedText = findViewById (R.id.idTvCapturedText);
- checkIfCalledByAnotherAppAndReceiveItsSharedData();
- }//init
- void checkIfCalledByAnotherAppAndReceiveItsSharedData(){
- Intent intentHowWasICalled = getIntent();
- if (intentHowWasICalled!=null){
- String strAction = intentHowWasICalled.getAction();
- boolean bIsItActionSend =
- strAction.equals(Intent.ACTION_SEND);
- //"banana".compareTo("Banana")!=0
- //"banana".compareToIgnoreCase("Banana")==0
- boolean bIsItActionSend2 =
- strAction.compareTo(Intent.ACTION_SEND)==0;
- boolean bIsItActionSend3 =
- strAction.compareToIgnoreCase(Intent.ACTION_SEND)==0;
- //is this a share situation?
- if (bIsItActionSend){
- String strType =
- intentHowWasICalled.getType();
- boolean bIsItSharedText =
- strType.startsWith("text/");
- boolean bIsItSharedImage =
- strType.startsWith("image/");
- if (bIsItSharedText){
- //TODO: we can handle text!
- //receive the shared text
- String strSharedText =
- intentHowWasICalled.getStringExtra(
- Intent.EXTRA_TEXT
- );
- //display the received text in mTvCapturedText
- mTvCapturedText.setText(strSharedText);
- }//if
- if (bIsItSharedImage){
- //TODO: how to handle image sharing?
- }
- }//if
- }//if
- }//checkIfCalledByAnotherAppAndReceiveItsSharedData
- }//MainActivity
Add Comment
Please, Sign In to add comment