Make android studio get data from web and add to url










0














I own a live tv app on android, but it was only made to play normal streams. However, my streams have token authentication in order to play so the stream must get the token from my server and add it to the end of the url then play. How can I do this on android studio? I basically am trying to get the app to get the token from my webpage where it is generated and add it to the end of the stream url then play.



I would appreciate it if someone could point me in the right direction. Thanks in advance.










share|improve this question





















  • Use a httpclient and get/post to the appropriate URL on your site to obtain token, then pass off to stream viewing URL. I used com.android.volley - developer.android.com/training/volley Note that it is an asynchronous thing, so you'll need to develop some sort of block-and-wait-for-return which I did with java.util.concurrent.CountDownLatch
    – ivanivan
    Nov 13 '18 at 0:13















0














I own a live tv app on android, but it was only made to play normal streams. However, my streams have token authentication in order to play so the stream must get the token from my server and add it to the end of the url then play. How can I do this on android studio? I basically am trying to get the app to get the token from my webpage where it is generated and add it to the end of the stream url then play.



I would appreciate it if someone could point me in the right direction. Thanks in advance.










share|improve this question





















  • Use a httpclient and get/post to the appropriate URL on your site to obtain token, then pass off to stream viewing URL. I used com.android.volley - developer.android.com/training/volley Note that it is an asynchronous thing, so you'll need to develop some sort of block-and-wait-for-return which I did with java.util.concurrent.CountDownLatch
    – ivanivan
    Nov 13 '18 at 0:13













0












0








0







I own a live tv app on android, but it was only made to play normal streams. However, my streams have token authentication in order to play so the stream must get the token from my server and add it to the end of the url then play. How can I do this on android studio? I basically am trying to get the app to get the token from my webpage where it is generated and add it to the end of the stream url then play.



I would appreciate it if someone could point me in the right direction. Thanks in advance.










share|improve this question













I own a live tv app on android, but it was only made to play normal streams. However, my streams have token authentication in order to play so the stream must get the token from my server and add it to the end of the url then play. How can I do this on android studio? I basically am trying to get the app to get the token from my webpage where it is generated and add it to the end of the stream url then play.



I would appreciate it if someone could point me in the right direction. Thanks in advance.







php android-studio access-token






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 23:27









Mohammed Salaam

111




111











  • Use a httpclient and get/post to the appropriate URL on your site to obtain token, then pass off to stream viewing URL. I used com.android.volley - developer.android.com/training/volley Note that it is an asynchronous thing, so you'll need to develop some sort of block-and-wait-for-return which I did with java.util.concurrent.CountDownLatch
    – ivanivan
    Nov 13 '18 at 0:13
















  • Use a httpclient and get/post to the appropriate URL on your site to obtain token, then pass off to stream viewing URL. I used com.android.volley - developer.android.com/training/volley Note that it is an asynchronous thing, so you'll need to develop some sort of block-and-wait-for-return which I did with java.util.concurrent.CountDownLatch
    – ivanivan
    Nov 13 '18 at 0:13















Use a httpclient and get/post to the appropriate URL on your site to obtain token, then pass off to stream viewing URL. I used com.android.volley - developer.android.com/training/volley Note that it is an asynchronous thing, so you'll need to develop some sort of block-and-wait-for-return which I did with java.util.concurrent.CountDownLatch
– ivanivan
Nov 13 '18 at 0:13




Use a httpclient and get/post to the appropriate URL on your site to obtain token, then pass off to stream viewing URL. I used com.android.volley - developer.android.com/training/volley Note that it is an asynchronous thing, so you'll need to develop some sort of block-and-wait-for-return which I did with java.util.concurrent.CountDownLatch
– ivanivan
Nov 13 '18 at 0:13












1 Answer
1






active

oldest

votes


















0














To do that you need to provide your access-token from a wen service, thene add the token to the end of the url, thene usethe new URL.



here an eample of a code (PHP) that generates a random access token thene provide it in the address " path-to-script/gettoken.php "



<?php
// the content of gettoken.php

// a funtion to generate random strings : they will serve as your tokens
function generateRandomString($length = 10)
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++)
$randomString .= $characters[rand(0, $charactersLength - 1)];

return $randomString;


// thene we will send the tokenwhee we recieve a GETrequestin the url of the script.
echo generateRandomString(10)
?>


In the Java Code you will get the token by the following lines of code :



// a function to send a get request 
public String sendGetRequest(String requestURL)
StringBuilder sb = new StringBuilder();
try
URL url = new URL(requestURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));

String s;
while ((s = bufferedReader.readLine()) != null)
sb.append(s + "n");

catch (Exception e)

return sb.toString();


// gettig a token
String URL = "The url of the php script" // replace itwithe correct URL
String token=sendGetRequest(URL)


By this you will be able to retrieve the token in your android app thene useitin the code.






share|improve this answer




















  • Thanks for the help. I want this to work when I press a button so where would I put this code?
    – Mohammed Salaam
    Nov 13 '18 at 7:39










  • put the php script n your server , and the sendGetRequest(URL) call in the button code
    – Khelifi Aymen
    Nov 13 '18 at 16:38










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271589%2fmake-android-studio-get-data-from-web-and-add-to-url%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














To do that you need to provide your access-token from a wen service, thene add the token to the end of the url, thene usethe new URL.



here an eample of a code (PHP) that generates a random access token thene provide it in the address " path-to-script/gettoken.php "



<?php
// the content of gettoken.php

// a funtion to generate random strings : they will serve as your tokens
function generateRandomString($length = 10)
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++)
$randomString .= $characters[rand(0, $charactersLength - 1)];

return $randomString;


// thene we will send the tokenwhee we recieve a GETrequestin the url of the script.
echo generateRandomString(10)
?>


In the Java Code you will get the token by the following lines of code :



// a function to send a get request 
public String sendGetRequest(String requestURL)
StringBuilder sb = new StringBuilder();
try
URL url = new URL(requestURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));

String s;
while ((s = bufferedReader.readLine()) != null)
sb.append(s + "n");

catch (Exception e)

return sb.toString();


// gettig a token
String URL = "The url of the php script" // replace itwithe correct URL
String token=sendGetRequest(URL)


By this you will be able to retrieve the token in your android app thene useitin the code.






share|improve this answer




















  • Thanks for the help. I want this to work when I press a button so where would I put this code?
    – Mohammed Salaam
    Nov 13 '18 at 7:39










  • put the php script n your server , and the sendGetRequest(URL) call in the button code
    – Khelifi Aymen
    Nov 13 '18 at 16:38















0














To do that you need to provide your access-token from a wen service, thene add the token to the end of the url, thene usethe new URL.



here an eample of a code (PHP) that generates a random access token thene provide it in the address " path-to-script/gettoken.php "



<?php
// the content of gettoken.php

// a funtion to generate random strings : they will serve as your tokens
function generateRandomString($length = 10)
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++)
$randomString .= $characters[rand(0, $charactersLength - 1)];

return $randomString;


// thene we will send the tokenwhee we recieve a GETrequestin the url of the script.
echo generateRandomString(10)
?>


In the Java Code you will get the token by the following lines of code :



// a function to send a get request 
public String sendGetRequest(String requestURL)
StringBuilder sb = new StringBuilder();
try
URL url = new URL(requestURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));

String s;
while ((s = bufferedReader.readLine()) != null)
sb.append(s + "n");

catch (Exception e)

return sb.toString();


// gettig a token
String URL = "The url of the php script" // replace itwithe correct URL
String token=sendGetRequest(URL)


By this you will be able to retrieve the token in your android app thene useitin the code.






share|improve this answer




















  • Thanks for the help. I want this to work when I press a button so where would I put this code?
    – Mohammed Salaam
    Nov 13 '18 at 7:39










  • put the php script n your server , and the sendGetRequest(URL) call in the button code
    – Khelifi Aymen
    Nov 13 '18 at 16:38













0












0








0






To do that you need to provide your access-token from a wen service, thene add the token to the end of the url, thene usethe new URL.



here an eample of a code (PHP) that generates a random access token thene provide it in the address " path-to-script/gettoken.php "



<?php
// the content of gettoken.php

// a funtion to generate random strings : they will serve as your tokens
function generateRandomString($length = 10)
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++)
$randomString .= $characters[rand(0, $charactersLength - 1)];

return $randomString;


// thene we will send the tokenwhee we recieve a GETrequestin the url of the script.
echo generateRandomString(10)
?>


In the Java Code you will get the token by the following lines of code :



// a function to send a get request 
public String sendGetRequest(String requestURL)
StringBuilder sb = new StringBuilder();
try
URL url = new URL(requestURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));

String s;
while ((s = bufferedReader.readLine()) != null)
sb.append(s + "n");

catch (Exception e)

return sb.toString();


// gettig a token
String URL = "The url of the php script" // replace itwithe correct URL
String token=sendGetRequest(URL)


By this you will be able to retrieve the token in your android app thene useitin the code.






share|improve this answer












To do that you need to provide your access-token from a wen service, thene add the token to the end of the url, thene usethe new URL.



here an eample of a code (PHP) that generates a random access token thene provide it in the address " path-to-script/gettoken.php "



<?php
// the content of gettoken.php

// a funtion to generate random strings : they will serve as your tokens
function generateRandomString($length = 10)
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++)
$randomString .= $characters[rand(0, $charactersLength - 1)];

return $randomString;


// thene we will send the tokenwhee we recieve a GETrequestin the url of the script.
echo generateRandomString(10)
?>


In the Java Code you will get the token by the following lines of code :



// a function to send a get request 
public String sendGetRequest(String requestURL)
StringBuilder sb = new StringBuilder();
try
URL url = new URL(requestURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));

String s;
while ((s = bufferedReader.readLine()) != null)
sb.append(s + "n");

catch (Exception e)

return sb.toString();


// gettig a token
String URL = "The url of the php script" // replace itwithe correct URL
String token=sendGetRequest(URL)


By this you will be able to retrieve the token in your android app thene useitin the code.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 0:18









Khelifi Aymen

496




496











  • Thanks for the help. I want this to work when I press a button so where would I put this code?
    – Mohammed Salaam
    Nov 13 '18 at 7:39










  • put the php script n your server , and the sendGetRequest(URL) call in the button code
    – Khelifi Aymen
    Nov 13 '18 at 16:38
















  • Thanks for the help. I want this to work when I press a button so where would I put this code?
    – Mohammed Salaam
    Nov 13 '18 at 7:39










  • put the php script n your server , and the sendGetRequest(URL) call in the button code
    – Khelifi Aymen
    Nov 13 '18 at 16:38















Thanks for the help. I want this to work when I press a button so where would I put this code?
– Mohammed Salaam
Nov 13 '18 at 7:39




Thanks for the help. I want this to work when I press a button so where would I put this code?
– Mohammed Salaam
Nov 13 '18 at 7:39












put the php script n your server , and the sendGetRequest(URL) call in the button code
– Khelifi Aymen
Nov 13 '18 at 16:38




put the php script n your server , and the sendGetRequest(URL) call in the button code
– Khelifi Aymen
Nov 13 '18 at 16:38

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271589%2fmake-android-studio-get-data-from-web-and-add-to-url%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線