Last active
April 17, 2017 05:32
-
-
Save oshinko/2ee288ff12a969de2103755c9b1ab952 to your computer and use it in GitHub Desktop.
リクエストヘッダを指定してブラウザを開く
This file contains 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
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