Passing selected files to App ?

Support for Android version of Total Commander

Moderators: white, Hacker, petermad, Stefan2

Post Reply
t_arn
Junior Member
Junior Member
Posts: 42
Joined: 2006-12-28, 07:52 UTC

Passing selected files to App ?

Post by *t_arn »

I have written an app that show differences between two text files.

Is there a way to select 2 files in TC (in 1 panel or in both) and pass those paths to my app?

Tom
Last edited by t_arn on 2011-07-14, 13:14 UTC, edited 1 time in total.
t_arn
Junior Member
Junior Member
Posts: 42
Joined: 2006-12-28, 07:52 UTC

Post by *t_arn »

OK, found the custom button feature, but it's not working as expected:

I have defined a button "Launch app (main function)" and set the Parameters as follows:
extra:FilePath1:%P%N
extra:FilePath2:%T%N

In the onCreate method of my application I have following code:

Code: Select all

    Bundle extras = getIntent().getExtras();
    if (extras != null)
    {
      String fp = extras.getString("FilePath1");
      if (fp!=null) fnLoadFile(fp,0);
      fp = extras.getString("FilePath2");
      if (fp!=null) fnLoadFile(fp,1);
    }
Then, I selected a file in both panels and press my custom button. My application starts OK, but extras is always null and therefore no files are getting loaded and displayed.

Is this a bug in TC or am I doing something wrong?

Tom
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Strange, "extras" should not be null. TC adds the values with a different name, though: If you specify "FilePath1", the extras will be added with name "android.intent.extra.FilePath1". It's added via myIntent.putExtra(extraname,extrastring).
Author of Total Commander
https://www.ghisler.com
t_arn
Junior Member
Junior Member
Posts: 42
Joined: 2006-12-28, 07:52 UTC

Post by *t_arn »

OK, I'll check again if extras is really null.
And if not, I'll try with "android.intent.extra.FilePath1"

Tom
t_arn
Junior Member
Junior Member
Posts: 42
Joined: 2006-12-28, 07:52 UTC

Post by *t_arn »

I have updated my code as follows:

Code: Select all

    // get passed data and load files
    Bundle extras = getIntent().getExtras();
    Log.i(stProgramName, "getting extras");
    if (extras != null)
    {
      Log.i(stProgramName, "getting extra values");
      String fp = extras.getString("android.intent.extra.FilePath1");
      if (fp!=null) fnLoadFile(fp,0);
      fp = extras.getString("android.intent.extra.FilePath2");
      if (fp!=null) fnLoadFile(fp,1);
    }
And yes, extras IS null. In the LogCat I see the message "getting extras", but then nothing else and the files are not being loaded.

The code as such works - I have verified that with another small test app.

Tom
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Strange, it works fine for me with the example in the help (to send two attachments to gmail). Does this example work on your device? The field used is extra:SUBJECT:File to set the subject field (extra2 is for string lists).
Author of Total Commander
https://www.ghisler.com
t_arn
Junior Member
Junior Member
Posts: 42
Joined: 2006-12-28, 07:52 UTC

Post by *t_arn »

ghisler(Author) wrote:Strange, it works fine for me with the example in the help
Well, this example uses "send to app", while I tried "launch app (main function)". They don't seem to work the same way...should they?

With "send to app" I can successfully send the first marked file of the active panel (%P%N) to my app. But how do I send the first marked file of the other panel? In other TC versions this works with %T%M, but %M does not work here.

My app (taTextDiff) shows differences between 2 text files, so I need to be able to pass 2 files, not just one. Why is %T supported but not %M as well?

Tom
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Total Commander only supports parameters for "ACTION_VIEW" and "ACTION_SEND" commands, not for "ACTION_MAIN". Why? According to Adroid documentation "ACTION_MAIN" does not support parameters:
http://developer.android.com/reference/android/content/Intent.html#ACTION_MAIN
public static final String ACTION_MAIN
Since: API Level 1

Activity Action: Start as a main entry point, does not expect to receive data.

Input: nothing

Output: nothing
Constant Value: "android.intent.action.MAIN"
Author of Total Commander
https://www.ghisler.com
Post Reply