SDL: permission dialog in start menu to write to external storage / SD card / USB stick
This commit is contained in:
@@ -598,6 +598,7 @@ public class MainActivity extends Activity
|
||||
public void onActivityResult(int request, int response, Intent data) {
|
||||
super.onActivityResult(request, response, data);
|
||||
cloudSave.onActivityResult(request, response, data);
|
||||
SettingsMenuMisc.StorageAccessConfig.onActivityResult(this, request, response, data);
|
||||
}
|
||||
|
||||
private int TextInputKeyboardList[][] =
|
||||
|
||||
@@ -248,6 +248,7 @@ class SettingsMenu
|
||||
new SettingsMenuKeyboard.ScreenGesturesConfig(),
|
||||
new SettingsMenuMisc.VideoSettingsConfig(),
|
||||
new SettingsMenuMisc.CommandlineConfig(),
|
||||
new SettingsMenuMisc.StorageAccessConfig(),
|
||||
new SettingsMenuMisc.ResetToDefaultsConfig(),
|
||||
new OkButton(),
|
||||
};
|
||||
|
||||
@@ -542,6 +542,42 @@ class SettingsMenuMisc extends SettingsMenu
|
||||
}
|
||||
}
|
||||
|
||||
public static class StorageAccessConfig extends Menu
|
||||
{
|
||||
public static int REQUEST_STORAGE_ID = 42;
|
||||
|
||||
public static void onActivityResult(final MainActivity p, final int requestCode, final int resultCode, final Intent resultData)
|
||||
{
|
||||
if (requestCode == REQUEST_STORAGE_ID)
|
||||
{
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
Uri treeUri = resultData.getData();
|
||||
p.getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
Log.i("SDL", "Storage write permission granted to path " + treeUri.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.i("SDL", "Storage write permission rejected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String title(final MainActivity p)
|
||||
{
|
||||
return p.getResources().getString(R.string.storage_access);
|
||||
}
|
||||
void run (final MainActivity p)
|
||||
{
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP)
|
||||
{
|
||||
p.startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), REQUEST_STORAGE_ID);
|
||||
}
|
||||
|
||||
goBack(p);
|
||||
}
|
||||
}
|
||||
|
||||
static class CommandlineConfig extends Menu
|
||||
{
|
||||
String title(final MainActivity p)
|
||||
|
||||
@@ -41,6 +41,7 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
||||
|
||||
// The game helper object. This class is mainly a wrapper around this object.
|
||||
protected GameHelper mHelper;
|
||||
public int REQUEST_CLOUD_SAVE_ID = 38;
|
||||
|
||||
MainActivity parent;
|
||||
|
||||
@@ -72,6 +73,8 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
||||
boolean createNewSave = false;
|
||||
public void onActivityResult(int request, int response, Intent intent)
|
||||
{
|
||||
if (request != REQUEST_CLOUD_SAVE_ID)
|
||||
return;
|
||||
Log.d("SDL", "CloudSave: onActivityResult() response " + response + " intent " + (intent != null));
|
||||
try
|
||||
{
|
||||
@@ -119,7 +122,7 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
parent.startActivityForResult(snapshotIntent, 0);
|
||||
parent.startActivityForResult(snapshotIntent, REQUEST_CLOUD_SAVE_ID);
|
||||
}
|
||||
});
|
||||
semaphore.acquireUninterruptibly();
|
||||
@@ -192,7 +195,7 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
parent.startActivityForResult(snapshotIntent, 0);
|
||||
parent.startActivityForResult(snapshotIntent, REQUEST_CLOUD_SAVE_ID);
|
||||
}
|
||||
});
|
||||
semaphore.acquireUninterruptibly();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<string name="storage_phone">Внутреннее хранение - %d Мб</string>
|
||||
<string name="storage_sd">SD карта - %d Мб</string>
|
||||
<string name="storage_question">Куда сохранять данные приложения</string>
|
||||
<string name="storage_access">Разрешение на запись на SD карту</string>
|
||||
<string name="optional_downloads">Дополнительные загрузки</string>
|
||||
<string name="ok">Продолжить</string>
|
||||
<string name="controls_arrows">Стрелки / джойстик / Dpad</string>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<string name="storage_phone">Внутрішнє зберігання - %d Мб</string>
|
||||
<string name="storage_sd">SD карта - %d Мб</string>
|
||||
<string name="storage_question">Куди зберігати дані програми</string>
|
||||
<string name="storage_access">Дозвіл на запис на SD карту</string>
|
||||
<string name="optional_downloads">Додаткові завантаження</string>
|
||||
<string name="ok">ОК</string>
|
||||
<string name="controls_arrows">Стрілки / джойстік / Dpad</string>
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<string name="storage_custom">Specify directory</string>
|
||||
<string name="storage_commandline">Command line parameters, one argument per line</string>
|
||||
<string name="storage_question">Data installation location</string>
|
||||
<string name="storage_access">Permission to write to SD card</string>
|
||||
<string name="optional_downloads">Downloads</string>
|
||||
<string name="downloads">Downloads</string>
|
||||
<string name="ok">OK</string>
|
||||
|
||||
@@ -587,8 +587,26 @@ int main(int argc, char* argv[])
|
||||
//SDL_ANDROID_SetScreenKeyboardButtonGenerateTouchEvents(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, 1);
|
||||
//SDL_ANDROID_SetScreenKeyboardButtonGenerateTouchEvents(SDL_ANDROID_SCREENKEYBOARD_BUTTON_3, 1);
|
||||
|
||||
create_server_socket(6000);
|
||||
|
||||
{
|
||||
// Write to SD card
|
||||
FILE * ff = fopen("/storage/C164-1DEC/ballfield.txt", "wb");
|
||||
if (ff)
|
||||
{
|
||||
fputs("Ballfield!\n", ff);
|
||||
fclose(ff);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Write to shared storage
|
||||
FILE * ff = fopen("/storage/emulated/0/ballfield2.txt", "wb");
|
||||
if (ff)
|
||||
{
|
||||
fputs("Ballfield!\n", ff);
|
||||
fclose(ff);
|
||||
}
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#define fprintf(X, ...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__)
|
||||
#define printf(...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__)
|
||||
|
||||
|
||||
|
||||
void error(const char *msg)
|
||||
{
|
||||
perror(msg);
|
||||
__android_log_print(ANDROID_LOG_ERROR, "Ballfield", "%s", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int create_server_socket(int portno)
|
||||
{
|
||||
int sockfd, newsockfd;
|
||||
socklen_t clilen;
|
||||
char buffer[256];
|
||||
struct sockaddr_in serv_addr, cli_addr;
|
||||
int n;
|
||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sockfd < 0) error("ERROR opening socket");
|
||||
bzero((char *) &serv_addr, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
serv_addr.sin_port = htons(portno);
|
||||
if (bind(sockfd, (struct sockaddr *) &serv_addr,
|
||||
sizeof(serv_addr)) < 0) error("ERROR on binding");
|
||||
listen(sockfd,5);
|
||||
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Opened TCP socket %d port %d", sockfd, portno);
|
||||
return 0;
|
||||
/*
|
||||
clilen = sizeof(cli_addr);
|
||||
newsockfd = accept(sockfd,
|
||||
(struct sockaddr *) &cli_addr,
|
||||
&clilen);
|
||||
if (newsockfd < 0)
|
||||
error("ERROR on accept");
|
||||
bzero(buffer,256);
|
||||
n = read(newsockfd,buffer,255);
|
||||
if (n < 0) error("ERROR reading from socket");
|
||||
printf("Here is the message: %s\n",buffer);
|
||||
n = write(newsockfd,"I got your message",18);
|
||||
if (n < 0) error("ERROR writing to socket");
|
||||
close(newsockfd);
|
||||
close(sockfd);
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user