• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Selecting a File To Load

 
Ranch Hand
Posts: 70
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I have working code that will export a SQ Lite Database to a set file name -



I then have working code that will load this same file back in -



What I'd like to do is name the file as it's saved, then select it from a list of .db files in the given directory.  I think the naming should be easy enough, how would I bring a file list up for the user to select from?  I think once the file is selected, the loading of the given file name should be easy enough too.

I don't need the precise code (although I wouldn't complain if you posted it) but happy enough to research commands if you can give me some tips on what I'm looking for.

Thanks!
 
Andy Crowther
Ranch Hand
Posts: 70
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I edit, I posted the wrong methods!?



and

 
Marshal
Posts: 28258
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, assuming that you're running that code in an environment where you can just pop up a dialog to ask a user to pick a file from the local machine (and not a web app or some other distributed code), then have a look at the tutorial about file choosers: How to Use File Choosers.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know that Android has a file chooser class.  I never found it and finally wrote one for myself.
I'd be very happy if there is now one available.
 
Andy Crowther
Ranch Hand
Posts: 70
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Well, assuming that you're running that code in an environment where you can just pop up a dialog to ask a user to pick a file from the local machine (and not a web app or some other distributed code), then have a look at the tutorial about file choosers: How to Use File Choosers.



Yeah, it's on my Android app.  Thanks, I'll follow that tutorial when I next have some coding time :)
 
Paul Clapham
Marshal
Posts: 28258
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I didn't notice that important keyword "Android".
 
Andy Crowther
Ranch Hand
Posts: 70
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, lol.  So the link is not what I need?  I had a quick look, it looked like Java? (Even though the screenies were Windows)
 
Paul Clapham
Marshal
Posts: 28258
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right. Check out Norm Radder's more relevant reply.
 
Andy Crowther
Ranch Hand
Posts: 70
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:I don't know that Android has a file chooser class.  I never found it and finally wrote one for myself.
I'd be very happy if there is now one available.



So I've come round to looking at this again, having fixed all my apps to work with Oreo...  it actually looks quite easy -

private static final int CHOOSE_FILE_REQUESTCODE = 1;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/AutBuddy/");
       Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
//        intent.addCategory(Intent.CATEGORY_OPENABLE);
       intent.setDataAndType(selectedUri, "*/db");
       Intent i = Intent.createChooser(intent, "File");
       startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);
       

   }

   @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {

       switch(requestCode){
           case CHOOSE_FILE_REQUESTCODE:
               if(resultCode==-1){
                   Uri uri = data.getData();
                   String filePath = uri.getPath();
                   Toast.makeText(this, filePath,
                           Toast.LENGTH_LONG).show();
               }
               break;
       }


       super.onActivityResult(requestCode, resultCode, data);
   }

That toasts the file location, which I assume (wont get to code it into an app until tomorrow evening at the earliest) I can just slot into my app.

What I've not got working (although people say this code should do it) is have it start off in the folder that has my db files in it.  Any ideas on that?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

have it start off in the folder that has my db files in it


That is one of the side benefits of a roll-your-own file chooser - it remembers where you last looked.


My app recognizes the extra values: START_PATH and TYPE_FILTER.
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic