0
package com.testing.email;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AndroidEmailActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
String msg = "**********Backup Phone Contacts**********\n\n";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button send = (Button)findViewById(R.id.button1);
    send.setOnClickListener(this);
}

public void onClick(View view){

    ContentResolver cr = getContentResolver();
    Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

    while(cursor.moveToNext()){
        String name = cursor.getString(cursor.getColumnIndexOrThrow(Phone.DISPLAY_NAME));
        String number = cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER));

        msg += name + "\t\t\t" + number + "\n";         
    }

    String emailAddress = "testing@hotmail.com";
    String emailSubject = "Testing";
    String emailText = msg;

    String emailAddressList[] = {emailAddress};

    Intent intent = new Intent(Intent.ACTION_SEND); 
    intent.setType("plain/text");
    intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);  
    intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); 
    intent.putExtra(Intent.EXTRA_TEXT, emailText); 
    startActivity(Intent.createChooser(intent, "Android apps send email:"));
    }
}

日志猫

10-16 13:18:41.435: E/ActivityThread(732): Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@41071180 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-16 13:18:41.435: E/ActivityThread(732): android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@41071180 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1043)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1030)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1024)
10-16 13:18:41.435: E/ActivityThread(732):  at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:341)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:65)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:99)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:53)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.Activity.performCreate(Activity.java:4465)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-16 13:18:41.435: E/ActivityThread(732):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-16 13:18:41.435: E/ActivityThread(732):  at android.os.Looper.loop(Looper.java:137)
10-16 13:18:41.435: E/ActivityThread(732):  at android.app.ActivityThread.main(ActivityThread.java:4424)
10-16 13:18:41.435: E/ActivityThread(732):  at java.lang.reflect.Method.invokeNative(Native Method)
10-16 13:18:41.435: E/ActivityThread(732):  at java.lang.reflect.Method.invoke(Method.java:511)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-16 13:18:41.435: E/ActivityThread(732):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-16 13:18:41.435: E/ActivityThread(732):  at dalvik.system.NativeStart.main(Native Method)

我正在开发一个应用程序,当手机丢失或被盗时,用户可以使用电子邮件找回所有手机联系人。我只是在测试一些简单的编码并尝试检索所有联系人号码并将它们放入消息中并发送到定义的电子邮件地址。我正在使用 Android 模拟器对此进行测试,并且我已经在模拟器中保存了 5 个示例联系人以进行实验。但是当我收到从这个应用程序发送的电子邮件时,我收到了超过 5 个联系电话,并且有很多联系电话不应该在我的模拟器中。我附上了我的代码和logcat,请有人帮我检查一下...谢谢...

4

1 回答 1

0

有更多人对某些 android 版本有此问题:

安卓错误

所以问题1

所以问题2

所以问题3

和更多 :)

于 2012-10-16T13:46:40.017 回答