I need to pass a string to an Android apk externally. Currently my app is in development, so I haven't deployed it on Google Market. Is there any way to pass a parameter to apk from an external file like properties file? If yes, please explain the procedure.
If you need it for development only, just place a file on the SD card.
final File tmpFile = new File("/sdcard/myparam.txt");
try {
FileInputStream s = new FileInputStream(tmpFile);
...
use adb push myparam.txt /sdcard/
and adb pull /sdcard/myparam.txt
to transfer it between the desktop and the device.
It is of course incorrect to assume that the SD card is mounted, as well as to use a hard-coded file name, but it is for development only.
If you need to pass a parameter from another application, store in the Intent (assuming that you are the author of both applications).
Actually android uses Intent instead of cmd args. To pass a string from your app to another, for example, you do...
String str = "Test";
Intent intent = new Intent(this,externalApp);
intent.putExtra("str",str);
startActivity(intent);
The app on the other side would go...
Intent intent = getIntent();
String str = getStringExtra("str");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.