java.lang.SecurityException: Permission Denial: opening provider...





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-2















Add Event in Calendar view. when add event in calendar then give below Permission error :



java.lang.SecurityException: Permission Denial: opening provider com.android.providers.calendar.CalendarProvider2 from ProcessRecord{3620f5c 13430:google.com/u0a149} (pid=13430, uid=10149) requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR


Give Permission in android Manifest file. :






My code is below:



  calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int i, int i1, int i2) {
String date =(i2 + "/" + (i1 + 1) + "/" + i);
showAlertDialog(date);

}
});

}

public void showAlertDialog(final String dateString1) {


LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.alert_dialog_item, null);


final EditText etTitle = (EditText) dialogView.findViewById(R.id.etTitle);
final EditText etEvent = (EditText) dialogView.findViewById(R.id.etEvent);

final EditText etEventDate = (EditText) dialogView.findViewById(R.id.etStartDate);

//final EditText etTime = (EditText) dialogView.findViewById(R.id.etTime);

final EditText etEndDate = (EditText) dialogView.findViewById(R.id.etEndDate);

Calendar cal = Calendar.getInstance();

long date1 = cal.getTimeInMillis();
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy, HH:mm a");
String dateString = dateFormat.format(date1);

etEventDate.setText(dateString);

long date2 = cal.getTimeInMillis() + 1000 * 60 * 60;
String endDate = dateFormat.format(date2);
etEndDate.setText(endDate);


final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialogView);
builder.setTitle("Add Event");
builder.setPositiveButton("ADD", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

String title = etTitle.getText().toString();
String eventDescription = etEvent.getText().toString();
String startDate = etEventDate.getText().toString();
String endDate = etEndDate.getText().toString();

//ContactsContract.CommonDataKinds.Event event = new ContactsContract.CommonDataKinds.Event(Color.RED,startDate,eventDescription);

try {

cr = getApplicationContext().getContentResolver();
cv = new ContentValues();
cv.put(CalendarContract.Events.DTSTART, startDate);
cv.put(CalendarContract.Events.DTEND, endDate);
cv.put(CalendarContract.Events.TITLE, title);
cv.put(CalendarContract.Events.DESCRIPTION, eventDescription);
cv.put(CalendarContract.Events.CALENDAR_ID, 1);
cv.put(CalendarContract.Events.EVENT_TIMEZONE, "UTC/GMT+5:30");
cv.put(CalendarContract.Events.CALENDAR_COLOR_KEY, Color.RED);

Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, cv);

if (ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {

}else if(ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED){

// ContentResolver contentResolver = getContentResolver();
//ContentValues contentValues = new ContentValues();


long eventID = Long.parseLong(uri.getLastPathSegment());

Toast.makeText(Event.this, (int) eventID, Toast.LENGTH_SHORT).show();

}



}catch(Exception ex){

ex.printStackTrace();
}
}
});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
builder.setCancelable(true);
}
});

builder.show();

}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults) {


switch (requestCode) {
case MY_PERMISSIONS_REQUEST_WRITE_CALENDAR:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

Toast.makeText(this, " Permission is Granted", Toast.LENGTH_SHORT).show();

} else {
//code for deny
}
break;
}
}


how to Give Permission of Read and Write to add event.please guide me this permission.



How to add event in Calendar synchronization with Mobile Calendar.










share|improve this question























  • dtstart string datatype its give java.lang.IllegalArgumentException: DTSTART cannot be empty.

    – rahul
    Nov 25 '18 at 11:20


















-2















Add Event in Calendar view. when add event in calendar then give below Permission error :



java.lang.SecurityException: Permission Denial: opening provider com.android.providers.calendar.CalendarProvider2 from ProcessRecord{3620f5c 13430:google.com/u0a149} (pid=13430, uid=10149) requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR


Give Permission in android Manifest file. :






My code is below:



  calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int i, int i1, int i2) {
String date =(i2 + "/" + (i1 + 1) + "/" + i);
showAlertDialog(date);

}
});

}

public void showAlertDialog(final String dateString1) {


LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.alert_dialog_item, null);


final EditText etTitle = (EditText) dialogView.findViewById(R.id.etTitle);
final EditText etEvent = (EditText) dialogView.findViewById(R.id.etEvent);

final EditText etEventDate = (EditText) dialogView.findViewById(R.id.etStartDate);

//final EditText etTime = (EditText) dialogView.findViewById(R.id.etTime);

final EditText etEndDate = (EditText) dialogView.findViewById(R.id.etEndDate);

Calendar cal = Calendar.getInstance();

long date1 = cal.getTimeInMillis();
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy, HH:mm a");
String dateString = dateFormat.format(date1);

etEventDate.setText(dateString);

long date2 = cal.getTimeInMillis() + 1000 * 60 * 60;
String endDate = dateFormat.format(date2);
etEndDate.setText(endDate);


