Skip to content

Instantly share code, notes, and snippets.

@oshinko
Last active April 17, 2017 05:32
Show Gist options
  • Save oshinko/2ee288ff12a969de2103755c9b1ab952 to your computer and use it in GitHub Desktop.
Save oshinko/2ee288ff12a969de2103755c9b1ab952 to your computer and use it in GitHub Desktop.
リクエストヘッダを指定してブラウザを開く
package activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Browser;
import android.support.v7.app.AppCompatActivity;
import BuildConfig;
import R;
/**
* ブラウザを起動.
*/
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// リクエストヘッダを指定してブラウザを開く.
// タブブラウザで既に開いているなら同じタブで開く.
Uri uri = Uri.parse("http://httpbin.org/headers");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
Bundle headers = new Bundle();
headers.putString("X-Token", "mine");
intent.putExtra(Browser.EXTRA_APPLICATION_ID, BuildConfig.APPLICATION_ID);
intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, false);
intent.putExtra(Browser.EXTRA_HEADERS, headers);
startActivity(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment