简体   繁体   中英

Android- How can Make my app as Default SMS App?

I am working an SMS Backup app which stores all SIM SMS in an xml file then we can restore back, then proplem is when i want restore it needs to make my APP as Default SMS app , I Have tried all the solutions but didn't worked for me... i used this but all in vain eg: Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, myPackageName); startActivity(intent);

My App is not showing in Select Default popup . Please Help.

I tried the following code and its working fine for android 10 and 11

make sure to implement all requirements as per this : http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html

and Put following in your Mainactivity class

public void perm2(){
        Context mContext3 = getApplicationContext();
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
            RoleManager roleManager = null;
            roleManager = mContext3.getSystemService(RoleManager.class);
            Intent roleRequestIntent = roleManager.createRequestRoleIntent(
                    RoleManager.ROLE_SMS);
            startActivityForResult(roleRequestIntent, MESSAGE_CODE);

        } else {
            Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
            intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
                    mContext3.getPackageName());
            startActivityForResult(intent, MESSAGE_CODE);
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM