This code working properly on lollypop version, But, when i use it on Kitkat, it always returns 0 when i choose "Yes/No" option from dialog.
btnSMSRestore.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (currentapiVersion >= android.os.Build.VERSION_CODES.KITKAT){
defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(SMSActivity.this);
if (!getPackageName().equals(defaultSmsApp))
{
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());
//startActivity(intent);
startActivityForResult(intent, DEF_SMS_REQ);
}
}
else
{
new RestoreSMS().execute();
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (requestCode)
{
case DEF_SMS_REQ:
if(resultCode == Activity.RESULT_OK)
{
new RestoreSMS().execute();
}
}
}
Activity.RESULT_OK value is -1 and resultCode in onActivityResult is always 0 when use with kitkat.