第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

以編程方式刪除Android SMS

以編程方式刪除Android SMS

慕虎7371278 2019-11-14 10:09:20
我想在我的Android應(yīng)用程序中自動(dòng)刪除某些短信。因此,我有一種方法可以完全按照我的意愿去做。但是,僅當(dāng)我將應(yīng)用程序直接從Eclipse部署到我的手機(jī)時(shí),它才有效。然后,它將刪除傳入的SMS。但是,如果從市場下載應(yīng)用程序,則無法使用。但是也沒有錯(cuò)誤。有人知道我如何解決這個(gè)問題,或者這只能在有根設(shè)備上起作用嗎?public void deleteSMS(Context context, String message, String number) {    try {        mLogger.logInfo("Deleting SMS from inbox");        Uri uriSms = Uri.parse("content://sms/inbox");        Cursor c = context.getContentResolver().query(uriSms,            new String[] { "_id", "thread_id", "address",                "person", "date", "body" }, null, null, null);        if (c != null && c.moveToFirst()) {            do {                long id = c.getLong(0);                long threadId = c.getLong(1);                String address = c.getString(2);                String body = c.getString(5);                if (message.equals(body) && address.equals(number)) {                    mLogger.logInfo("Deleting SMS with id: " + threadId);                    context.getContentResolver().delete(                        Uri.parse("content://sms/" + id), null, null);                }            } while (c.moveToNext());        }    } catch (Exception e) {        mLogger.logError("Could not delete SMS from inbox: " + e.getMessage());    }}
查看完整描述

3 回答

?
青春有我

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超8個(gè)贊

將應(yīng)用程序設(shè)置為默認(rèn)應(yīng)用程序,請參見此。刪除之前,請檢查您的應(yīng)用是否為默認(rèn)短信應(yīng)用。使用電話類提供的URI而不是硬編碼。


public void deleteSMS(Context context,int position)

{

    Uri deleteUri = Uri.parse(Telephony.Sms.CONTENT_URI);

    int count = 0;

    Cursor c = context.getContentResolver().query(deleteUri, new String[]{BaseColumns._ID}, null,

            null, null); // only query _ID and not everything

        try {

              while (c.moveToNext()) {

                // Delete the SMS

                String pid = c.getString(Telephony.Sms._ID); // Get _id;

                String uri = Telephony.Sms.CONTENT_URI.buildUpon().appendPath(pid)

                count = context.getContentResolver().delete(uri,

                    null, null);

              }

        } catch (Exception e) {

        }finally{

          if(c!=null) c.close() // don't forget to close the cursor

        }


   }

它刪除所有(收件箱,發(fā)件箱,草稿)短信。


查看完整回答
反對 回復(fù) 2019-11-14
  • 3 回答
  • 0 關(guān)注
  • 648 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號