1

I'm trying to write a broadcast receiver that gets called for every SMS text message that comes in. All the published code to do that (that I can find) either has been deprecated or doesn't work.

My code fails at install time, with this message in the log (twice):

06-17 10:15:59.316   396   413 W ActivityManager: No content provider found for permission revoke: file:///data/local/tmp/locator.apk
06-17 10:15:59.316   396   413 W ActivityManager: No content provider found for permission revoke: file:///data/local/tmp/locator.apk

My manifest file looks like this:

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

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
    <receiver android:name=".SmsReceiver" > 
        <intent-filter> 
            <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
        </intent-filter> 
    </receiver>  
</application>

Would be glad if anyone could point out what I'm doing wrong. I'm beginning to suspect that there is no API for reading incoming SMSs.

My source code looks like this:

package com.example;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.util.Log;


public class SmsReceiver extends BroadcastReceiver {
    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
    private static final String TAG = "locator";

    @SuppressWarnings("deprecation")
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "Intent recieved: " + intent.getAction());

        if (intent.getAction() == SMS_RECEIVED) {
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                Object[] pdus = (Object[]) bundle.get("pdus");
                final SmsMessage[] messages = new SmsMessage[pdus.length];
                for (int i = 0; i < pdus.length; i++) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                }
                if (messages.length > -1) {
                    Log.i(TAG,
                            "Message recieved: " + messages[0].getMessageBody());
                }
            }
        }
    }
}
Peter vdL
  • 4,953
  • 10
  • 40
  • 60
  • Are you sure there's nothing else in your app? You are not referencing any `ContentProvider` anywhere. Your app is similar to one of mine, that worked the last time I tried it: https://github.com/commonsguy/cw-omnibus/tree/master/SMS/Monitor – CommonsWare Jun 17 '12 at 17:32
  • possible duplicate of http://stackoverflow.com/questions/8639873/cannot-install-apk-on-android-device-through-eclipse – Vipul Jun 17 '12 at 17:35
  • It's not a duplicate of http://stackoverflow.com/questions/8639873/cannot-install-apk-on-android-device-through-eclipse -- that question relates to directory permissions on a rooted phone. This is a non-rooted phone, and users don't have the ability to chmod permissions in the /data hierarchy. – Peter vdL Jun 17 '12 at 17:48
  • I have downloaded and built the SMS Monitor sample code that you pointed me at, Mark. To my surprise and consternation, I get exactly the same error message with your code, as with mine: 06-17 12:35:08.108 396 413 W ActivityManager: No content provider found for permission revoke: file:///data/local/tmp/sms2.apk 06-17 12:35:08.108 396 413 W ActivityManager: No content provider found for permission revoke: file:///data/local/tmp/sms2.apk -- I will go try a different phone. – Peter vdL Jun 17 '12 at 19:36
  • Did this ever go anywhere...? I'm running into the *exact* same issue now, down to the `BroadcastReceiver` for SMS and everything. – j6m8 Feb 28 '14 at 04:21

2 Answers2

0

Your code (and mine) works just fine on another handset, Mark. I had flashed ICS onto this phone, and I suspect there's something slightly out of whack. It's the handset or the build. Thank you, Peter

Peter vdL
  • 4,953
  • 10
  • 40
  • 60
0

Look for a(another) error message

“No content provider found or permission revoke” is a warning that may not mean anything wrong. In the package install case I investigated it's just a warning message that the package URI doesn't contain an 'authority' (userid/password) portion. handleStartCopy(), (in frameworks/base/services/java/com/android/server/pm/PackageManagerService.java) does:

mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, mPackageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);

some work, then:

mContext.revokeUriPermission(mPackageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);

the message is true, but inconsequential. (removeUriPermission() is in frameworks/base/services/java/com/android/server/pm/ActivityManagerService.java)

For me, this part of the .apk install process worked -- despite the warning message. Check logcat showed for other messages that might indicate why it failed.

Ribo
  • 3,363
  • 1
  • 29
  • 35