ユーザーが自分のアプリケーションを使用してテキストを共有できるようにするAndroid用のアプリケーションを作成しようとしています。
私が持っているコードは次のとおりです。エラーを見つけるのを手伝ってください。
エミュレータで共有アプリケーションを実行して共有ボタンをクリックすると、他のアプリケーションがエミュレータにインストールされているにもかかわらず、ストックメッセージアプリケーションが直接開かれたため、logcatメッセージがありません。そのため、電話でアプリケーションをテストする必要がありました。
共有のために作成したアプリケーションコード
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
主な用途
マニフェスト宣言
<activity
android:name="com.example.app.MainActivity"
android:label="@string/title_activity_main"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
MAINACTIVITY.JAVAからのコード
Intent myintent = getIntent();
String action = myintent.getAction();
String type = myintent.getType();
if(Intent.ACTION_SEND.equals(action) && type !=null) {
if("text/plain".equals(type)) {
handleSendText(myintent);
}
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
editText.setText(sharedText);
}
}
私のアプリケーションとストックメッセージアプリケーションでIntentChooserがポップアップしない理由を見つけるのを手伝ってください。