请在阅读前不要将其标记为重复
我已经在stackoverflow和Github上的所有链接中进行了搜索,找到了可能的答案,但是仍然遇到相同的错误。
以下是清单文件:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:authorities="com.example.aditya.pdf_report"
android:exported="false" android:grantUriPermissions="true"
android:name="android.support.v4.content.FileProvider"
android:readPermission="com.company.aditya.pdf_report.READ">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
</application>
这是Java文件:
File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/pdf_report/" + reportname.getText().toString().trim() + ".pdf" );
Uri path;
path = FileProvider.getUriForFile(MainActivity.this, getPackageName(),filelocation);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Here is the Branch Visit Report - Human Resources");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
这是file-paths.xml:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="pdf_report" path="pdf_report/"/>
</paths>
这是我的包裹名称:
com.example.aditya.pdf_report
这是我的手机上保存Pdf的位置:
Environment.getExternalStorageDirectory().getAbsolutePath() + "/pdf_report"
我已经浏览了所有链接,但我认为它是我写错东西的文件paths.xml
答案 0 :(得分:0)
如下更改您的<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external_files"
path="." />
</paths>
。可能有用。
cont=(EditText)findViewById(R.id.editcontact);
final String MobilePattern = "[0-9]{10}";
btn_log=(Button)findViewById(R.id.button_log);
btn_log.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String phn=cont.getText().toString();
if (!phn.matches(MobilePattern)) {
Toast.makeText(LoginActivity.this, "Invalid Contact number", Toast.LENGTH_SHORT).show();
} else {
Intent i = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(i);
}
}
});