0

ユーザーが自分のアプリケーションを使用してテキストを共有できるようにする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がポップアップしない理由を見つけるのを手伝ってください。

4

1 に答える 1

0

Try to run it in emulator and use debugger to find where your app is crashed then write it here try use catching exceptions

于 2012-12-09T09:54:19.600 に答える