Question

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;    
    }
}
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top