12

Google Plusに投稿する共有インテントを追加しようとしていますが、新しいShareCompat.IntentBuilder(Android サポート ライブラリ クラス) をstartActivityメソッドに渡す問題を解決できないようです。私はこの例を使い始めました。私のアプリは Android 2.2 プラットフォームを使用してコンパイルされています。アクティビティを開始して共有インテントを起動する別のサポート方法がある可能性はありますか?

IntentBuilder shareIntent = ShareCompat.IntentBuilder.from(MyActivity.this);                
shareIntent.setText(message);
shareIntent.setSubject(subject);

if (mFullFileName != null) {
    File imageFile = new File(mFullFileName);
    if (imageFile.exists()) {
        shareIntent.setStream(Uri.fromFile(imageFile));
        shareIntent.setType("image/jpeg");
    }
} else {
    shareIntent.setType("*.*");
}   
shareIntent.getIntent();
// doesn't compile only accepts Intent and not the Intentbuilder 
startActivity(shareIntent); 
4

3 に答える 3

9

おかしい、私はそれを理解しました...与えられた例は、IntentBuilderオブジェクトではなくインテントを作成すると仮定していました..オブジェクトの作成を連鎖させるためにコードを変更する必要がありました。

Intent i = ShareCompat.IntentBuilder.from(MyActivity.this)
                       .setText(message)
                       .setSubject(subject)
                       .setStream(Uri.fromFile(imageFile))
                       .setType("image/jpeg")
                       .getIntent()
                       .setPackage("com.google.android.apps.plus");
于 2012-06-08T05:12:13.937 に答える