0

我一直在尝试创建一个警报管理器,以允许我将电子邮件发送到一个小时。我的应用程序是一种日历,所以我会有很多任务,我需要区分程序。为此,我使用事件的开始时间作为 id。

这是我的代码:

public class EndEventTask extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    String email = "someemaildirection@gmail.com";
    Uri uri = Uri.parse(email);
    Intent EmailActivity = new Intent(Intent.ACTION_SENDTO, uri);                                   
    //EmailActivity.putExtra(Intent.EXTRA_SUBJECT,
    //        "Customer comments/questions");
    String message="Prueba de la aplicación del proyecto.";// message to send
    EmailActivity.putExtra(Intent.EXTRA_TEXT, message);
    EmailActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(EmailActivity);       
}

}

并且警报管理器是从一个活动发送的,一旦发送了任务,活动就会完成。例如这里::

if(preferences.getBoolean("AlertCustomer", false)){
        scheduleAlarmEnd(finalDate.getTimeInMillis());
    }
Intent newIntent = getIntent();
    newIntent.putExtra("title", dateTitleText);
    newIntent.putExtra("beginDate", selectedDate.getTimeInMillis());
    newIntent.putExtra("endDate", finalDate.getTimeInMillis());
    newIntent.putExtra("siteLatBeg", latBeg);
    newIntent.putExtra("siteLonBeg", lonBeg);
    newIntent.putExtra("siteBegText", siteBegTextAutoComp);
    newIntent.putExtra("siteLatDes", latDes);
    newIntent.putExtra("siteLonDes", lonDes);
    newIntent.putExtra("siteDesText", siteText);
    newIntent.putExtra("mobile", mobileInt);
    newIntent.putExtra("email", emailText);
    newIntent.putExtra("duration", duration + extraTime);

    this.setResult(RESULT_OK, newIntent);

    finish();

…………………………………………………………………………

private void scheduleAlarmEnd(long time)
{
        Intent intentAlarm = new Intent(this, EndEventTask.class);

        // create the object
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        PendingIntent pIntent = PendingIntent.getBroadcast(this,
                (int) time,  intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);

        //set the alarm for particular time
        alarmManager.set(AlarmManager.RTC_WAKEUP,time, pIntent);

}

这是我的 Mainfest:

    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/> 

.....................

    <receiver   android:name="com.android.task.BegEventTask">
        <intent-filter>
            <action  android:name="android.intent.action.ACTION_SENDTO" />
        </intent-filter>
    </receiver>

最后在启动意图时出现错误(context.startActivity(EmailActivity);):

07-17 11:37:41.059: E/AndroidRuntime(2647): FATAL EXCEPTION: main
07-17 11:37:41.059: E/AndroidRuntime(2647): java.lang.RuntimeException: Unable to start                 receiver com.android.task.EndEventTask: android.content.ActivityNotFoundException: No     Activity found to handle Intent { act=android.intent.action.SENDTO dat=someemaildirection@gmail.com flg=0x10000000 }
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2287)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.app.ActivityThread.access$1600(ActivityThread.java:140)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.os.Looper.loop(Looper.java:137)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.app.ActivityThread.main(ActivityThread.java:4921)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at java.lang.reflect.Method.invokeNative(Native Method)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at java.lang.reflect.Method.invoke(Method.java:511)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at dalvik.system.NativeStart.main(Native Method)
07-17 11:37:41.059: E/AndroidRuntime(2647): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO dat=someemaildirection@gmail.com flg=0x10000000 }
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1580)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.app.ContextImpl.startActivity(ContextImpl.java:1054)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.app.ContextImpl.startActivity(ContextImpl.java:1043)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:283)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:283)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at com.android.task.EndEventTask.onReceive(EndEventTask.java:31)
07-17 11:37:41.059: E/AndroidRuntime(2647):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2280)
07-17 11:37:41.059: E/AndroidRuntime(2647):     ... 10 more
4

2 回答 2

0
String email = "someemaildirection@gmail.com";

Intent EmailActivity = new Intent(Intent.ACTION_SEND);                                   
//EmailActivity.putExtra(Intent.EXTRA_SUBJECT,
//        "Customer comments/questions");
EmailActivity.putExtra(Intent.EXTRA_EMAIL,email);
String message="Prueba de la aplicación del proyecto.";// message to send
EmailActivity.putExtra(Intent.EXTRA_TEXT, message);
EmailActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(EmailActivity); 
于 2013-07-17T10:08:44.963 回答
0
 String email ="someemaildirection@gmail.com";

 Intent EmailActivity = new Intent(Intent.ACTION_SEND);   
 EmailActivity.setType(plain/text);   // here you have to set mime type                          
 EmailActivity.putExtra(Intent.EXTRA_EMAIL,new String[]{email});
 String message="Prueba de la aplicación del proyecto.";// message to send
 EmailActivity.putExtra(Intent.EXTRA_TEXT, message);
 EmailActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  context.startActivity(EmailActivity); 

//这是工作代码

于 2013-10-11T10:49:25.817 回答