It's a example to share plain text using ShareActionProvider.
With share history:
Create /menu/menu.xml to define our ActionBar, with Share action only.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_item_share"
android:showAsAction="ifRoom"
android:title="Share"
android:actionProviderClass="android.widget.ShareActionProvider" />
</menu>
Main Java code:
package com.exercise.AndroidShareActionProvider;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ShareActionProvider;
public class AndroidShareActionProviderActivity extends Activity {
private ShareActionProvider myShareActionProvider;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
myShareActionProvider = (ShareActionProvider)item.getActionProvider();
myShareActionProvider.setShareHistoryFileName(
ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
myShareActionProvider.setShareIntent(createShareIntent());
return true;
}
private Intent createShareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT,
"http://android-er.blogspot.com/");
return shareIntent;
}
}
Download the files.
Is there a way to disable share history and remove the frequently used share app icon on the right?
ReplyDeletehow to delete the share history i only want the plain text ShareActionProvider
ReplyDeleteDo you have a sample using the support library?
ReplyDeletehow to share current text on that screen
ReplyDelete