aarinfantasy's YAOI Collection

Results 1 to 7 of 7
  1. #1
    tina21
    Guest

    Need help with Java for app development

    I'm trying to make an app for a class project and the prof is no real help and we've only just started learning Java in another class so any help from anyone that knows Java would be awesome =D

    Just a heads up I know very little when it comes to Java, like simple starter stuff. Writing some classes and methods and see if they work, hardly 20-30 lines of code, so that's your warning for running away xDDD

    What I want to build is an app that will list the books I have stored in an emulator's storage (I'm coding in Android Studio and the emulator is a Nexus 9 tablet). I've put some files in the emulator's storage which is located in Settings->Storage->Explore->Downloads.

    So the main screen of the app has a floating button that when you click on it, the app on the background (not visible to the user) will access the aforementioned folder in the storage, filter the file types and display the books it found there (cover, title and author).

    I can post the MainActivity as it is now or the part of the code on the MainActivity that I've put in (after much google searching) that supposedly does what I mentioned I want but I haven't managed to make it work 'cos like I said complete novice here walking blind.

    So yeah... anyone experienced/knowledgeable or something that can help?

  2. #2
    Yaoi Veteran
    Join Date
    Jun 2009
    Location
    Smile ! Life is **** anyway
    Posts
    1,368
    Points
    1,113,051
    Savings
    382,000


    Rei (L3)Shinji (L4)Kaworu (L4)
    Aki (L7)Akihito (L4)Sono (L3)
    Reinhard (L10)Saralegui (L3)Shinobu (L6)
    Tough one. If it was python... I suggest you go to stackoverflow

    https://stackoverflow.com/

  3. #3
    tina21
    Guest
    @libertypo

    I had made a thread but no one seemed to answer so I deleted it

  4. #4
    Yaoi Devotee

    Join Date
    Nov 2010
    Location
    Under a Rock.
    Posts
    966
    Points
    49,141,561
    Savings
    120,000,000


    DS_005_leftFuji (L6)DS_005_right
    Mikoshiba Mikoto (L6)Mikoshiba Mikoto (L6)Mikoshiba Mikoto (L6)
    Aomine (L13)MabelMikoshiba Mikoto (L6)

    Stackoverflow is a great place for Java questions too, not just python.
    As for the problem, it's hard to tell what the exact problem is without more detail.

    Is it not working because the button isn't working? Or is it something else? Are you using Reader? Scanner? or Stream?

    Did you import all the relevant Classes?

    Is it just not displaying?

    What part isn't working?

    EDIT re:Stackoverflow thread:
    Were you specific about your problem there? Generally, you need to be extremely specific about the issue for someone to answer. Also, don't be afraid to put a bit of your code out there. It'll make it easier for someone to spot the problem.
    Last edited by peilicanhelican; 04-16-2017 at 04:22 AM.

  5. #5
    tina21
    Guest
    @peilicanhelican
    Everything that needs to be imported is imported, frankly Android Studio is great like that and I have mastered the Alt+Enter when it comes to importing xDD

    I don't know how to code the whole accessing the external storage's downloads folder so for now what the button does is taking you here: Imgur: The most awesome images on the Internet

    which isn't what I want and I'm pretty sure except of this part of the code that does what is shown on the pic:
    Code:
    btn = (FloatingActionButton) findViewById(R.id.addButton);         btn.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);                 Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/external_sd/Downloads/");                 intent.setDataAndType(uri, "*/*");                 startActivity(Intent.createChooser(intent, "Open folder"));
    the rest of it doesn't work:
    Code:
    root = new File(Environment.getExternalStorageDirectory().getAbsolutePath());         //getfile(root);          for (int i = 0; i < fileList.size(); i++) {             TextView textView = new TextView(this);             textView.setText(fileList.get(i).getName());             textView.setPadding(5, 5, 5, 5);              System.out.println(fileList.get(i).getName());              if (fileList.get(i).isDirectory()) {                 textView.setTextColor(Color.parseColor("#FF0000"));             }             view.addView(textView);         }          btn = (FloatingActionButton) findViewById(R.id.addButton);         btn.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);                 Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/external_sd/Downloads");                 intent.setDataAndType(uri, "*/*");                 startActivity(Intent.createChooser(intent, "Open folder"));                  //Intent intent = new Intent(Intent.ACTION_GET_CONTENT);                 //Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/external_sd/Downloads");                 //intent.setDataAndType(uri, "*/*");                 //startActivity(Intent.createChooser(intent, "Open folder"));             }         });     }       public ArrayList<File> getfile(File dir) {         File listFile[] = dir.listFiles();         if (listFile != null && listFile.length > 0) {             for (int i = 0; i < listFile.length; i++) {                  if (listFile[i].isDirectory()) {                     fileList.add(listFile[i]);                     getfile(listFile[i]);                  }                 else {                     if (listFile[i].getName().endsWith(".mobi")                             || listFile[i].getName().endsWith(".epub")) {                         fileList.add(listFile[i]);                     }                 }              }         }         return fileList;     }       @Override     protected void onActivityResult(int requestCode, int resultCode, Intent data) {         super.onActivityResult(requestCode, resultCode, data);         if(resultCode==PICKFILE_RESULT_CODE){             Log.d("TAG", "File Uri " +data.getData());         }     }
    This is only the part of the code that is relevant to what I want to do, but I'll post the whole MainActivity if that might help. Also actually I just realized that since mobi and epub aren't recognizable files to the emulator maybe I should change the filtering to pdfs or something

  6. #6
    Yaoi Addict

    Join Date
    Jul 2006
    Location
    Canada
    Posts
    401
    Points
    15,047,811
    Savings
    9,137,198


    Spacer 1Ike (L1)Spacer 1
    Spacer 1Spacer 1Spacer 1
    Guts (L1)Layton (L5)Luke (L5)
    @tina21
    I haven't done a lot of Java but I'll try to help figure out the issue. For this line:

    Uri uri = Uri.parse(Environment.getExternalStorageDirectory( ).getPath() + "/external_sd/Downloads/");

    Check to see if the path is directed to the correct location. Environment.getExternalStorageDirectory() is probably already going to /external_sd/Downloads/ so it's redundant to add that. Give /Downloads/ a try instead. This StackOverflow answer might explain more: link

    Or if you can somehow print out the path to Android Studio's console so you can see the entire path, that would be useful.

    Tip: could you also paste your code in something that will preserve the whitespace? (eg. Pastebin, Github) It'll be easier to read and debug too, something to keep in mind for the future.

  7. #7
    Yaoi Amateur
    Join Date
    Sep 2009
    Location
    USA New England
    Posts
    76
    Points
    200,000
    Savings
    1,258,103


    Heero (L4)Honey (L2)Link (L7)
    Johan Liebert (L3)(S012) Hollow IchigoMokkun
    Near (L9)
    Please post the entire class as well as your pom.xml, any resource folder contents, MANAFEST.MF, on pastebin and link here or publish your entire project to github. Please also include the stack trace, or at least root cause exception. It may also help to know how you're running and publishing your code (eg: andriod sdk version and emulator or some other ide ....)

    Thank you.
    Last edited by maguscrowley; 01-13-2018 at 10:35 PM.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •