这需要android.permission.INTERACT_ACROSS_USERS_FULL

时间:2015-07-04 19:57:08

标签: android smsmanager

此问题与此问题有关

send and receive sms to verify mobile number

我在& t设备上解锁了三星。我试图通过代码发送消息。但我的代码没有工作,所以我用USB连接我的设备,跟踪问题是什么。我发现我得到了这个例外

981/? E/DatabaseUtils﹕ Writing exception to parcel
    java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
        at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13175)
        at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2044)
        at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:615)
        at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
        at android.os.Binder.execTransact(Binder.java:388)
        at dalvik.system.NativeStart.run(Native Method)
07-05 00:53:08.676    2411-2981/? W/ActivityManager﹕ Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
07-05 00:53:08.691  22617-22617/com.keepAeye.gps E/code is﹕ 29514 

我在清单文件中添加了这些权限

   <uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>

但仍然没有工作。

我现在该怎么办?

我知道这个网站上有几个关于这个问题的帖子,但没有一个帮助我。

更新

这是我发送消息的代码

  private void sendSMS1(String  phoneNumber, String  message)
{
    String  SENT = "SMS_SENT";
    String  DELIVERED = "SMS_DELIVERED";

    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
            new Intent(SENT), 0);

    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);

    //---when the SMS has been sent---
    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode()) {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS sent",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Toast.makeText(getBaseContext(), "Generic failure",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(getBaseContext(), "No service",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(getBaseContext(), "Null PDU",
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getBaseContext(), "Radio off",
                            Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    }, new IntentFilter(SENT));

    //---when the SMS has been delivered---
    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode()) {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS delivered",
                            Toast.LENGTH_SHORT).show();
                    break;
                case Activity.RESULT_CANCELED:
                    Toast.makeText(getBaseContext(), "SMS not delivered",
                            Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    }, new IntentFilter(DELIVERED));

    SmsManager sms = SmsManager.getDefault();

    sms.sendTextMessage("9501921***", null, "hello", sentPI, deliveredPI);
}

它总是会失败。不知道为什么。

1 个答案:

答案 0 :(得分:1)

为了能够保留INTERACT_ACROSS_USERS,您的应用必须由固件的签名密钥签名,或者必须安装在系统分区上。

为了能够保留INTERACT_ACROSS_USERS_FULL,您的应用必须通过固件的签名密钥进行签名。

普通应用程序未通过固件的签名密钥签名,因为它适用于设备制造商和编写自定义ROM的人员。普通应用程序未安装在系统分区上,因为它适用于设备制造商,编写自定义ROM的人员以及根设备的人员。

目前还不清楚为什么您认为您在问题中显示的消息与您的应用有关。如果您确定这样做,则需要确定触发这些消息的代码是什么,然后修复该代码。