2016-04-05 4 views
0

FacebookのアプリコンテンツをRecyclerViewのonClickメソッドで共有しようとしています。 Recyclerviewはうまく動作し、onclickメソッドの前にデータを正しく表示します。FacebookのコンテンツをFacebookのRecyclerViewで共有する

すべての依存関係や他のものがgradleファイルなどで行われています...私が直面している問題は、ユーザーが共有ボタンをクリックすると、新しいインテントが生成され、関連するパラメータを渡していますが、何らかのアクションを実行します。

は以下のFacebook(HomeActivity)を開くためのコードのonCreate()メソッドです:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    FacebookSdk.sdkInitialize(getApplicationContext()); 
    setContentView(R.layout.home); 
    if (savedInstanceState == null) { 
     Bundle extras = getIntent().getExtras(); 
     if(extras == null) { 
      imageURL= null; 
      position=0; 
     } else { 
      imageURL= extras.getString("imageURL"); 
      //position = extras.getInt("position"); 
     } 
    } else { 
     imageURL= (String) savedInstanceState.getSerializable("imageURL"); 
     //position= (int) savedInstanceState.getSerializable("position"); 

    } 
    callbackManager = CallbackManager.Factory.create(); 

// loginDataBaseAdapter = new LoginDataBaseAdapter(this); 
// loginDataBaseAdapter = loginDataBaseAdapter.open(); 

    facebookLogin = (LoginButton) findViewById(R.id.login_button); 
    facebookLogin.registerCallback(callbackManager, callback); 
} 

そして、これは私がコールバックメソッドの間にやって何、それが正常にログインしているが、その後クラッシュします。

public FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() { 

    @Override 
    public void onSuccess(LoginResult loginResult) { 
     // Toast.makeText(getApplicationContext(),"On facebook",Toast.LENGTH_LONG).show(); 
     AccessToken accessToken = loginResult.getAccessToken(); 
     ShareLinkContent content = new ShareLinkContent.Builder() 
       .setContentUrl(Uri.parse(imageURL)) 
       .build(); 
     ShareDialog.show(HomeActivity.this, content); 

    } 

    @Override 
    public void onCancel() { 

    } 

    @Override 
    public void onError(FacebookException error) { 
     Profile profile = Profile.getCurrentProfile(); 
     textView.setText("Connection Lost ! Pleasr Try Again :" + profile.getName()); 

    } 
}; 

そして、これのonClick()メソッドが書かれている方法です。

@Override 
    public void onClick(View v) { 


     Intent intent = new Intent(context.getApplicationContext(),HomeActivity.class); 
     intent.putExtra("position",getAdapterPosition()); 
     intent.putExtra("imageURL",uri); 
     context.startActivity(intent); 
    } 

誰かがこのを通して私を導くことができます。私は、ソーシャルアプリでアプリを作ったり、コンテンツを共有したりする経験はあまりありません。どんな助けも高く評価されます。

答えて

1

あなたは直接Facebookアプリ上で共有しよう、すなわち

try { 
       Intent intent1 = new Intent(); 
       intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler"); 
       intent1.setAction(Intent.ACTION_SEND); 
       intent1.setType("text/plain"); 
       intent1.putExtra(Intent.EXTRA_TEXT, "any text"); 
       startActivity(intent1); 
      } catch (Exception e) { 
       Intent intent = new Intent(Intent.ACTION_SEND); 
       String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + "any constant"; 
       intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl)); 
       intent.putExtra(Intent.EXTRA_TEXT, "any text"); 
       startActivity(intent); 
      } 

を使用してログインfacebookで共有することができます。アプリがデバイスにインストールされていない場合、共有はブラウザ上で開きます

+0

これは機能しません。画像のURLを開くだけです。ここで何をしようとしているのは、 Facebook wall – Umair

+0

アプリは電話にインストールされ、正常にログインしますが、このコードでは画像のURLを開くだけです... – Umair

関連する問題