added permissoin request for android example
This commit is contained in:
@@ -1,11 +1,17 @@
|
|||||||
package net.irext.ircontrol.ui.activity;
|
package net.irext.ircontrol.ui.activity;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.support.annotation.RequiresApi;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -88,6 +94,46 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
gotoCreateNew();
|
gotoCreateNew();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
isReadStoragePermissionGranted();
|
||||||
|
isWriteStoragePermissionGranted();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReadStoragePermissionGranted() {
|
||||||
|
if (Build.VERSION.SDK_INT >= 23) {
|
||||||
|
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||||
|
== PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Log.v(TAG,"read permission is granted");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Log.v(TAG,"read permission is revoked");
|
||||||
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 3);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { //permission is automatically granted on sdk<23 upon installation
|
||||||
|
Log.v(TAG,"read permission is granted");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWriteStoragePermissionGranted() {
|
||||||
|
if (Build.VERSION.SDK_INT >= 23) {
|
||||||
|
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
|
== PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Log.v(TAG,"write permission is granted");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Log.v(TAG,"write permission is revoked");
|
||||||
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { //permission is automatically granted on sdk<23 upon installation
|
||||||
|
Log.v(TAG,"write permission is granted");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void gotoCreateNew() {
|
private void gotoCreateNew() {
|
||||||
@@ -127,4 +173,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
switch (requestCode) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,16 +137,6 @@ public class ControlFragment extends Fragment implements View.OnClickListener {
|
|||||||
|
|
||||||
/* decode SDK - load binary file */
|
/* decode SDK - load binary file */
|
||||||
int ret = mIRDecode.openFile(category, mCurrentRemoteControl.getSubCategory(), binFileName);
|
int ret = mIRDecode.openFile(category, mCurrentRemoteControl.getSubCategory(), binFileName);
|
||||||
File binFile = new File(binFileName);
|
|
||||||
byte []binaries = new byte[(int)binFile.length()];
|
|
||||||
try {
|
|
||||||
if (null != binFile) {
|
|
||||||
FileInputStream fin = new FileInputStream(binFile);
|
|
||||||
fin.read(binaries);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Log.d(TAG, "binary opened : " + ret);
|
Log.d(TAG, "binary opened : " + ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user