Advertisement
core_st

Android basic authorization

Mar 8th, 2015
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. public void onClick(View v) {
  2. Intent in = getIntent();
  3. String filename = in.getStringExtra(KEY_FILENAME);
  4.  
  5. if(v.getId() == R.id.ButtonTestPlayPause){
  6.  
  7. try {
  8. String AUDIO_PATH = "http://91.73.25.212:8080/imap/attachments/"+filename;
  9. String username = "admin";
  10. String password = "admin";
  11. String userpassword = username + ":" + password;
  12. byte[] authEncBytes = Base64.encodeBase64(userpassword.getBytes());
  13. String authStringEnc = new String(authEncBytes);
  14.  
  15. URL url = new URL(AUDIO_PATH);
  16. URLConnection urlConnection = url.openConnection();
  17. urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
  18.  
  19. Toast.makeText(getApplicationContext(),"play", Toast.LENGTH_LONG).show();
  20. mediaPlayer.setDataSource(AUDIO_PATH);
  21. mediaPlayer.prepareAsync();
  22. } catch (MalformedURLException e) {
  23. e.printStackTrace();
  24. } catch (IOException e) {
  25. e.printStackTrace();
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement