Page 1 of 1

Passing selected files to App ?

Posted: 2011-07-12, 06:36 UTC
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

Posted: 2011-07-13, 13:38 UTC
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

Posted: 2011-07-14, 13:36 UTC
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).

Posted: 2011-07-14, 14:10 UTC
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

Posted: 2011-07-14, 14:59 UTC
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

Posted: 2011-07-15, 15:21 UTC
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).

Posted: 2011-07-15, 22:16 UTC
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

Posted: 2011-07-16, 07:36 UTC
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"