如何使用cwac-provider启动ACTION_SEND意图?
我尝试了以下代码(来自提供商演示的修改代码)
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("application/pdf");
//i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
i.putExtra(Intent.EXTRA_STREAM, PROVIDER.buildUpon().appendPath("help.pdf").build());
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(i);
//finish();
}
当我选择邮件应用程序发送pdf时,邮件应用程序崩溃了。
java.lang.RuntimeException:无法启动活动ComponentInfo {com.commonsware.cwac.provider.demo /com.commonsware.cwac.provider.demo.MainActivity}:android.content.ActivityNotFoundException:未找到任何活动处理Intent {act = android.intent.action.SEND(has extras)}
下一个代码可以正常工作:
Intent theIntent = new Intent(Intent.ACTION_SEND);
theIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
theIntent.setType("application/pdf");
File f = new File("/mnt/sdcard/task.pdf");
Uri uri = Uri.fromFile(f);
theIntent.putExtra(Intent.EXTRA_STREAM, uri);