2

我在从 APP 发送短信时遇到问题。我的应用程序在三星、诺基亚等设备上运行良好。但在 OPPO、VIVO 设备等设备上无法运行。我测试的所有设备都是 SDK29 (ANDROID 10)。

ps:我是新手

下面是我的代码Sombodey,请帮助我。

sendSms() 方法用于发送短信。

 private void sendSms() {
        String names = name_text.getText().toString();

        String s1=phone_text.getText().toString();
        String s2=("Hi "+names+", You have Successfully recharged ₹ " +d1 +" to your account  on "+timeStamp+". Your current balance is ₹ "+amount+" . Kindly clear your balance on time without any due. \n - Thank you! ");
        try {

            if (!TextUtils.isEmpty(s1) && !TextUtils.isEmpty(s2)) {

                if (checkPermission(Manifest.permission.SEND_SMS)) {
                    SmsManager smsManager = SmsManager.getDefault();
                    ArrayList<String> part = smsManager.divideMessage(s2); //this is line 629//

                    smsManager.sendMultipartTextMessage(s1, null, part, null, null);
                } else {
                    Toast.makeText(UserDetailsActivity.this, "Permission Denied", Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(UserDetailsActivity.this, "Permission denied", Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e) {
            Log.wtf("userDetailsActivity","Error ", e);
            e.printStackTrace();

        }

    }

在设备 OPPO/VIVO 上调用此方法时没有任何反应

但在三星上工作正常

运行中显示的是

E/userDetailsActivity: Error 
    java.lang.SecurityException: getGroupIdLevel1
        at android.os.Parcel.createException(Parcel.java:2085)
        at android.os.Parcel.readException(Parcel.java:2053)
        at android.os.Parcel.readException(Parcel.java:2001)
        at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getGroupIdLevel1ForSubscriber(IPhoneSubInfo.java:1009)
        at android.telephony.TelephonyManager.getGroupIdLevel1(TelephonyManager.java:4007)
        at android.telephony.SmsMessage.hasEmsSupport(SmsMessage.java:1010)
        at com.android.internal.telephony.SmsMessageBase.calcUnicodeEncodingDetails(SmsMessageBase.java:512)
        at com.android.internal.telephony.gsm.SmsMessage.calculateLength(SmsMessage.java:1002)
        at android.telephony.SmsMessage.fragmentText(SmsMessage.java:435)
        at android.telephony.SmsManager.divideMessage(SmsManager.java:958)
        at com.ancorp.aplo.activity.UserDetailsActivity.sendSms(UserDetailsActivity.java:629)
        at com.ancorp.aplo.activity.UserDetailsActivity.access$700(UserDetailsActivity.java:61)
        at com.ancorp.aplo.activity.UserDetailsActivity$11.onClick(UserDetailsActivity.java:607)
        at android.view.View.performClick(View.java:7187)
        at android.view.View.performClickInternal(View.java:7164)
        at android.view.View.access$3500(View.java:813)
        at android.view.View$PerformClick.run(View.java:27642)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:230)
        at android.app.ActivityThread.main(ActivityThread.java:7752)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:508)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)

这是我的Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ancorp.aplo">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light">
        <activity android:name=".activity.CollectionDetailsActivity"
            android:parentActivityName=".activity.MainActivity"></activity>
        <activity android:name=".activity.BoxDetailsActivity"
            android:parentActivityName=".activity.MainActivity"/>
        <activity android:name=".activity.PaymentDetailsActivity"
            android:parentActivityName=".activity.MainActivity"/>
        <activity
            android:name=".activity.SettingsActivity"
            android:label="@string/title_activity_settings"
            android:parentActivityName=".activity.MainActivity" />
        <activity android:name=".activity.AddPlanActivity" />
        <activity
            android:name=".activity.UserAddActivity"
            android:label="Add Customer"
            android:parentActivityName=".activity.MainActivity" />
        <activity
            android:name=".activity.UserDetailsActivity"
            android:parentActivityName=".activity.MainActivity" />
        <activity android:name=".activity.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />
            </intent-filter>
        </activity>
        <activity android:name=".activity.SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE_PERMISSION" />

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />



</manifest>
4

1 回答 1

0

我认为问题在于您声明字符串的方式。尝试不使用分割消息功能。将 arraylist 直接传递给sendMultipartTextMessage函数

于 2020-08-27T12:07:36.590 回答