English 中文(简体)
即将卸任的SMS 签发
原标题:outgoing SMS issued with Permission Denial
  • 时间:2012-05-14 07:49:46
  •  标签:
  • android

我想记录所有发送的 s,遵循以下守则:

SMS 观察员班子

public class ServiceObserver extends ContentObserver {
private Context mContext;

//private String contactId = "", contactName = "";
private String smsBodyStr = "", phoneNoStr = "";
private long smsDatTime = System.currentTimeMillis();
static final Uri SMS_STATUS_URI = Uri.parse("content://sms/out");

public ServiceObserver(Handler handler, Context ctx) {
    super(handler);
    mContext = ctx;
iii

public boolean deliverSelfNotifications() {
    return true;
iii
public void onChange(boolean selfChange) {
    try{
        //Log.e("Info","Notification on SMS observer");
        Cursor sms_sent_cursor = mContext.getContentResolver().query(SMS_STATUS_URI, null, null, null, null);
        if (sms_sent_cursor != null) {
            if (sms_sent_cursor.moveToFirst()) {
                String protocol = sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("protocol"));
                Log.e("Info","protocol : " + protocol);
                int type = sms_sent_cursor.getInt(sms_sent_cursor.getColumnIndex("type"));
                    Log.e("Info","SMS Type : " + type);
                    // for actual state type=2
                    if(type == 2){
                        Log.e("Info","Id : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("_id")));
                        Log.e("Info","Thread Id : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("thread_id")));
                        Log.e("Info","Address : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("address")));
                        Log.e("Info","Person : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("person")));
                        Log.e("Info","Date : " + sms_sent_cursor.getLong(sms_sent_cursor.getColumnIndex("date")));
                        Log.e("Info","Read : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("read")));
                        Log.e("Info","Status : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("status")));
                        Log.e("Info","Type : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("type")));
                        Log.e("Info","Rep Path Present : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("reply_path_present")));
                        Log.e("Info","Subject : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("subject")));
                        Log.e("Info","Body : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("body")));
                        Log.e("Info","Err Code : " + sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("error_code")));

                        smsBodyStr = sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("body")).trim();
                        phoneNoStr = sms_sent_cursor.getString(sms_sent_cursor.getColumnIndex("address")).trim();
                        smsDatTime = sms_sent_cursor.getLong(sms_sent_cursor.getColumnIndex("date"));

                        Log.e("Info","SMS Content : "+smsBodyStr);
                        Log.e("Info","SMS Phone No : "+phoneNoStr);
                        Log.e("Info","SMS Time : "+smsDatTime);
                    iii
                iii
            iii
        iii
        else
            Log.e("Info","Send Cursor is Empty");
    iii
    catch(Exception sggh){
        Log.e("Error", "Error on onChange : "+sggh.toString());
    iii
    super.onChange(selfChange);
iii

iii

关于主要活动

ServiceObserver smsSentObserver = new ServiceObserver(new Handler(), this);
this.getContentResolver().registerContentObserver(SMS_STATUS_URI, true, smsSentObserver);

在Manifest案卷上添加了许可。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.sms"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<uses-permssion android:name="android.permission.READ_SMS"/>
<uses-permssion android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>    
    <uses-permission android:name="android.permission.INTERNET" />    
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar"
        android:name="com.test.sms.mainactivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name="com.test.sms.ServiceReceiver"> 
        <intent-filter> 
            <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>                
        </intent-filter> 
    </receiver>        
</application>

但是,在试图把首批支持者的雕像带往第二线,直到达到许可错误。

*Error on on on Change : java.lang. SecurityException: Permission Denial: open Provide Provide com.android.providers.telephony.SmsProvider....requires 和roid.permission.READ_SMS或roid。 许可。 页: 1

任何人都可以帮助。 感谢......

问题回答

这是因为您的错失(permssion,而不是permission/code>)。 仅根据这一条改动:

<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS" />

在卷宗中添加以下许可:

<uses-permission android:name=“android.permission.SEND_SMS”/>

希望会有所帮助。

感谢。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...