Can I override autotimeout on Android?

I use Twitter4J to post on Twitter, but you need to open a browser and receive a message from Twitter for my application in order to be able to do this, and it works, but when I return to my application, the activity time is closed. Is there any way to open my activity? Web browsing does not work, since Twitter does not allow you to allow using the usual path.

public void TwitterSend () {
    // The factory instance is re-useable and thread safe.
    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(consumer_token, consumer_secret);

    //WebView webview = (WebView) findViewById(R.id.webview);
    //webview.setVisibility(View.VISIBLE);
    //ScrollView sc = (ScrollView) findViewById(R.id.scrollView1);
    //sc.setVisibility(View.VISIBLE);
    EditText edit = (EditText) findViewById(R.id.editText1);
    edit.setVisibility(View.VISIBLE);
    RequestToken requestToken = null;
    try {
        requestToken = twitter.getOAuthRequestToken();
        System.out.println(requestToken.toString());
    } catch (TwitterException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    AccessToken accessToken = null;

    //webview.loadUrl("https://api.twitter.com/oauth/authorize");
    Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(requestToken.getAuthorizationURL()));
    browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(browserIntent);


      System.out.println("Open the following URL and grant access to your account:");

      System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
      String pin = edit.getText().toString();
    CountDownTimer timer = new CountDownTimer(900000, 1000) {

        public void onTick(long millisUntilFinished) {
        }


        public void onFinish() {

        }
     };
     timer.start();
      while(pin.length()<7)
      {
          pin = edit.getText().toString();
      }
      System.out.print(pin);
      try{
         if(pin.length() > 0){
           accessToken = twitter.getOAuthAccessToken(requestToken, pin);
         }else{
           accessToken = twitter.getOAuthAccessToken();
         }
      } catch (TwitterException te) {
        if(401 == te.getStatusCode()){
          System.out.println("Unable to get the access token.");
            edit.setVisibility(View.GONE);
        }else{
          te.printStackTrace();
        }
      }

    //persist to the accessToken for future reference.
    Status status = null;
    try {

        SharedPreferences stats = getSharedPreferences(PREFS_NAME, 0);
        String quote = stats.getString("shareQuote", "An error has occured. We are Sorry.");
        status = twitter.updateStatus(quote);
    } catch (TwitterException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        //webview.setVisibility(View.GONE);
        //edit.setVisibility(View.GONE);
    }
     Toast.makeText(getApplicationContext(), "Successfully updated the status to [" + status.getText() + "].", Toast.LENGTH_LONG).show();
    System.out.println("Successfully updated the status to [" + status.getText() + "].");
   // webview.setVisibility(View.GONE);
    edit.setVisibility(View.GONE);
    //sc.setVisibility(View.GONE);
    /*WebView webview = (WebView) findViewById(R.id.webview);
    webview.setVisibility(View.VISIBLE);
    Twitter twitter=new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(consumer_token, consumer_secret);
    AccessToken a = new AccessToken(oauth_token, oauth_token_secret);
    twitter.setOAuthAccessToken(a);
    try {
        RequestToken requestToken = twitter.getOAuthRequestToken("https://api.twitter.com/oauth/request_token");
        webview.loadUrl("https://api.twitter.com/oauth/authorize");
    } catch (TwitterException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }*/

}
+3
source share

All Articles