Skip to content

Commit

Permalink
android: added permissions checks to allow custom datadir read/write
Browse files Browse the repository at this point in the history
  • Loading branch information
D33r-Gee committed Mar 22, 2024
1 parent 734e509 commit 7d4a331
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/qt/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<uses-sdk android:targetSdkVersion="24"/>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
Expand Down
21 changes: 21 additions & 0 deletions src/qt/android/src/org/bitcoincore/qt/BitcoinQtActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import android.system.Os;
import android.view.WindowManager;
import android.view.View;
import android.Manifest;
import android.content.pm.PackageManager;

import org.qtproject.qt5.android.bindings.QtActivity;

import java.io.File;

public class BitcoinQtActivity extends QtActivity
{
private static final int PERMISSIONS_REQUEST_CODE = 123;

@Override
public void onCreate(Bundle savedInstanceState)
{
Expand All @@ -36,5 +40,22 @@ public void onCreate(Bundle savedInstanceState)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);

if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {
Manifest.permission.WRITE_EXTERNAL_STORAGE
}, PERMISSIONS_REQUEST_CODE);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == PERMISSIONS_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
System.out.println("Permission was granted");
} else {
System.out.println("Permission was denied");
}
}
}
}

0 comments on commit 7d4a331

Please sign in to comment.