|
22 | 22 |
|
23 | 23 | package com.example.wolfssl; |
24 | 24 |
|
| 25 | +import android.content.Intent; |
| 26 | +import android.net.Uri; |
| 27 | +import android.os.Environment; |
| 28 | +import android.provider.Settings; |
25 | 29 | import android.support.v7.app.AppCompatActivity; |
26 | 30 | import android.os.Bundle; |
| 31 | +import android.view.View; |
| 32 | +import android.widget.Button; |
27 | 33 | import android.widget.TextView; |
28 | | -import android.Manifest; |
29 | | -import android.content.pm.PackageManager; |
30 | 34 |
|
31 | 35 | import com.wolfssl.WolfSSL; |
32 | 36 | import com.wolfssl.WolfSSLException; |
33 | 37 | import com.wolfssl.provider.jsse.WolfSSLProvider; |
34 | 38 | import com.wolfssl.provider.jsse.WolfSSLX509; |
35 | 39 |
|
36 | 40 | import java.io.FileInputStream; |
37 | | -import java.io.FileNotFoundException; |
38 | 41 | import java.io.IOException; |
39 | 42 | import java.security.KeyStore; |
40 | 43 | import java.security.KeyStoreException; |
|
48 | 51 |
|
49 | 52 | public class MainActivity extends AppCompatActivity { |
50 | 53 |
|
| 54 | + private View.OnClickListener buttonListener = new View.OnClickListener() { |
| 55 | + @Override |
| 56 | + public void onClick(View v) { |
| 57 | + TextView tv = (TextView) findViewById(R.id.sample_text); |
| 58 | + |
| 59 | + try { |
| 60 | + testLoadCert(tv); |
| 61 | + } catch (Exception e) { |
| 62 | + e.printStackTrace(); |
| 63 | + } |
| 64 | + } |
| 65 | + }; |
| 66 | + |
51 | 67 | @Override |
52 | 68 | protected void onCreate(Bundle savedInstanceState) { |
53 | 69 | int permission; |
54 | 70 | super.onCreate(savedInstanceState); |
55 | 71 | setContentView(R.layout.activity_main); |
56 | 72 |
|
| 73 | + Button button = (Button) findViewById(R.id.button); |
| 74 | + button.setOnClickListener(buttonListener); |
| 75 | + |
57 | 76 | TextView tv = (TextView) findViewById(R.id.sample_text); |
58 | 77 | tv.setText("wolfSSL JNI Android Studio Example App"); |
59 | 78 |
|
60 | 79 |
|
61 | | - permission = checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE); |
62 | | - if (permission != PackageManager.PERMISSION_GRANTED) { |
63 | | - requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},1); |
64 | | - } |
65 | | - |
66 | | - try { |
67 | | - testLoadCert(tv); |
68 | | - } catch (Exception e) { |
69 | | - e.printStackTrace(); |
| 80 | + if (Environment.isExternalStorageManager()) { |
| 81 | + } else { |
| 82 | + Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); |
| 83 | + Uri uri = Uri.fromParts("package", getPackageName(), null); |
| 84 | + intent.setData(uri); |
| 85 | + startActivity(intent); |
70 | 86 | } |
71 | 87 | } |
72 | 88 |
|
|
0 commit comments