final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialogView);
builder.setTitle("Add Event");
builder.setPositiveButton("ADD", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

String title = etTitle.getText().toString();
String eventDescription = etEvent.getText().toString();
String startDate = etEventDate.getText().toString();
String endDate = etEndDate.getText().toString();

//ContactsContract.CommonDataKinds.Event event = new ContactsContract.CommonDataKinds.Event(Color.RED,startDate,eventDescription);

try {

cr = getApplicationContext().getContentResolver();
cv = new ContentValues();
cv.put(CalendarContract.Events.DTSTART, startDate);
cv.put(CalendarContract.Events.DTEND, endDate);
cv.put(CalendarContract.Events.TITLE, title);
cv.put(CalendarContract.Events.DESCRIPTION, eventDescription);
cv.put(CalendarContract.Events.CALENDAR_ID, 1);
cv.put(CalendarContract.Events.EVENT_TIMEZONE, "UTC/GMT+5:30");
cv.put(CalendarContract.Events.CALENDAR_COLOR_KEY, Color.RED);

Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, cv);

if (ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {

}else if(ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED){

// ContentResolver contentResolver = getContentResolver();
//ContentValues contentValues = new ContentValues();


long eventID = Long.parseLong(uri.getLastPathSegment());

Toast.makeText(Event.this, (int) eventID, Toast.LENGTH_SHORT).show();

}



}catch(Exception ex){

ex.printStackTrace();
}
}
});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
builder.setCancelable(true);
}
});

builder.show();

}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults) {


switch (requestCode) {
case MY_PERMISSIONS_REQUEST_WRITE_CALENDAR:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

Toast.makeText(this, " Permission is Granted", Toast.LENGTH_SHORT).show();

} else {
//code for deny
}
break;
}
}


how to Give Permission of Read and Write to add event.please guide me this permission.



How to add event in Calendar synchronization with Mobile Calendar.










share|improve this question























  • dtstart string datatype its give java.lang.IllegalArgumentException: DTSTART cannot be empty.

    – rahul
    Nov 25 '18 at 11:20














-2












-2








-2








Add Event in Calendar view. when add event in calendar then give below Permission error :



java.lang.SecurityException: Permission Denial: opening provider com.android.providers.calendar.CalendarProvider2 from ProcessRecord{3620f5c 13430:google.com/u0a149} (pid=13430, uid=10149) requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR


Give Permission in android Manifest file. :






My code is below:



  calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int i, int i1, int i2) {
String date =(i2 + "/" + (i1 + 1) + "/" + i);
showAlertDialog(date);

}
});

}

public void showAlertDialog(final String dateString1) {


LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.alert_dialog_item, null);


final EditText etTitle = (EditText) dialogView.findViewById(R.id.etTitle);
final EditText etEvent = (EditText) dialogView.findViewById(R.id.etEvent);

final EditText etEventDate = (EditText) dialogView.findViewById(R.id.etStartDate);

//final EditText etTime = (EditText) dialogView.findViewById(R.id.etTime);

final EditText etEndDate = (EditText) dialogView.findViewById(R.id.etEndDate);

Calendar cal = Calendar.getInstance();

long date1 = cal.getTimeInMillis();
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy, HH:mm a");
String dateString = dateFormat.format(date1);

etEventDate.setText(dateString);

long date2 = cal.getTimeInMillis() + 1000 * 60 * 60;
String endDate = dateFormat.format(date2);
etEndDate.setText(endDate);


final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialogView);
builder.setTitle("Add Event");
builder.setPositiveButton("ADD", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

String title = etTitle.getText().toString();
String eventDescription = etEvent.getText().toString();
String startDate = etEventDate.getText().toString();
String endDate = etEndDate.getText().toString();

//ContactsContract.CommonDataKinds.Event event = new ContactsContract.CommonDataKinds.Event(Color.RED,startDate,eventDescription);

try {

cr = getApplicationContext().getContentResolver();
cv = new ContentValues();
cv.put(CalendarContract.Events.DTSTART, startDate);
cv.put(CalendarContract.Events.DTEND, endDate);
cv.put(CalendarContract.Events.TITLE, title);
cv.put(CalendarContract.Events.DESCRIPTION, eventDescription);
cv.put(CalendarContract.Events.CALENDAR_ID, 1);
cv.put(CalendarContract.Events.EVENT_TIMEZONE, "UTC/GMT+5:30");
cv.put(CalendarContract.Events.CALENDAR_COLOR_KEY, Color.RED);

Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, cv);

if (ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {

}else if(ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED){

// ContentResolver contentResolver = getContentResolver();
//ContentValues contentValues = new ContentValues();


long eventID = Long.parseLong(uri.getLastPathSegment());

Toast.makeText(Event.this, (int) eventID, Toast.LENGTH_SHORT).show();

}



}catch(Exception ex){

ex.printStackTrace();
}
}
});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
builder.setCancelable(true);
}
});

builder.show();

}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults) {


switch (requestCode) {
case MY_PERMISSIONS_REQUEST_WRITE_CALENDAR:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

Toast.makeText(this, " Permission is Granted", Toast.LENGTH_SHORT).show();

} else {
//code for deny
}
break;
}
}


how to Give Permission of Read and Write to add event.please guide me this permission.



