androidandroid-fragmentstwitter-oauthtwitter4j

How to getIntent().getData(); on Fragment


My application uses login with twitter, the example code works using Activity but I want my app to work using Fragment like this:

  1. Click login with twitter button
  2. Go to web browser for Authorize application
  3. Back to application Feeds(use fragment) & show Toast twitter_id

How to edit error on Uri uri = getIntent().getData();

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_feed, container, false);
    
    Uri uri = getIntent().getData(); // <<<<<<<
    String verifier = uri.getQueryParameter(ConstantValues.URL_PARAMETER_TWITTER_OAUTH_VERIFIER);

       
    TwitterGet get=new TwitterGet();
    get.execute(verifier);
       
    return rootView;
}

Solution

  • Use Uri uri = getIntent().getData(); in the fragment, you just need call getActivity() first:

    Uri uri = getActivity().getIntent().getData();