我有一个laravel应用程序。现在我需要将它转移到android。我的第一个任务是实施奖励视频。问题是,在触发onRewarded
方法后,我需要向服务器发送一个请求,根据我的标准添加奖励。因为在Java我是新的,我遇到了一个问题。我意识到webview
和HttpURLConnection
有不同的会话。到目前为止,我得出结论,通过cookie翻译auth :: user () -> id
是值得的,我设置会话,然后从前面的会话我创建cookie,从我发送到webview
。下一个问题是我需要将这些cookie转移到另一个活动。我找到了Intent类,通过它我通过了putExtra ("ACCESS_TOKEN", CookieValue);
。问题是,我怎样才能进入第二项活动。如果我完全错误地做到这一点,我会对任何提示感到满意
private class apiPostCoins extends AsyncTask<Void,Void,Void>
{
@Override
protected Void doInBackground(Void... params)
{
try {
//This is what i want to reach
String cookieValue = data.getStringExtra("ACCESS_TOKEN");
//
URL url = new URL("http://localhost/redirect_get_coins/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
你可以这样做。
FirstActivity
Intent intent = new Intent(this,SecondActivity.class);
intent.putExtra ("ACCESS_TOKEN", CookieValue);
startActivity(intent);
SecondActivity
Intent intent = getIntent();
String access_token = intent.getStringExtra("ACCESS_TOKEN");