在无法在Oreo 8.0中运行的其他应用程序上共享图像

时间:2018-08-12 06:29:10

标签: java android

我正在使用此代码在Whatsapp,Facebook和Instagram等上共享图像。 此代码在API 25以下可以正常工作,但在API 25以上不能正常工作。

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   '-g',
1 verbose cli   'acorn' ]
2 info using npm@5.6.0
3 info using node@v8.11.3
4 verbose npm-session 0648b6c8ae8267c4
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 304 https://registry.npmjs.org/acorn 896ms (from cache)
8 silly pacote tag manifest for acorn@latest fetched in 954ms
9 silly install loadIdealTree
10 silly install cloneCurrentTreeToIdealTree
11 silly install loadShrinkwrap
12 silly install loadAllDepsIntoIdealTree
13 silly resolveWithNewModule acorn@5.7.1 checking installable status
14 silly currentTree npm
15 silly idealTree npm
15 silly idealTree `-- acorn@5.7.1
16 silly install generateActionsToTake
17 silly diffTrees action count 1
18 silly diffTrees add acorn@5.7.1
19 silly decomposeActions action count 8
20 silly decomposeActions fetch acorn@5.7.1
21 silly decomposeActions extract acorn@5.7.1
22 silly decomposeActions preinstall acorn@5.7.1
23 silly decomposeActions build acorn@5.7.1
24 silly decomposeActions install acorn@5.7.1
25 silly decomposeActions postinstall acorn@5.7.1
26 silly decomposeActions finalize acorn@5.7.1
27 silly decomposeActions refresh-package-json acorn@5.7.1
28 silly install executeActions
29 silly doSerial global-install 8
30 verbose correctMkdir C:\Users\Babar Baig\AppData\Roaming\npm-cache\_locks correctMkdir not in flight; initializing
31 verbose lock using C:\Users\Babar Baig\AppData\Roaming\npm-cache\_locks\staging-51cfd9b4628f34cb.lock for C:\Users\Babar Baig\AppData\Roaming\npm\node_modules\.staging
32 silly doParallel extract 8
33 silly extract acorn@5.7.1
34 silly pacote trying acorn@https://registry.npmjs.org/acorn/-/acorn-5.7.1.tgz by hash: sha512-d+nbxBUGKg7Arpsvbnlq61mc12ek3EY8EQldM3GPAhWJ1UVxC6TDGbIvUMNU6obBX3i1+ptCIzV4vq0gFPEGVQ==
35 silly pacote acorn@https://registry.npmjs.org/acorn/-/acorn-5.7.1.tgz extracted to C:\Users\Babar Baig\AppData\Roaming\npm\node_modules\.staging\acorn-4f034420 by content address 24ms
36 silly doReverseSerial unbuild 8
37 silly doSerial remove 8
38 silly doSerial move 8
39 silly doSerial finalize 8
40 silly finalize C:\Users\Babar Baig\AppData\Roaming\npm\node_modules\acorn
41 silly doParallel refresh-package-json 8
42 silly refresh-package-json C:\Users\Babar Baig\AppData\Roaming\npm\node_modules\acorn
43 silly doParallel preinstall 8
44 silly preinstall acorn@5.7.1
45 info lifecycle acorn@5.7.1~preinstall: acorn@5.7.1
46 silly doSerial build 8
47 silly build acorn@5.7.1
48 info linkStuff acorn@5.7.1
49 silly linkStuff acorn@5.7.1 has C:\Users\Babar Baig\AppData\Roaming\npm\node_modules as its parent node_modules
50 silly linkStuff acorn@5.7.1 is part of a global install
51 silly linkStuff acorn@5.7.1 is installed into a global node_modules
52 silly linkStuff acorn@5.7.1 is installed into the top-level global node_modules
53 verbose linkBins acorn@5.7.1
54 verbose linkBins [ { acorn: './bin/acorn' },
54 verbose linkBins   'C:\\Users\\Babar Baig\\AppData\\Roaming\\npm',
54 verbose linkBins   true ]
55 verbose linkMans acorn@5.7.1
56 verbose unlock done using C:\Users\Babar Baig\AppData\Roaming\npm-cache\_locks\staging-51cfd9b4628f34cb.lock for C:\Users\Babar Baig\AppData\Roaming\npm\node_modules\.staging
57 verbose stack Error: ENOENT: no such file or directory, chmod 'C:\Users\Babar Baig\AppData\Roaming\npm\node_modules\acorn\bin\acorn'
58 verbose cwd C:\Users\Babar Baig\Desktop\Angular
59 verbose Windows_NT 10.0.17134
60 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "acorn"
61 verbose node v8.11.3
62 verbose npm  v5.6.0
63 error path C:\Users\Babar Baig\AppData\Roaming\npm\node_modules\acorn\bin\acorn
64 error code ENOENT
65 error errno -4058
66 error syscall chmod
67 error enoent ENOENT: no such file or directory, chmod 'C:\Users\Babar Baig\AppData\Roaming\npm\node_modules\acorn\bin\acorn'
68 error enoent This is related to npm not being able to find a file.
69 verbose exit [ -4058, true ]

4 个答案:

答案 0 :(得分:1)

首先请确保您已添加权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

然后使用此代码

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
Uri imageUri =  Uri.parse(this.imgUrl);                                
share.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(share, "Select"));

答案 1 :(得分:0)

如果targetSdkVersion高于24,则使用Provider授予访问权限。

创建一个xml文件:res \ xml \ provider_paths.xml

1. Shell Scripting Tutorial for Beginners 1 -  Introduction
https://www.youtube.com/watch?v=cQepf9fY6cE&list=PLS1QulWo1RIYmaxcEqw5JhK3b-6rgdWO_&index=2&t=0s
--------------------------------------------------------------------------------
2. Shell Scripting Tutorial for Beginners 2 - using Variables and Comments
https://www.youtube.com/watch?v=vQv4W-JfrmQ&list=PLS1QulWo1RIYmaxcEqw5JhK3b-6rgdWO_&index=3&t=0s
--------------------------------------------------------------------------------
3. Shell Scripting Tutorial for Beginners 3 - Read User Input
https://www.youtube.com/watch?v=AcSkkNAsGCY&list=PLS1QulWo1RIYmaxcEqw5JhK3b-6rgdWO_&index=4&t=0s
--------------------------------------------------------------------------------

... all the way to:

32. How Install VirtualBox Guest Additions on Ubuntu 18.04 Guest / virtual machine
https://www.youtube.com/watch?v=qNecdUsuTPw&list=PLS1QulWo1RIYmaxcEqw5JhK3b-6rgdWO_&index=33&t=0s
--------------------------------------------------------------------------------
33. How to install Java JDK 10 on Ubuntu 18.04 LTS (Debian Linux)
https://www.youtube.com/watch?v=4RJ60fqeTN4&list=PLS1QulWo1RIYmaxcEqw5JhK3b-6rgdWO_&index=34&t=0s
--------------------------------------------------------------------------------

现在在AndroidManifest.xml文件中添加提供程序

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>

并将其替换为您的代码

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/provider_paths"/>
</provider>

更新

Intent share = new Intent("android.intent.action.SEND");
            share.setType("image/jpeg");
Uri uri = FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID+ ".provider",new File(this.imgUrl));
            share.putExtra("android.intent.extra.STREAM", uri);

            startActivity(Intent.createChooser(share, "via"));

答案 2 :(得分:0)

尝试一下:

Intent shareIntent = new Intent();
     shareIntent.setAction(Intent.ACTION_SEND); 
     shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage); 
     shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent,getResources().getText(R.string.send_to)));

答案 3 :(得分:0)

  

使用文件提供程序获取 IMAGE URI ,并将标志添加到   意向...

请仔细执行以下步骤。.android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()此更新自牛轧糖以来就已完成。.