I'm trying to set a timer on the phone (not in the app I created) using ACTION_SET_TIMER intent and I'm not sure why it's not working when I click the button it either restarts the app or crashes it. Thanks for the help!
<Button
android:id="#+id/timer_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:onClick="startTimer"
android:text="#string/timer_note"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/camera_button"
/>
public void startTimer(View view) {
String searchFor = ((EditText) findViewById(R.id.share_edittext)).getText().toString();
String strNew = searchFor.replaceFirst("You ordered a ", "");
int seconds = 10;
Intent intent = new Intent(AlarmClock.ACTION_SET_TIMER)
.putExtra(AlarmClock.EXTRA_MESSAGE, strNew)
.putExtra(AlarmClock.EXTRA_LENGTH, seconds)
.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}
After further digging I realized I needed to add a permission to the Manifest.XML file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.homework">
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
Related
This question already has answers here:
App on Google Play always shows "Update" instead of open [closed]
(6 answers)
Closed 4 years ago.
I have uploaded an update to my app on Play and as soon as I update it, it asks to update again.
The app comprises a few button on an otherwise simple WebView app, and Google Play keeps wanting to update the app.
I cannot find any errors causing this.
I would appreciate heads-up as so what could be causing this.
public class PilatesTimetable extends AppCompatActivity {
WebView rootView;
boolean installed;
ImageButton myWhatsApp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pilates_timetable);
rootView = findViewById(R.id.timetable);
rootView.loadUrl("http://www.example.com");
rootView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
WebView.setWebContentsDebuggingEnabled(false);
installed = appInstalledOrNot("com.whatsapp");
myWhatsApp = findViewById(R.id.whatsAppButton);
if (installed) {
myWhatsApp.setVisibility(View.VISIBLE);
}
if (myWhatsApp.getVisibility() == View.VISIBLE) {
myWhatsApp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String number = "+3530871234567";
String url = "https://api.whatsapp.com/send?phone=" + number;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
}
}
public void callUs(View v){
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:0871234567"));
startActivity(callIntent);
}
public void textUs(View v){
try{
Intent textIntent = new Intent(Intent.ACTION_SENDTO);
textIntent.setData((Uri.parse("smsto:0871234567")));
startActivity(textIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(PilatesTimetable.this, "You do not have a texting application installed.", Toast.LENGTH_LONG).show();
}
}
public void emailUs (View v){
try {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData((Uri.parse("mailto:user#example.com")));
startActivity(emailIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(PilatesTimetable.this, "You do not have an email application installed.", Toast.LENGTH_LONG).show();
}
}
public void bookOnline (View v){
try {
Intent bookIntent = new Intent(Intent.ACTION_VIEW);
bookIntent.setData((Uri.parse("http://www.example.com")));
startActivity(bookIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(PilatesTimetable.this, "You do not have an Internet viewing application installed.", Toast.LENGTH_LONG).show();
}
}
public boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
}
Example code from the activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="ie.myPackage.PilatesTimetable">
<WebView
android:id="#+id/timetable"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
app:layout_constraintBottom_toTopOf="#+id/linearLayout"
app:layout_constraintTop_toTopOf="parent">
</WebView>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="85dp"
android:background="#color/primaryLightColor"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageButton
android:id="#+id/whatsAppButton"
android:layout_width="0dp"
android:layout_height="85dp"
android:layout_weight="1"
android:background="#null"
android:backgroundTint="#color/primaryLightColor"
android:contentDescription="#string/whats_app_us"
android:tint="#color/white"
android:visibility="gone"
app:srcCompat="#drawable/wa_55" />
I have just finished chatting to Google and they confirmed that they have an ongoing issue with this at the moment.
So nothing to do with the app, it's their system.
Hi I'm trying to play a 432x320 .mp4 video (which I've manually converted to .mp4 H.264 format) on an Android Studio application using a Relative Layout within a frame layout. I keep getting a "Can't play this video error."
Here's what I have as an .xml file (note, I have many buttons/imagebuttons that I omitted from my post here because they're irrelevant and they take up a lot of space)...
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="com.example.kenneth.alphieii.AlphieII">
<ImageView
android:id="#+id/Robot"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="#drawable/alphie_robot1"
android:scaleType="fitCenter"/>
<TextView android:id="#+id/mytexttester"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_marginTop="19dp"
android:visibility="gone"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
...a bunch of buttons here including Yellowb0...this is not an error
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/videoView"
android:layout_width="250dp"
android:layout_height="150dp"
android:layout_above="#+id/Yellowb0"
android:layout_centerHorizontal="true"
android:visibility="visible" />
</RelativeLayout>
</FrameLayout>
I have the actual video posted here and it can be easily downloaded...
!https://streamable.com/y01zy
And I have a picture of the current interface (note the videoview size needs to be adjusted)
I've tried a number of things such as...
mVideoView.setVideoPath("android.resource://com.example.s3project/raw/" +
R.raw.alphie_vidprompt);
mVideoView.start();
and...
String uriPath = "android.resource://" +
"com.android.engineersdream.ed_video/" + R.raw.alphie_vidprompt;
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mVideoView.start();
}
});
I haven't been able to get anything to work despite trying out suggestions made to people who've had a similar problem getting a videoview video to work. Is there any other suggestion that I could be missing? Is the format of my video improper? Is there another easier method of playing videos on Android Studio? Thanks.
EDIT:
I tried copying the video .mp4 files to the SD Card as suggested and it still doesn't work. I've placed these in the Android Manifest.xml file:
android.permission.READ_EXTERNAL_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE.
Here's what I have for OnCreate...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alphie_ii);
mVideoView = (VideoView)findViewById(R.id.videoView);
push = (ImageButton) findViewById(R.id.On);
//imgButton.setOnClickListener(imgButtonHandler);
final int[] mvids = new int[] { R.raw.alphie_vidprompt, R.raw.alphie_vidcorrect };
for (int i = 0; i < mvids.length; i++) {
try {
String path = Environment.getExternalStorageDirectory() + "/Alphie";
File dir = new File(path);
if (dir.mkdirs() || dir.isDirectory()) {
String str_song_name = i + ".mp4";
CopyRAWtoSDCard(mvids[i], path + File.separator + str_song_name);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void CopyRAWtoSDCard(int id, String path) throws IOException {
InputStream in = getResources().openRawResource(id);
FileOutputStream out = new FileOutputStream(path);
byte[] buff = new byte[1024];
int read = 0;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
} finally {
in.close();
out.close();
}
}
And here's what I used to call the video...
Uri vidFile = Uri.parse(
Environment.getExternalStorageDirectory().getAbsolutePath()
+ "alphie/alphie_vidprompt");
mVideoView.setVideoURI(vidFile);
mVideoView.start();
I still get the same message "Can't play this video"
Though I still have plenty of things to learn, I still don't understand why copying a video to the SD card would be necessary. I'd hope that it would be easy enough to run it from the res/raw directory.
You give a wrong package name (com.example.s3project or com.android.engineersdream.ed_video). Your should be com.example.kenneth.alphieii or com.example.kenneth, given by your layout. But you should use package name from context, like:
getPackageName();
So in your case you should use
"android.resource://".concat(getPackageName()).concat("/raw/").concat(R.raw.alphie_vidprompt);
In the documentation for the new "Pinned Shortcuts" feature in Android O, they mention that "You can also create a specialized activity that helps users create shortcuts, complete with custom options and a confirmation button".
I tried following the documentation, but when I tried to create a new shortcut I only saw the default dialog, and not my activity.
Here's the declaration in the Manifest:
<activity android:name=".ShortcutActivity">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
</intent-filter>
</activity>
P.S
In the documentation they also shows an example in the Gmail app - how do I get to that screen? I wanted to see the flow but I couldn't find it.
You have to create a new activity as dialog, then you can add whatever options you want on that dialog and handle as you want the addShortcut method.
I tried that code to add and remove a dynamical shortcut and it worked.
AndroidManifest.xml
<activity android:name=".DialogActivity"
android:excludeFromRecents="true"
android:theme="#style/Theme.AppCompat.Dialog"
>
...
</activity>
DialogActivity.java
public class DialogActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
this.setFinishOnTouchOutside(false);
findViewById(R.id.add_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addShortcut();
}
});
findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
...
}
activity_dialog.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:id="#+id/activity_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.metax.myapplication.DialogActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you want to add shortcut?"/>
<Button
android:id="#+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_alignParentStart="true"
android:text="No thanks"/>
<Button
android:id="#+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:text="Add me"/>
</RelativeLayout>
In you Java class insert
ShortcutManager sM = c.getSystemService(ShortcutManager.class);
Intent intent2 = new Intent(c.getApplicationContext(), ShortcutActivity.class);
intent2.setAction(Intent.ACTION_VIEW);
ShortcutInfo shortcut2 = new ShortcutInfo.Builder(c,MSG_SHORCUT_CUSTOM)
.setIntent(intent2)
.setShortLabel("ShortLabel")
.setLongLabel("LongLaber")
.setDisabledMessage("DisabledMessage")
.setIcon(Icon.createWithResource(c, R.mipmap.ic_add_outline_short))
.build();
listshortcut.add(shortcut2);
Intent pinnedShortcutCallbackIntent = mShortcutManager.createShortcutResultIntent(shortcut2);
PendingIntent successCallback = PendingIntent.getBroadcast(context, 0, pinnedShortcutCallbackIntent, 0);
mShortcutManager.requestPinShortcut(pinShortcutInfo, successCallback.getIntentSender());
sM.setDynamicShortcuts(listshortcut);
To launch your shortcut activity with action as ACTION_CREATE_SHORTCUT, long tap on app icon, and press widget icon, you ll notice a 1x1 widget, on tap of which your desired activity would be launched.
Also you can explicitly fire that intent from your app as well on some desired action.
Create a new resource file: res/xml/shortcuts.xml. This is how you create shortcuts,After you have done the nessicary changes in manifest
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="compose"
android:enabled="true"
android:icon="#drawable/compose_icon"
android:shortcutShortLabel="#string/compose_shortcut_short_label1"
android:shortcutLongLabel="#string/compose_shortcut_long_label1"
android:shortcutDisabledMessage="#string/compose_disabled_message1">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="your package"
android:targetClass="com.example.myapplication.ComposeActivity" />
</shortcut>
<!-- Specify more shortcuts here. -->
</shortcuts>
In manifest add this to the activity tag,
<meta-data android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
If you want to read more refer this doc it explains about pinned shortcuts, static and dynamic shortcuts.
Here is an example from google, in their samples repo
I'm trying to add a widget into my app and I am facing a problem. Whenever I grab the widget and place it on my homescreen, it just disappears. I can only see it for about 0.5 seconds. Here is the code:
Manifest.xml
<receiver
android:label="MyApp"
android:name=".widget.MyWidgetProvider" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_info" />
</receiver>
MyWidgetProvider.java
public class MyWidgetProvider extends AppWidgetProvider {
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//IDs
for (int i=0; i<appWidgetIds.length; i++) {
int currentWidgetId = appWidgetIds[i];
// Create data
SharedPreferences prefs = context.getSharedPreferences("com.example.app_preferences", 0);
int number = prefs.getInt("progress", 0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.appwidget);
Log.w("WidgetExample", String.valueOf(number));
// Set the text
remoteViews.setTextViewText(R.id.widgettext, String.valueOf(number));
// Register an onClickListener
Intent intent = new Intent(context, MyWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.widgettext, pendingIntent);
appWidgetManager.updateAppWidget(currentWidgetId, remoteViews);
Toast.makeText(context, "widget added", Toast.LENGTH_SHORT).show();
}
}
}
appwidget.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widgetlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/widgetimage" >
<TextView
android:id="#+id/widgettext"
style="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
widget_info.xml
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:updatePeriodMillis="86400000"
android:minWidth="120dp"
android:minHeight="50dp"
android:initialLayout="#layout/appwidget"
android:previewImage="#drawable/widgetimage"
android:configure="com.example.app.widget.MyWidgetProvider" >
</appwidget-provider>
you can see the last line of the java file contains a toast. This toast actually gets called and there are no errors whatsoever in the logcat.
Thanks!
You're android:configure element must refer to an activity that will allow configuration of your widget. This activity must set result to RESULT_OK, otherwise configuration is cancelled and widget is removed.
I suppose referring to your widget provider, not an activity, has the same effect of returning RESULT_CANCEL from the configuration activity.
If you don't have a configuration activity, simply remove this entry and the widget will be added without trying to open such.
Another possibility other than 3c71's answer is that you might have forgotten to use the two-parameter version of setResult(int resultCode, Intent data). The data parameter has to include an EXTRA which identifies the widget ID.
Intent intent = new Intent();
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, intent);
sendBroadcast(intent);
The widget ID is provided to the configuration activity as an EXTRA in the Intent that is supplied to the activity when it is called. Retrieve it and store it like this:
mAppWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
i want to add "Share" button to my android app.
Like that
I added "Share" button, but button is not active. I click, but nothing happens.
My code in MainActivity.java:
private ShareActionProvider mShareActionProvider;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.share_menu, menu);
getMenuInflater().inflate(R.menu.main, menu);
MenuItem item = menu.findItem(R.id.share_menu);
mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share_menu).getActionProvider();
mShareActionProvider.setShareIntent(getDefaultShareIntent());
return true;
}
{
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(sharingIntent, "Share using"));
}
I want to share text in my first tab (first_tab.xml) or second tab (second_tab.xml).
Code in tab (xml) (If need):
<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"
android:background="#color/background_color"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity$DummySectionFragment" >
<TextView
android:id="#+id/section_label1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/text"
android:textColor="#color/text_color" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/sprite" />
Add a Button and on click of the Button add this code:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "Here is the share content body";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
Useful links:
For basic sharing
For customization
Create a button with an id share and add the following code snippet.
share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "Your body here";
String shareSub = "Your subject here";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSub);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share using"));
}
});
The above code snippet will open the share chooser on share button click action.
However, note...The share code snippet might not output very good results using emulator. For actual results, run the code snippet on android device to get the real results.
in kotlin :
val sharingIntent = Intent(android.content.Intent.ACTION_SEND)
sharingIntent.type = "text/plain"
val shareBody = "Application Link : https://play.google.com/store/apps/details?id=${App.context.getPackageName()}"
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "App link")
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody)
startActivity(Intent.createChooser(sharingIntent, "Share App Link Via :"))
Share Any File as below ( Kotlin ) :
first create a folder named xml in the res folder and create a new XML Resource File named provider_paths.xml and put the below code inside it :
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="files"
path="."/>
<external-path
name="external_files"
path="."/>
</paths>
now go to the manifests folder and open the AndroidManifest.xml and then put the below code inside the <application> tag :
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" /> // provider_paths.xml file path in this example
</provider>
now you put the below code in the setOnLongClickListener :
share_btn.setOnClickListener {
try {
val file = File("pathOfFile")
if(file.exists()) {
val uri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file)
val intent = Intent(Intent.ACTION_SEND)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.setType("*/*")
intent.putExtra(Intent.EXTRA_STREAM, uri)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent)
}
} catch (e: java.lang.Exception) {
e.printStackTrace()
toast("Error")
}
}
Kotlin
Inside the click listener needed to add this module for sharing text via applications like whatsApp, email, Slack..
shareOptionClicked.setOnClickListener{
val shareData = Intent(Intent.ACTION_SEND)
shareData.type = "text/plain"
val dataToShare = "Text from my application"
shareData.putExtra(Intent.EXTRA_SUBJECT, "Subject from my application")
shareData.putExtra(Intent.EXTRA_TEXT, dataToShare)
startActivity(Intent.createChooser(shareData, "Share Via"))
}