I am trying to send a link from a fragment to the same application via Intent.ACTION_SEND. When the share intent is sent, the list of applications have my application which on click takes me to an activity within my app, where i am trying to receive data via intent but the bundle is empty.
SENDING DATA AS PATH
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
final ArrayList<Intent> shareIntents;
try {
shareIntents = getExternalShareIntents(context, shareIntent);
Intent chooserIntent = Intent.createChooser(shareIntent, "Share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, shareIntents.toArray(new
Parcelable[]{}));
chooserIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
chooserIntent.putExtra(chooserIntent.getStringExtra(Intent.EXTRA_TEXT), path);
context.startActivity(chooserIntent);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
RECEIVING INTENT IN ACTIVITY
bundle = getIntent().getExtras();
Intent intent0 = getIntent();
String action = intent0.getAction();
String type = intent0.getType();
if (intent0 != null) {
//if (action.equals(Intent.ACTION_SEND)) D
imageUri = intent0.getStringExtra(Intent.EXTRA_TEXT);
Toast.makeText(NewHomeScreenActivty.this, "onResume " + imageUri,
Toast.LENGTH_SHORT).show();
// }
}
RECEIVING ACTIVITY IN MANIFEST
<activity
android:name=".app.activity.NewHomeScreenActivty"
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true"
android:label=""
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/CustomActionBar"
android:uiOptions="splitActionBarWhenNarrow"
android:windowSoftInputMode="adjustPan">
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
I am unable to receive any data passed via intent.
Instead of using this in the sending data class:
Use the following: