Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

addAndroidDownloads can't recognize Android APK file #75

Closed
siyuan opened this issue Aug 7, 2016 · 23 comments
Closed

addAndroidDownloads can't recognize Android APK file #75

siyuan opened this issue Aug 7, 2016 · 23 comments

Comments

@siyuan
Copy link

siyuan commented Aug 7, 2016

I download an APK file using addAndroidDownloads. I click the file but can't open. This is my config.
RNFetchBlob.config({
addAndroidDownloads : {
useDownloadManager : true,
title : 'some apk',
description : 'apk install file',
mime : 'application/vnd.android.package-archive',
mediaScannable : true,
notification : true,
}
})
.fetch('GET', 'http://xxxxxxx/yyy.apk')

How to let Downloads know yyy.apk is an APK file?

@wkh237 wkh237 added the android label Aug 7, 2016
@wkh237
Copy link
Owner

wkh237 commented Aug 7, 2016

@siyuan , thank you for reporting this problem, I've never tried download an APK using DownloadManager, I'll do some tests about this issue.

wkh237 added a commit that referenced this issue Aug 7, 2016
@wkh237 wkh237 added this to the v0.9.0 milestone Aug 7, 2016
@wkh237 wkh237 self-assigned this Aug 7, 2016
@wkh237
Copy link
Owner

wkh237 commented Aug 7, 2016

@siyuan , according to this post and this StackOverflow, perhaps you can not install APK in Downloads App due to some security issue, but it is possible to do it using an intent.

However user still have to change their settings, otherwise it will prompt something like this

2016-08-07 4 11 43

I've added a new API for Android which can send an intent that opens a file in an activity correspond to its MIME type (see test cases for its usage). This API will launch in 0.9.0

@siyuan
Copy link
Author

siyuan commented Aug 9, 2016

@wkh237 Thank you very much for your help. I clone react-native-fetch-blob to node_modules of my project, and checkout to branch 0.9.0. I got this error when compiling:

JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug...

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':app'.

    Cannot evaluate module react-native-fetch-blob : Configuration with name 'default' not found.

Is there any new configuration for version 0.9.0?
Thank you.

@wkh237
Copy link
Owner

wkh237 commented Aug 10, 2016

@siyuan , the error message usually means android/settings.gradle contains wrong project path. Since the git repository contains the whole development environment, I suppose you should copy files in src folder to your node_modules and rename the folder to react-native-fetch-blob instead of copy the whole folder 😏 src is the folder which we publish as npm package.

Alternatively, you can install beta version from npm

$ npm install --save react-native-fetch-blob@beta

Which will install beta release

Beta README.md.

@siyuan
Copy link
Author

siyuan commented Aug 10, 2016

"$ npm install --save react-native-fetch-blob@beta", this method doesn't work. the same as before. It seems that Downloads app can't recognize the new downloaded app.

@siyuan
Copy link
Author

siyuan commented Aug 10, 2016

"copy src to node_modules and rename the folder to react-native-fetch-blob" doesn't work either. I use hardware Android 6.0, Android 6.0 simulator and Android 5.1 simulator do the test. None of them work.

@wkh237
Copy link
Owner

wkh237 commented Aug 11, 2016

@siyuan , The error message means the path it points to does not contains an Android project. did you check android/settings.gradle if there contains a correct path to the android project of react-native-fetch-blob?

rootProject.name = 'RNFetchBlobTest'

include ':app'
+include ':react-native-fetch-blob'                                                                                                                                                   
+project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android'')                                                                

In this case, there should be an Android project in node_modules/react-native-fetch-blob/android/, also check if the path string contains extra space that causes the error (See #62)

As for the installation problem, after upgrade to 0.9.0-beta.x, you should use RNFetchBlob.android.actionViewIntent(path, mime) install the APK, simply click the APK in Downloads app will not work since is not supported.

@siyuan
Copy link
Author

siyuan commented Aug 11, 2016

Thank you for your help.
I can install react-native-fetch-blob@beta and compile successfully, but cannot install the APP. This is my code:

upgradeApp()
  {
    RNFetchBlob.config({
      addAndroidDownloads : {
        useDownloadManager : true,
        mime : 'application/vnd.android.package-archive',
        mediaScannable : true,
        notification : true,
      }
    })
    .fetch('GET', 'http://x.x.x.x/doc/abc.apk')
    .then((res) => {
      console.log('save to ' + res.path())
      let sendIntent = RNFetchBlob.android.actionViewIntent
      return sendIntent(res.path(), 'application/vnd.android.package-archive')
    })
    .then(() => {
      done()
    })    
  }

I found the console output is "save to null". I think this is the problem. Why the path is null?
I appreciate your help. Thank you.

@wkh237
Copy link
Owner

wkh237 commented Aug 11, 2016

Hi, @siyuan , does this happens on Android 6.0 only or it also happens on 5.x ?

@siyuan
Copy link
Author

siyuan commented Aug 11, 2016

Hi, @wkh237
Android 6.0 and 5.1 have this problem with react-native-fetch-blob v0.9 beta.
By the way, react-native-fetch-blob v0.8.1's res.path() is correct.

@wkh237
Copy link
Owner

wkh237 commented Aug 11, 2016

@siyuan , thanks for your information. I think I know where the problem is, I'll publish a test version later !

@wkh237
Copy link
Owner

wkh237 commented Aug 11, 2016

@siyuan , please try 0.9.0-beta.5 and see if the problem got solved

$npm install --save react-native-fetch-blob@beta

Thank you 😄

@siyuan
Copy link
Author

siyuan commented Aug 11, 2016

@wkh237 0.9.0-beta.5's res.path() is null. Tested on 6.0 and 6.1.

@wkh237
Copy link
Owner

wkh237 commented Aug 11, 2016

@siyuan , Since I don't have 6.0 + devices and I can't reproduce the problem on emulator, I'd like to know more information if you can give me a hand !

  • content of res.data
  • the res.type

It would be nice if you have an Android IDE (Android Studio), you can set break points at the following lines

/react-native-fetch-blob/blob/0.9.0-beta.5/src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java#L573

/react-native-fetch-blob/blob/0.9.0-beta.5/src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java#L585

/react-native-fetch-blob/blob/0.9.0-beta.5/src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java#L588

/react-native-fetch-blob/blob/0.9.0-beta.5/src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java#L592

see if they're executed and the value of filePath

@siyuan
Copy link
Author

siyuan commented Aug 11, 2016

@wkh237
res.data /data/user/0/com.android.providers.downloads/cache/abc.apk
res.type undefined

I will study how to set breakpoint in Android Studio.
Thank you.

@wkh237
Copy link
Owner

wkh237 commented Aug 11, 2016

Thank you ! @siyuan , this would be helpful, you can also use res.data as an alternative of res.path()

@siyuan
Copy link
Author

siyuan commented Aug 11, 2016

@wkh237 use res.data still cannot install by sendIntent. I have enabled "Unknown sources, Allow installation of apps from unknown sources"
I'm afraid sendIntent have problem.

@wkh237
Copy link
Owner

wkh237 commented Aug 11, 2016

@siyuan , does it help if you reinstall the package ?

$ rnpm uninstall react-native-fetch-blob
$ npm install --save react-native-fetch-blob@beta
$ rnpm link

then recompile the project

@siyuan
Copy link
Author

siyuan commented Aug 11, 2016

@wkh237 I found my issue happened on
"react": "15.2.0",
"react-native": "^0.28.0",

When I create a new project with 'react-native init', sendIntent works fine ("react": "15.2.1", "react-native": "^0.31.0"). res.path() has right value.

Do you have plan to support old react-native version?

@wkh237
Copy link
Owner

wkh237 commented Aug 12, 2016

@siyuan , thanks for the information. I'll do some test on that version and see if I can fix it. However you can also upgrade you application if possible.

@wkh237
Copy link
Owner

wkh237 commented Aug 12, 2016

@siyuan , it turns out that the API works properly on 0.24~0.31 environments, could you try removing the package from node_modules and reinstall it ? I think the problem might due to the inconsistency between js and native module version in your environment ?

@siyuan
Copy link
Author

siyuan commented Aug 12, 2016

@wkh237
I completely reinstalled my APP. react-native-fetch-blob's intent works fine with "react-native 0.28.0". Thank you very much. I appreciate your help.

@wkh237
Copy link
Owner

wkh237 commented Aug 13, 2016

@siyuan , great 👍 Please feel free to ask any question anytime.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants