2012-07-19 145 views
0

你好我是Android的新手,即使在我的清单文件中具有所需的SMS权限后,我仍然遇到了这个问题。我尝试了几种方法,但它不再有任何想法?权限拒绝:广播意图android.provider.Telephony.SMS_RECEIVED

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:

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(); 
         }  
        }  
       } 
       } 
      }  
    } 
     } 
}  
} 
+0

你能发布您想要访问SMS的代码? – javajavajava 2012-07-19 18:32:39

+0

只是发布它。 – dythe 2012-07-19 18:44:45

+0

你可以发布崩溃的整个logcat - 2行是不够的! – t0mm13b 2012-07-19 18:49:38

回答

4

我设法通过改变以下来解决它:

<?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> 
0

变化:

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

要:

<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> 

您需要的许可标记,在接收器也是如此。

编辑:

更改属性的android:出口= “假” 到Android:出口= “真”

+0

是的,也试过了,我甚至添加了一些调试日志中间,但它似乎甚至没有达到日志 – dythe 2012-07-19 19:24:23

+0

更新 – dythe 2012-07-19 19:26:57

+0

所以错误已经改变?! – javajavajava 2012-07-19 19:32:55