How to add event in Calendar synchronization with Mobile Calendar.










share|improve this question














Add Event in Calendar view. when add event in calendar then give below Permission error :



java.lang.SecurityException: Permission Denial: opening provider com.android.providers.calendar.CalendarProvider2 from ProcessRecord{3620f5c 13430:google.com/u0a149} (pid=13430, uid=10149) requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR


Give Permission in android Manifest file. :






My code is below:



  calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int i, int i1, int i2) {
String date =(i2 + "/" + (i1 + 1) + "/" + i);
showAlertDialog(date);

}
});

}

public void showAlertDialog(final String dateString1) {


LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.alert_dialog_item, null);


final EditText etTitle = (EditText) dialogView.findViewById(R.id.etTitle);
final EditText etEvent = (EditText) dialogView.findViewById(R.id.etEvent);

final EditText etEventDate = (EditText) dialogView.findViewById(R.id.etStartDate);

//final EditText etTime = (EditText) dialogView.findViewById(R.id.etTime);

final EditText etEndDate = (EditText) dialogView.findViewById(R.id.etEndDate);

Calendar cal = Calendar.getInstance();

long date1 = cal.getTimeInMillis();
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy, HH:mm a");
String dateString = dateFormat.format(date1);

etEventDate.setText(dateString);

long date2 = cal.getTimeInMillis() + 1000 * 60 * 60;
String endDate = dateFormat.format(date2);
etEndDate.setText(endDate);


final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialogView);
builder.setTitle("Add Event");
builder.setPositiveButton("ADD", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

String title = etTitle.getText().toString();
String eventDescription = etEvent.getText().toString();
String startDate = etEventDate.getText().toString();
String endDate = etEndDate.getText().toString();

//ContactsContract.CommonDataKinds.Event event = new ContactsContract.CommonDataKinds.Event(Color.RED,startDate,eventDescription);

try {

cr = getApplicationContext().getContentResolver();
cv = new ContentValues();
cv.put(CalendarContract.Events.DTSTART, startDate);
cv.put(CalendarContract.Events.DTEND, endDate);
cv.put(CalendarContract.Events.TITLE, title);
cv.put(CalendarContract.Events.DESCRIPTION, eventDescription);
cv.put(CalendarContract.Events.CALENDAR_ID, 1);
cv.put(CalendarContract.Events.EVENT_TIMEZONE, "UTC/GMT+5:30");
cv.put(CalendarContract.Events.CALENDAR_COLOR_KEY, Color.RED);

Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, cv);

if (ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {

}else if(ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(Event.this, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED){

// ContentResolver contentResolver = getContentResolver();
//ContentValues contentValues = new ContentValues();


long eventID = Long.parseLong(uri.getLastPathSegment());

Toast.makeText(Event.this, (int) eventID, Toast.LENGTH_SHORT).show();

}



}catch(Exception ex){

ex.printStackTrace();
}
}
});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
builder.setCancelable(true);
}
});

builder.show();

}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults) {


switch (requestCode) {
case MY_PERMISSIONS_REQUEST_WRITE_CALENDAR:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

Toast.makeText(this, " Permission is Granted", Toast.LENGTH_SHORT).show();

} else {
//code for deny
}
break;
}
}


how to Give Permission of Read and Write to add event.please guide me this permission.



How to add event in Calendar synchronization with Mobile Calendar.







android calendar android-permissions






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 5:33









rahulrahul

126




126













  • dtstart string datatype its give java.lang.IllegalArgumentException: DTSTART cannot be empty.

    – rahul
    Nov 25 '18 at 11:20



















  • dtstart string datatype its give java.lang.IllegalArgumentException: DTSTART cannot be empty.

    – rahul
    Nov 25 '18 at 11:20

















dtstart string datatype its give java.lang.IllegalArgumentException: DTSTART cannot be empty.

– rahul
Nov 25 '18 at 11:20





dtstart string datatype its give java.lang.IllegalArgumentException: DTSTART cannot be empty.

– rahul
Nov 25 '18 at 11:20












1 Answer
1






active

oldest

votes


















0














You need manifest and runtime permissions to do that:



Refer to this https://developer.android.com/training/permissions/requesting






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464934%2fjava-lang-securityexception-permission-denial-opening-provider-com-android-pro%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You need manifest and runtime permissions to do that:



    Refer to this https://developer.android.com/training/permissions/requesting






    share|improve this answer




























      0














      You need manifest and runtime permissions to do that:



      Refer to this https://developer.android.com/training/permissions/requesting






      share|improve this answer


























        0












        0








        0







        You need manifest and runtime permissions to do that:



        Refer to this https://developer.android.com/training/permissions/requesting






        share|improve this answer













        You need manifest and runtime permissions to do that:



        Refer to this https://developer.android.com/training/permissions/requesting







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 6:55









        Jawad AhmedJawad Ahmed

        7916




        7916
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464934%2fjava-lang-securityexception-permission-denial-opening-provider-com-android-pro%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Xamarin.form Move up view when keyboard appear

            JBPM : POST request for execute process go wrong