Created
June 3, 2013 21:31
-
-
Save virifi/5701606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * AndroidManifest.xmlに | |
| * <uses-permission android:name="com.twitter.android.permission.AUTH_APP" /> | |
| * を追加する必要がある | |
| */ | |
| public class MainActivity extends Activity { | |
| private static final String TAG = MainActivity.class.getSimpleName(); | |
| private static final int AUTH_REQUEST_CODE = 1; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| final Button authButton = (Button) findViewById(R.id.auth_button); | |
| authButton.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| try { | |
| Intent intent = new Intent(); | |
| intent.setClassName("com.twitter.android", "com.twitter.android.AuthorizeAppActivity"); | |
| intent.putExtra("ck", "Consumer Key"); | |
| intent.putExtra("cs", "Consumer Secret"); | |
| startActivityForResult(intent, AUTH_REQUEST_CODE); | |
| } catch (ActivityNotFoundException e) { | |
| Toast.makeText(getApplicationContext(), "Auth activity not found", Toast.LENGTH_SHORT).show(); | |
| } | |
| } | |
| }); | |
| } | |
| @Override | |
| protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| super.onActivityResult(requestCode, resultCode, data); | |
| if (requestCode != AUTH_REQUEST_CODE) | |
| return; | |
| if (data == null) { | |
| Toast.makeText(getApplicationContext(), "Authentication failed", Toast.LENGTH_SHORT).show(); | |
| return; | |
| } | |
| final Bundle extra = data.getExtras(); | |
| for (String key : extra.keySet()) { | |
| Log.d(TAG, key + " = " + extra.get(key).toString()); | |
| } | |
| } | |
| @Override | |
| public boolean onCreateOptionsMenu(Menu menu) { | |
| // Inflate the menu; this adds items to the action bar if it is present. | |
| getMenuInflater().inflate(R.menu.main, menu); | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment