The aim of the app is to fetch news from different wordpress websites and display in the application. While the news are displayed, the app gives you the ability to click and view each news within the app. Instead of taking you out of the app, it gives you the comfort of viewing within the app.
The Share feature was added to make the application interactive and flexible. This makes users get to share interesting crypto news to anyone they wish to instead of manually copying the link from the website (i.e going to the website which is outside the app). Of course, users would like to do this at their comfort in the app.
menu_news_webpage.xml file. This is the icon that will help a user trigger an action to share.<menu 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"
tools:context=".NewsWebPageActivity">
<item
android:id="@+id/action_share"
android:orderInCategory="100"
android:title="@string/share"
android:icon="@mipmap/share_icon"
app:showAsAction="always" />
</menu>
NewsWebPageActivity.java file, an intent is triggered to share the post with some attributes like subject and text of the post. Accompanied by a post sent, the title with url is displayed to a user before clicking to have a clue of what the post is about.@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_share) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = title + " " + url;
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
return true;
}