权限拒绝:广播Intent android.provider.Telephony.SMS_RECEIVED [英] Permission Denial: broadcasting Intent android.provider.Telephony.SMS_RECEIVED

查看:95
本文介绍了权限拒绝:广播Intent android.provider.Telephony.SMS_RECEIVED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是Android的新手,即使清单文件中具有必需的SMS权限,我仍然遇到此问题.我尝试了几种方法,但是它不起作用了吗?

Hello i am new to Android, I'm getting this problem even after having the required SMS permissions inside my manifest file. I tried a couple of ways but it doesn't work anymore got any idea?

AndroidManifest.xml

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.phonefinder2"
        android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

        <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION" />    
   <uses-permission android:name="android.permission.RECEIVE_SMS" />
   <uses-permission android:name="android.permission.READ_SMS" />

    <application android:icon="@drawable/ic_launcher">


        <activity android:name=".PhoneFinder" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name=".FinderReceiver" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_SMS"> 
            <intent-filter > 
                <action android:name="android.provider.Telephony.SMS_RECEIVED" android:priority="999"/> 
            </intent-filter> 
        </receiver>
    </application>

</manifest> 

错误:

07-19 19:23:25.915: D/SntpClient(66): request time failed: java.net.SocketException: Address family not supported by protocol
07-19 19:23:29.444: W/ActivityManager(66): Permission denied: checkComponentPermission() reqUid=10042
07-19 19:23:29.454: W/ActivityManager(66): Permission Denial: broadcasting Intent { act=android.provider.Telephony.SMS_RECEIVED (has extras) } from com.android.phone (pid=124, uid=1001) requires android.permission.RECEIVE_SMS due to receiver com.example.phonefinder2/com.example.phonefinder2.FinderReceiver
07-19 19:23:29.544: V/Telephony(235): getOrCreateThreadId uri: content://mms-sms/threadID?recipient=83380222
07-19 19:23:29.616: V/Telephony(235): getOrCreateThreadId cursor cnt: 1
07-19 19:23:30.126: D/Mms:app(235): getSmsNewMessageNotificationInfo: count=19, first addr=83380222, thread_id=1
07-19 19:23:30.194: W/NotificationService(66): STOP command without a player
07-19 19:23:30.305: D/MediaPlayer(66): Couldn't open file on client side, trying server side
07-19 19:23:30.334: E/MediaPlayerService(34): Couldn't open fd for content://settings/system/notification_sound
07-19 19:23:30.334: E/MediaPlayer(66): Unable to to create media player
07-19 19:23:30.354: W/NotificationService(66): error loading sound for content://settings/system/notification_sound
07-19 19:23:30.354: W/NotificationService(66): java.io.IOException: setDataSource failed.: status=0x80000000
07-19 19:23:30.354: W/NotificationService(66):  at android.media.MediaPlayer.setDataSource(Native Method)
07-19 19:23:30.354: W/NotificationService(66):  at android.media.MediaPlayer.setDataSource(MediaPlayer.java:716)
07-19 19:23:30.354: W/NotificationService(66):  at android.media.MediaPlayer.setDataSource(MediaPlayer.java:671)
07-19 19:23:30.354: W/NotificationService(66):  at com.android.server.NotificationPlayer$CreationAndCompletionThread.run(NotificationPlayer.java:88)

FinderReceiver.java:

FinderReceiver.java:

package com.example.phonefinder2;

import android.app.Notification;   
import android.app.NotificationManager;   
import android.app.PendingIntent;   
import android.content.BroadcastReceiver;   
import android.content.Context;   
import android.content.Intent;   
import android.content.SharedPreferences;   
import android.location.Location;   
import android.location.LocationManager;   
import android.os.Bundle;   
import android.telephony.SmsManager;   
import android.telephony.SmsMessage;   
import android.util.Log;
import android.widget.Toast;

public class FinderReceiver extends BroadcastReceiver {
    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
    private static final String TAG = "Logging Activity";

    Context context;   
    @Override    
    public void onReceive(Context context, Intent intent) {  
        Log.v(TAG, "New Broadcast Receiver");
        this.context = context;   
        SharedPreferences passwdfile = context.getSharedPreferences(    
                PhoneFinder.PASSWORD_PREF_KEY, 0); 

        Log.v(TAG, PhoneFinder.PASSWORD_PREF_KEY);

        String correctMd5 = passwdfile.getString(PhoneFinder.PASSWORD_PREF_KEY,    
                null);    

        Log.v(TAG, correctMd5);

        if (correctMd5 != null) {    
            Log.v(TAG, "MD5 is not null");

            if (intent.getAction().equals(SMS_RECEIVED)) {
              Log.v(TAG, "Intent SMS RECEIVED success");
              Bundle bundle = intent.getExtras();   
              if (bundle != null) {
              Object pdus[] = (Object[]) bundle.get("pdus");
              SmsMessage smsMessage[] = new SmsMessage[pdus.length];   

//              for(int i = 0; i < smsMessage.length; i++)
              for(int i = 0; i < pdus.length; i++) {   
                  smsMessage[i] = SmsMessage.createFromPdu((byte[])pdus[i]);   
                if (smsMessage[i].getMessageBody().contains("RING:")) {    
                    String[] tokens = smsMessage[i].getMessageBody().split(":");    
                    if (tokens.length >= 2) {    
                        String md5hash = PhoneFinder.getMd5Hash(tokens[1]);    

                        if (correctMd5.equals(md5hash)) {    
/*                            String to = smsMessage[i].getOriginatingAddress (); 
                            SmsManager sm = SmsManager.getDefault(); 

                             sm.sendTextMessage (to, null, "success!", null, null);
                            NotificationManager nm =  
                                (NotificationManager) context.getSystemService (Context.NOTIFICATION_SERVICE); 
                            Notification notification = new Notification(android.R.drawable.ic_dialog_info, "Alert", System.currentTimeMillis());
                            PendingIntent contentIntent = PendingIntent.getActivity (context, 0, new Intent (context, PhoneFinder.class), 0);
                            notification.setLatestEventInfo (context, "GPS address", "You have been detected", contentIntent);
                            nm.notify (R.string.service_start, notification);*/
                            this.abortBroadcast();
                            Toast toast = Toast.makeText(context, "Ring success!", Toast.LENGTH_LONG); 
                            toast.show();
                        }    
                    }    
                } 
                }   
            }    
    }
        }
}    
}

推荐答案

我设法通过更改以下内容对其进行了修复:

I managed to fix it by changing the following:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.phonefinder2" android:versionCode="1" android:versionName="1.0">

    <uses-permission android:name="android.permission.BROADCAST_SMS"/>
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION" />    
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <application android:icon="@drawable/ic_launcher">

        <activity android:name=".PhoneFinder" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name=".FinderReceiver" android:enabled="true" android:exported="true" android:permission="android.permission.BROADCAST_SMS"> 
            <intent-filter android:priority="1000"> 
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/> 
            </intent-filter> 
        </receiver>

     </application>

     <uses-sdk android:minSdkVersion="8" />
     <uses-permission android:name="android.permission.RECEIVE_SMS" />

</manifest> 

这篇关于权限拒绝:广播Intent android.provider.Telephony.SMS_RECEIVED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