我正在使用一个AlarmManager触发广播信号的意图.以下是我的代码:
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(this, Wakeup.class);
try
{
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
Long elapsed += // sleep time;
mgr.set(AlarmManager.RTC_WAKEUP, elapsed, pi);
}
catch(Exception r)
{
Log.v(TAG, "RunTimeException: " + r);
}
Run Code Online (Sandbox Code Playgroud)
我从一个调用这个代码Activity,所以我不知道如何得到以下错误...
ERROR/AndroidRuntime(7557): java.lang.RuntimeException: Unable to start receiver com.wcc.Wakeup: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Run Code Online (Sandbox Code Playgroud) 我在该应用程序中有图像厨房应用程序我将所有图像放入drawable-hdpi文件夹中.我在我的活动中调用了这样的图像:
private Integer[] imageIDs = {
R.drawable.wall1, R.drawable.wall2,
R.drawable.wall3, R.drawable.wall4,
R.drawable.wall5, R.drawable.wall6,
R.drawable.wall7, R.drawable.wall8,
R.drawable.wall9, R.drawable.wall10
};
Run Code Online (Sandbox Code Playgroud)
所以现在我想知道我如何使用共享Intent我分享这些图像我推出的共享代码如下:
Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + imageIDs);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
}
});
Run Code Online (Sandbox Code Playgroud)
当我点击分享按钮时我也有共享按钮分享框正在打开但当我克服任何服务时,大多数崩溃或一些服务说:无法打开图像所以我怎么能解决这个问题或者是否有任何其他格式代码来共享图像????
编辑:
我尝试使用下面的代码.但它不起作用.
Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("android.resource://com.android.test/*");
try { …Run Code Online (Sandbox Code Playgroud) 我想在电子邮件正文中添加图片.我不想将图像附加到电子邮件中,而是在电子邮件正文中添加图像.
这该怎么做?
我正在使用它.
"<img src=\"data:image/png;base64,"+convertFileTOByteEncrypt()+"\">"
Run Code Online (Sandbox Code Playgroud)
要么
"<img src=\"http://images.anandtech.com/doci/3982/HTCSurround-0134.jpg\">"
Run Code Online (Sandbox Code Playgroud)
然后图像显示如下.

我在这个网站上看到多个线程讨论在android中发送带附件的电子邮件.我想讨论的每一个方法在这里,这里和这里.
我正在通过代码创建一个csv文件并将此文件保存到android内部存储.然后我想在电子邮件中将此文件作为附件发送.嗯,电子邮件正在发送,我收到它没有附件.这就是我所做的.
String columnString = "\"Person\",\"Gender\",\"Street1\",\"PostOfice\",\"Age\"";
String dataString = "\"" + currentUser.userName +"\",\"" + currentUser.gender + "\",\"" + currentUser.street1 + "\",\"" + currentUser.poNumber.toString() + "\",\"" + currentUser.age.toString() + "\"";
String combinedString = columnString + "\n" + dataString;
File file = new File(this.getCacheDir()+ File.separator + "Data.csv");
try {
FileOutputStream out = new FileOutputStream(file);
out.write(combinedString.getBytes());
out.close();
} catch (IOException e) {
Log.e("BROKEN", "Could not write file " + e.getMessage());
}
Uri u1 = Uri.fromFile(file);
Intent sendIntent …Run Code Online (Sandbox Code Playgroud) 我正在尝试用Intent选择多个文件,但似乎我缺少某些东西.
我创建了一个Intent.ACTION_GET_CONTENT Intent,将Intent.EXTRA_ALLOW_MULTIPLE作为额外的
(它似乎完全符合目的)并创建一个选择器(可选),它选择应该能够选择多个文件并返回它们的应用程序.
问题是我只能选择一个文件.
我试过多个文件浏览器.这是API 18(4.3).
ACTIVITY_CHOOSE_FILE = 1; //global constant
Button btn = (Button) this.findViewById(R.id.btnGetFiles);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent chooseFile;
Intent intent;
chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.setType("file/*");
chooseFile.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent = Intent.createChooser(chooseFile, "Choose a file");
startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);
}
});
Run Code Online (Sandbox Code Playgroud)
我还将此添加到Manifest(它在添加之前具有相同的功能):
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
为什么我不能选择多个文件?
(澄清:问题不在于,多个文件没有返回 - 我不能选择多个文件)
//EMAIL SENDING CODE FROM ASSET FOLDER
email = editTextEmail.getText().toString();
subject = editTextSubject.getText().toString();
message = editTextMessage.getText().toString();
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("file/html");
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://com.example.deepa.xmlparsing/file:///android_assets/Combination-1.html"));
startActivity(Intent.createChooser(emailIntent, "Send email using"));
Run Code Online (Sandbox Code Playgroud)
最后,我从资产文件夹(Combination-1.html)获取文件.
它越来越好了
找不到运行时错误文件异常.
有没有其他方式发送文件附件?
我想通过eMail发送几个文件.我发现这个 Android多个电子邮件附件使用Intent,但它确实有效,我没有收到任何错误消息.它只是不附加文件(我也尝试只发送一个文件,但我得到了相同的结果).
我有没有监督过什么?你有什么建议吗?
private static void email (Context context, String emailTo, String emailCC,
String subject, String emailText, List<String> filePaths)
{
//need to "send multiple" to get more than one attachment
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/xml");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{emailTo});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText);
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (String file : filePaths)
{
File fileIn = new File(file);
// Uri u = Uri.fromFile(fileIn);
Uri …Run Code Online (Sandbox Code Playgroud) 我通过我的申请发送邮件.为此,我使用以下代码.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
它只是工作正常,但我想附加一个xml文件.可能吗?怎么样?