I am trying to access the folder of my app from data/data
but it need to change the permission to 0777
. So, I had used some code that can change at
Here, I developed one class for to give granted permission on marshmallow device.
Getpermission.java
public class GetPermission extends Activity {
private static final int REQUEST_CODE = 2;
private static final int REQUEST_PERMISSIONS = 10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >=23)
{
getPermission();
}
else
{
startService();
}
}
private void getPermission()
{
if (ContextCompat.checkSelfPermission(GetPermission.this, Manifest.permission.READ_EXTERNAL_STORAGE)
+ ContextCompat.checkSelfPermission(GetPermission.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(GetPermission.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
},
REQUEST_PERMISSIONS);
}
else
{
startService();
}
}
private void startService()
{
//In this intent add your starting first activity
Intent in = new Intent(getApplicationContext(),HomeScreen.class);
startActivity(in)
finish();
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSIONS) {
if ((grantResults.length > 0) && (grantResults[0]+grantResults[1]+grantResults[2])
== PackageManager.PERMISSION_GRANTED) {
getWindowOverLayPermission();
} else {
Toast.makeText(GetPermission.this, "All Permission is required to use xyz", Toast.LENGTH_LONG).show();
finish();
}
}
}
@TargetApi(Build.VERSION_CODES.M)
private void getWindowOverLayPermission()
{
if (!Settings.canDrawOverlays(GetPermission.this))
{
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
}
else
{
startService();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE)
{
Toast.makeText(GetPermission.this, "Windows Overlay Permission is required",Toast.LENGTH_LONG).show();
getWindowOverLayPermission();
}
else
{
startService();
}
}
}
After that change your Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.christmashdwallpaper" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/icon_256"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MyMaterialTheme" >
<activity android:name=".Permission.GetPermission" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity.HomeScreen"/>
</application>
Hope,It will help you...