我正在嘗試編寫一個廣播接收器,該接收器會針對每一條SMS文本消息進行調用。所有發佈的代碼都是這樣做的(我可以找到)要麼已被棄用或不起作用。關於安裝「找不到內容提供者」的Android錯誤消息
我的代碼失敗,在安裝時,與在日誌中此消息(兩次):
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
我的清單文件看起來是這樣的:
<?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>
會很高興如果有人能指出我做錯了什麼。我開始懷疑沒有讀取傳入短信的API。
我的源代碼如下所示:
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());
}
}
}
}
}
你確定你的應用中沒有其他東西嗎?你沒有在任何地方引用任何'ContentProvider'。你的應用與我的應用類似,最後一次嘗試時也是如此:https://github.com/commonsguy/cw-omnibus/tree/master/SMS/Monitor – CommonsWare
http://stackoverflow.com的可能重複/ questions/8639873/can not-install-apk-on-android-device-through-eclipse –
它不是http://stackoverflow.com/questions/8639873/cannot-install-apk-on-android-device-通過日食 - 這個問題涉及根目錄手機上的目錄權限。這是一款根深蒂固的手機,用戶無法在/ data層次結構中修改權限。 –