[解決済み] アンドロイドのアプリで「共有」ボタンを有効にするには?
2022-05-18 06:32:51
質問
アンドロイドアプリに「共有」ボタンを追加したいのですが、どうすればいいですか?
このように
Share"ボタンを追加しましたが、ボタンがアクティブではありません。クリックしても、何も起こりません。
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"));
}
1つ目のタブ(first_tab.xml)または2つ目のタブ(second_tab.xml)でテキストを共有したいです。
タブ(xml)内のコード(必要な場合)。
<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" />
どのように解決するのですか?
を追加します。
Button
を追加し、クリックすると
Button
をクリックすると、このコードが追加されます。
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"));
便利なリンク集です。
関連
-
配列定数は初期化子でのみ使用可能です。
-
IDEAError:javaの依存性エラー。Annotation processing is not supported for module cycles...(アノテーション処理はモジュールサイクルではサポートされていません。
-
Zipファイルの圧縮・解凍にantを使用する
-
[解決済み] android.os.NetworkOnMainThreadException' を修正するにはどうすればよいですか?
-
[解決済み] JavaでInputStreamを読み込んでStringに変換するにはどうすればよいですか?
-
[解決済み] Androidのソフトキーボードをプログラムで閉じる/隠すにはどうすればよいですか?
-
[解決済み] Androidでアクティビティ起動時にEditTextにフォーカスが当たらないようにする方法
-
[解決済み] リンクのように動作するHTMLボタンを作成する方法
-
[解決済み] Androidの「コンテキスト」とは何ですか?
-
[解決済み】Android UserManager.isUserAGoat()の正しい使用例?)
最新
-
nginxです。[emerg] 0.0.0.0:80 への bind() に失敗しました (98: アドレスは既に使用中です)
-
htmlページでギリシャ文字を使うには
-
ピュアhtml+cssでの要素読み込み効果
-
純粋なhtml + cssで五輪を実現するサンプルコード
-
ナビゲーションバー・ドロップダウンメニューのHTML+CSSサンプルコード
-
タイピング効果を実現するピュアhtml+css
-
htmlの選択ボックスのプレースホルダー作成に関する質問
-
html css3 伸縮しない 画像表示効果
-
トップナビゲーションバーメニュー作成用HTML+CSS
-
html+css 実装 サイバーパンク風ボタン
おすすめ
-
XMLファイル操作時のjava.util.NoSuchElementExceptionを解決する方法。
-
型に解決できない エラー解決
-
Javaクラスが "Error occurred during initialization of boot layer "というエラーで実行される。
-
Git Pull Failed マージされていないファイルがあるため、Pull できません。
-
スレッド "main" での例外 java.lang.ArrayIndexOutOfBoundsException:5 エラー
-
ajax コミット リソースの読み込みに失敗しました: サーバーはステータス 400 で応答しました ()
-
強制型変換について
-
シェルコマンドやスクリプトのJavaコール
-
java.sql.SQLException: 結果セットの開始前
-
Java基礎編 - オブジェクト指向