1

I was hoping somebody could help me or at least give me some ideas.

I am developing an App Inventor app for the engineering industry. The app is basically finished, but App Inventor does not support I/O to sd card.

Now I need to be able to get the data from the app to a pc somehow without the use of any internet connection (i.e. only over USB or WIFI)(cant use Bluetooth either)

I wrote a short Java app in Eclipse that can save some data to the sdcard, but I don't know how to launch the app from within App Inventor.

Any ideas on how I can accomplish this without having to re-write the whole app in Eclipse?

Here is the code of the Eclipse app that needs to be launched:

    package tlc.savetosd;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

import android.app.Activity;
//import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View.OnClickListener;

public class Savetosd extends Activity {


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

        final EditText txtData = (EditText) findViewById(R.id.edtText);
        this.getPackageName();
        TextView txt = (TextView) findViewById(R.id.textView1);


         Button btnSave = (Button) findViewById(R.id.btnSave);
         btnSave.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
        // write on SD card file data in the text box
        try {
            File myFile = new File("/sdcard/mysdfile.txt");
            myFile.createNewFile();
            FileOutputStream fOut = new FileOutputStream(myFile);
            OutputStreamWriter myOutWriter = 
                                    new OutputStreamWriter(fOut);
            myOutWriter.append(txtData.getText());
            myOutWriter.close();
            fOut.close();
            Toast.makeText(getBaseContext(),
                    "Done writing SD 'mysdfile.txt'",
                    Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Toast.makeText(getBaseContext(), e.getMessage(),
                    Toast.LENGTH_SHORT).show();
        }
    }// onClick
    });

}


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_savetosd, menu);
        return true;    
    }
}

1 Answer 1

1

you can launch other apps from within App Inventor with the Activity Starter.
See also more info about Using the Activity Starter here.

Starting arbitrary apps

You can use the Activity Starter to start any activity at all if you know the package name and class name, or the appropriate intent. Some developers document these intents for the benefit of other Android developers. For hints on starting other apps using intents, see the Android API documentation or search the Android developer forums.

If you have an app on your phone and you don't have the source code, you might still be able figure out the package name and class name (and sometimes the intent) by launching the app and inspecting the Android system log, as indicated above.

UPDATE: You meanwhile can find a small tutorial "How to save a text file to SD card using the Activity Starter calling a Java app" here

Sign up to request clarification or add additional context in comments.

6 Comments

yes, that is a possible answer to part of my question. unfortunately the app that needs to be launched that does the write to sd is an app that was written in eclipse. I know the Package name of the app, but I cant seem to get it to launch from App Inventor. I will edit my original post to include the code of the Eclipse app.
you only need the package name and class name to start your app, you are the developer, so you should know that info... also, don't hesitate to read the activity starter docu (see links provided)... the source code of your app does not help in this case...
I actually figured it out!!! i used the wrong class name. it was supposed to be tlc.savetosd.savetosd instead of just save to sd. now just to figure out how to modify my eclipse app to accept some string from app inventor app and then save it
great! good job! btw: your example also could help other App Inventors to save something on SD card...
i will post a little tutorial somewhere as soon as i figure out how to receive data from app inventor to this Eclipse app
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.