├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── libs │ └── tbs_sdk_thirdapp_v3.2.0.1104_43200_sharewithdownload_withfilereader_withoutGame_obfs_20170609_115346.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── windinwork │ │ └── officeapplication │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── test.pptx │ ├── java │ │ └── com │ │ │ └── windinwork │ │ │ └── officeapplication │ │ │ ├── MainActivity.java │ │ │ ├── StorageUtils.java │ │ │ ├── TbsConstant.java │ │ │ ├── TbsReaderAssist.java │ │ │ └── TbsReaderFragment.java │ ├── jniLibs │ │ └── armeabi │ │ │ └── liblbs.so │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── file_provider.xml │ └── test │ └── java │ └── com │ └── windinwork │ └── officeapplication │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches/build_file_checksums.ser 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > 不同于iOS,Android的webView不支持打开office和pdf文档,所以当我们遇到在应用内打开office和pdf文档的需求时,往往无法从系统原生功能去支持。这篇文章的写下笔者在Android应用中集成office和pdf文件能力的心得,附上demo地址:[https://github.com/windinwork/OfficeApplication](https://github.com/windinwork/OfficeApplication) 2 | 3 | ### 一、确定解决方案 4 | 5 | Android应用打开office和pdf文件。常用的有以下四种解决方案: 6 | 1. 在线网页打开文件方案:通过微软或谷歌提供的在线页面打开office和pdf文件 7 | 2. 集成相关文档处理开源库:通过集成开源库类似于AndroidPdfViewer 8 | 3. 通过系统中的第三方应用打开文档 9 | 4. 集成腾讯x5 sdk文件能力 10 | 11 | 四种方案各有优劣,这里笔者选择了x5 sdk为主要手段,第三方应用辅助的这样一种解决方案 12 | 13 | ### 二、集成x5内核 14 | 15 | 腾讯官方提供的x5内核有两个版本,这里选择具有文件能和的sdk: 16 | 17 | 18 | ![](https://user-gold-cdn.xitu.io/2019/1/19/1686501b9e843889?w=1061&h=498&f=png&s=50584) 19 | 20 | 接下来的集成可以参考[x5内核接入文档](https://x5.tencent.com/tbs/guide/sdkInit.html),这里便不详述。集成的主要工作便是集成jar包和so文件,并在Application初始化时调用QbSdk.initX5Environment(context, callback)来完成初始化工作。 21 | 22 | ### 三、集成TbsReader 23 | 24 | x5内核中提供了TbsReaderView,让我们可以通过这个类在App中显示文档。考虑到TbsReaderView这个类具有生命周期的方法,我们把它封装在一个Fragment中,方便我们的调用。TbsReaderView的主要方法有两个,一个是preOpen(String, boolean),另一个是openFile(Bundle)。preOpen(String, boolean)是用来检测x5文件能力是否成功初始化和是否支持打开文件的格式,当符合打开文件的条件时该方法返回true;openFile(Bundle)则是在preOpen(String, boolean)的返回值为true的情况进行调用,顾名思义这个方法是用来打开文件的,其中bundle用来传入文件路径。 25 | 26 | ``` 27 | String path = file.getPath(); 28 | String format = parseFormat(path); 29 | boolean preOpen = mReaderView.preOpen(format, false); // 该状态标志x5文件能力是否成功初始化并支持打开文件的格式 30 | if (preOpen) { // 使用x5内核打开office文件 31 | Bundle bundle = new Bundle(); 32 | bundle.putString("filePath", path); 33 | bundle.putString("tempPath", StorageUtils.getTempDir(context).getPath()); 34 | mReaderView.openFile(bundle); 35 | } 36 | ``` 37 | 38 | 有了这部分核心代码,TbsReaderView基本上就能打开Office和PDF文件了。 39 | 40 | ![](https://user-gold-cdn.xitu.io/2019/1/23/168788349cf04caa?w=1080&h=2280&f=jpeg&s=152346) 41 | 42 | ### 四、完善文件能力 43 | 44 | 市面上的安卓手机各式各样,虽然集成了TbsReaderView,但是还是会收到用户反馈说无法打开Office文件。这是因为用户手机上的x5文件能力没有初始化成功,至于为什么没有初始化成功,原因还无法确定。针对这部分用户,我们需要在他们无法使用TbsReaderView浏览Office文件的情况下,提供另外的途径去打开Office文件。大致思路是检测到TbsReaderView无法打开Office或PDF时,跳转到第三方应用去打开。这里x5的jar包提供了这样一个api:openFileReader(Context, String, HashMap, ValueCallback)用来使用第三方应用打开文件,并且支持前往下载具有Office浏览功能的QQ浏览器,这样的功能对用户比较友好,我们可以直接拿来用。 45 | 46 | 47 | ![](https://user-gold-cdn.xitu.io/2019/1/23/168787ebe9b1ff09?w=380&h=611&f=png&s=19921) 48 | 49 | 然而,x5的jar包中使用第三方应用打开时调用了Uri.fromFile(file),这个生成文件Uri的方法在Android7.0以下有效,但在Android7.0及以上会造成崩溃,这是Android7.0的文件权限管理导致。为了使Android7.0及以上的用户可以正常跳转到第三方应用打开,我们需要使用FileProvider去获取Uri,但代码在Jar包中写死了。幸运的是,经过多次尝试,发现可以将跳转到第三方应用打开的这部分代码复制出来,修正Uri.fromFile(file)的代码以正常调用,免去了要修改jar的麻烦。这里笔者把这部分代码封装在一个叫TbsReaderAssist的类中,辅助调用。 50 | 51 | 这样一来,一个比较完善的打开Office和PDF的功能就算做完成。 52 | 53 | ``` 54 | String path = file.getPath(); 55 | String format = parseFormat(path); 56 | boolean preOpen = mReaderView.preOpen(format, false); // 该状态标志x5文件能力是否成功初始化并支持打开文件的格式 57 | if (preOpen) { // 使用x5内核打开office文件 58 | Bundle bundle = new Bundle(); 59 | bundle.putString("filePath", path); 60 | bundle.putString("tempPath", StorageUtils.getTempDir(context).getPath()); 61 | mReaderView.openFile(bundle); 62 | } else { // 打开文件失败,可能是由于x5内核未成功初始化引起 63 | if (QbSdk.isSuportOpenFile(format, 1)) { // 再次检查文件是否支持 64 | HashMap params = new HashMap<>(); 65 | params.put("style", "1"); 66 | params.put("local", "false"); 67 | TbsReaderAssist.openFileReader(context, path, params, null); 68 | } 69 | } 70 | ``` 71 | 72 | ### 五、总结 73 | 74 | 这里笔者写了一个App打开Office或PDF文件的解决方案,个人认为对于一个App来说是相对完善的处理。这里是demo的地址:[https://github.com/windinwork/OfficeApplication](https://github.com/windinwork/OfficeApplication),共享出来,可以让有需要做类似功能的小伙伴少走些弯路。 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.windinwork.officeapplication" 7 | minSdkVersion 15 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | 13 | // Specifies the ABI configurations of your native 14 | // libraries Gradle should build and package with your APK. 15 | ndk { 16 | abiFilters "armeabi" 17 | } 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | implementation 'com.android.support:appcompat-v7:28.0.0' 30 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 34 | } 35 | -------------------------------------------------------------------------------- /app/libs/tbs_sdk_thirdapp_v3.2.0.1104_43200_sharewithdownload_withfilereader_withoutGame_obfs_20170609_115346.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/libs/tbs_sdk_thirdapp_v3.2.0.1104_43200_sharewithdownload_withfilereader_withoutGame_obfs_20170609_115346.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/windinwork/officeapplication/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.windinwork.officeapplication; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.windinwork.officeapplication", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/assets/test.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/assets/test.pptx -------------------------------------------------------------------------------- /app/src/main/java/com/windinwork/officeapplication/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.windinwork.officeapplication; 2 | 3 | import android.content.Context; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | import java.io.File; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | 13 | public class MainActivity extends AppCompatActivity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | 20 | Context context = this; 21 | 22 | // 将文件从assets目录中复制出来 23 | File file = new File(StorageUtils.getFileDir(context), "test.pptx"); 24 | try { 25 | InputStream inputStream = getAssets().open("test.pptx"); 26 | FileOutputStream fos = new FileOutputStream(file); 27 | 28 | byte[] buffer = new byte[1024]; 29 | int b; 30 | while(-1 != (b = inputStream.read(buffer))) { 31 | fos.write(buffer, 0, b); 32 | } 33 | inputStream.close(); 34 | fos.flush(); 35 | fos.close(); 36 | } catch (IOException e) { 37 | e.printStackTrace(); 38 | } 39 | 40 | // 使用TbsReader打开Office文件 41 | TbsReaderFragment fragment = TbsReaderFragment.newFragment(file.getAbsolutePath()); 42 | 43 | getSupportFragmentManager() 44 | .beginTransaction() 45 | .add(R.id.container, fragment) 46 | .show(fragment) 47 | .commit(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/windinwork/officeapplication/StorageUtils.java: -------------------------------------------------------------------------------- 1 | package com.windinwork.officeapplication; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.NonNull; 5 | 6 | import java.io.File; 7 | 8 | public class StorageUtils { 9 | 10 | /** 11 | * 获取存放文件的文件夹 12 | * @param context 13 | * @return 14 | */ 15 | public static File getFileDir(@NonNull Context context) { 16 | File cache = context.getExternalCacheDir(); 17 | File tmp = new File(cache, "file"); 18 | if (!tmp.exists()) { 19 | tmp.mkdirs(); 20 | } 21 | return tmp; 22 | } 23 | 24 | /** 25 | * 获取临时文件夹 26 | * @param context 27 | * @return 28 | */ 29 | public static File getTempDir(@NonNull Context context) { 30 | File cache = context.getExternalCacheDir(); 31 | File tmp = new File(cache, "tmp"); 32 | if (!tmp.exists()) { 33 | tmp.mkdirs(); 34 | } 35 | return tmp; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/windinwork/officeapplication/TbsConstant.java: -------------------------------------------------------------------------------- 1 | package com.windinwork.officeapplication; 2 | 3 | public class TbsConstant { 4 | 5 | /** 6 | * FileProvider的authorities,用于Android7.0及以上跨应用访问文件 7 | */ 8 | public static final String FILE_PROVIDER = "com.windinwork.officeapplication.fileprovider"; 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/windinwork/officeapplication/TbsReaderAssist.java: -------------------------------------------------------------------------------- 1 | package com.windinwork.officeapplication; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.pm.ApplicationInfo; 6 | import android.content.pm.PackageManager; 7 | import android.content.pm.ResolveInfo; 8 | import android.graphics.Bitmap; 9 | import android.graphics.BitmapFactory; 10 | import android.graphics.Color; 11 | import android.net.Uri; 12 | import android.os.Build; 13 | import android.os.Bundle; 14 | import android.support.annotation.NonNull; 15 | import android.support.v4.content.FileProvider; 16 | import android.text.TextUtils; 17 | import android.util.Log; 18 | 19 | import com.tencent.smtt.sdk.QbSdk; 20 | import com.tencent.smtt.sdk.ValueCallback; 21 | import com.tencent.smtt.sdk.b.a.f; 22 | 23 | import org.json.JSONArray; 24 | import org.json.JSONObject; 25 | 26 | import java.io.File; 27 | import java.util.ArrayList; 28 | import java.util.HashMap; 29 | import java.util.Iterator; 30 | import java.util.List; 31 | import java.util.Map; 32 | import java.util.Set; 33 | 34 | public class TbsReaderAssist { 35 | 36 | public static int openFileReader(Context var0, String var1, HashMap var2, ValueCallback var3) { 37 | if (var1 != null) { 38 | String var4 = var1.substring(var1.lastIndexOf(".") + 1, var1.length()); 39 | if (!a(var0, var1, var4)) { 40 | openFileReaderListWithQBDownload(var0, var1, var3); 41 | return 3; 42 | } 43 | 44 | if (startQBForDoc(var0, var1, 4, 0, var4, a(var0, (Map) var2))) { 45 | if (var3 != null) { 46 | var3.onReceiveValue("open QB"); 47 | } 48 | return 1; 49 | } 50 | 51 | Log.d("QbSdk", "openFileReader startQBForDoc return false"); 52 | } else { 53 | Log.d("QbSdk", "openFileReader QQ browser not installed"); 54 | } 55 | 56 | if (var2 == null) { 57 | var2 = new HashMap(); 58 | } 59 | 60 | var2.put("local", "true"); 61 | openFileReaderListWithQBDownload(var0, var1, var3); 62 | return 3; 63 | } 64 | 65 | public static boolean startQBForDoc(Context var0, String var1, int var2, int var3, String var4, Bundle var5) { 66 | HashMap var6 = new HashMap(); 67 | var6.put("ChannelID", var0.getApplicationContext().getApplicationInfo().processName); 68 | var6.put("PosID", Integer.toString(var2)); 69 | return a(var0, var1, var3, var4, var6, var5); 70 | } 71 | 72 | private static boolean a(Context var0, String var1, String var2) { 73 | Intent var3 = new Intent("com.tencent.QQBrowser.action.sdk.document"); 74 | var3.setDataAndType(fromFile(var0, new File(var1)), "mtt/" + var2); 75 | List var4 = var0.getPackageManager().queryIntentActivities(var3, 0); 76 | boolean var5 = false; 77 | Iterator var6 = var4.iterator(); 78 | 79 | while (var6.hasNext()) { 80 | ResolveInfo var7 = (ResolveInfo) var6.next(); 81 | String var8 = var7.activityInfo.packageName; 82 | if (var8.contains("com.tencent.mtt")) { 83 | var5 = true; 84 | break; 85 | } 86 | } 87 | 88 | return var5; 89 | } 90 | 91 | private static Bundle a(Context var0, Map var1) { 92 | try { 93 | if (var1 == null) { 94 | return null; 95 | } else { 96 | Bundle var2 = new Bundle(); 97 | var2.putString("style", var1.get("style") == null ? "0" : (String) var1.get("style")); 98 | 99 | try { 100 | int var3 = Color.parseColor((String) var1.get("topBarBgColor")); 101 | var2.putInt("topBarBgColor", var3); 102 | } catch (Exception var12) { 103 | ; 104 | } 105 | 106 | if (var1 != null && var1.containsKey("menuData")) { 107 | String var14 = (String) var1.get("menuData"); 108 | JSONObject var4 = null; 109 | var4 = new JSONObject(var14); 110 | JSONArray var5 = var4.getJSONArray("menuItems"); 111 | if (var5 != null) { 112 | ArrayList var6 = new ArrayList(); 113 | 114 | for (int var7 = 0; var7 < var5.length() && var7 < 5; ++var7) { 115 | try { 116 | JSONObject var8 = (JSONObject) var5.get(var7); 117 | int var9 = var8.getInt("iconResId"); 118 | Bitmap var10 = BitmapFactory.decodeResource(var0.getResources(), var9); 119 | var6.add(var7, var10); 120 | var8.put("iconResId", var7); 121 | } catch (Exception var11) { 122 | ; 123 | } 124 | } 125 | 126 | var2.putParcelableArrayList("resArray", var6); 127 | } 128 | 129 | var2.putString("menuData", var4.toString()); 130 | } 131 | 132 | return var2; 133 | } 134 | } catch (Exception var13) { 135 | var13.printStackTrace(); 136 | return null; 137 | } 138 | } 139 | 140 | public static void openFileReaderListWithQBDownload(Context var0, String var1, ValueCallback var2) { 141 | if (var0 != null && !var0.getApplicationInfo().packageName.equals("com.tencent.androidqqmail")) { 142 | String var3 = "选择其它应用打开"; 143 | Intent var4 = new Intent("android.intent.action.VIEW"); 144 | var4.addCategory("android.intent.category.DEFAULT"); 145 | String var5 = com.tencent.smtt.sdk.b.a.i.c(var1); 146 | var4.setDataAndType(fromFile(var0, new File(var1)), var5); 147 | var4.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 148 | QbSdk.isDefaultDialog = false; 149 | f var6 = new f(var0, var3, var4, var2, var5); 150 | String var7 = var6.a(); 151 | if (var7 != null && !TextUtils.isEmpty(var7) && checkApkExist(var0, var7)) { 152 | if ("com.tencent.mtt".equals(var7)) { 153 | var4.putExtra("ChannelID", var0.getApplicationContext().getPackageName()); 154 | var4.putExtra("PosID", "4"); 155 | } 156 | 157 | var4.setPackage(var7); 158 | var0.startActivity(var4); 159 | if (var2 != null) { 160 | var2.onReceiveValue("default browser:" + var7); 161 | } 162 | } else { 163 | if ("com.tencent.rtxlite".equalsIgnoreCase(var0.getApplicationContext().getPackageName()) && QbSdk.isDefaultDialog) { 164 | return; 165 | } 166 | 167 | if (QbSdk.isDefaultDialog) { 168 | if (var2 != null) { 169 | var2.onReceiveValue("can not open"); 170 | } 171 | } else { 172 | var6.show(); 173 | } 174 | } 175 | 176 | } 177 | } 178 | 179 | public static boolean checkApkExist(Context var0, String var1) { 180 | if (var1 != null && !"".equals(var1)) { 181 | try { 182 | // ApplicationInfo var2 = var0.getPackageManager().getApplicationInfo(var1, 8192); 183 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { 184 | ApplicationInfo var2 = var0.getPackageManager().getApplicationInfo(var1, PackageManager.MATCH_UNINSTALLED_PACKAGES); 185 | } else { 186 | ApplicationInfo var2 = var0.getPackageManager().getApplicationInfo(var1, PackageManager.GET_UNINSTALLED_PACKAGES); 187 | } 188 | return true; 189 | } catch (PackageManager.NameNotFoundException var3) { 190 | return false; 191 | } 192 | } else { 193 | return false; 194 | } 195 | } 196 | 197 | public static boolean a(Context var0, String var1, int var2, String var3, HashMap var4, Bundle var5) { 198 | try { 199 | Intent var6 = new Intent("com.tencent.QQBrowser.action.sdk.document"); 200 | if (var4 != null) { 201 | Set var7 = var4.keySet(); 202 | if (var7 != null) { 203 | Iterator var8 = var7.iterator(); 204 | 205 | while (var8.hasNext()) { 206 | String var9 = (String) var8.next(); 207 | String var10 = (String) var4.get(var9); 208 | if (!TextUtils.isEmpty(var10)) { 209 | var6.putExtra(var9, var10); 210 | } 211 | } 212 | } 213 | } 214 | 215 | File var12 = new File(var1); 216 | var6.putExtra("key_reader_sdk_id", 3); 217 | var6.putExtra("key_reader_sdk_type", var2); 218 | if (var2 == 0) { 219 | var6.putExtra("key_reader_sdk_path", var1); 220 | } else if (var2 == 1) { 221 | var6.putExtra("key_reader_sdk_url", var1); 222 | } 223 | 224 | var6.putExtra("key_reader_sdk_format", var3); 225 | var6.setDataAndType(fromFile(var0, var12), "mtt/" + var3); 226 | var6.putExtra("loginType", d(var0.getApplicationContext())); 227 | if (var5 != null) { 228 | var6.putExtra("key_reader_sdk_extrals", var5); 229 | } 230 | 231 | var0.startActivity(var6); 232 | return true; 233 | } catch (Exception var11) { 234 | var11.printStackTrace(); 235 | return false; 236 | } 237 | } 238 | 239 | private static int d(Context var0) { 240 | byte var1 = 26; 241 | String var2 = var0.getApplicationInfo().processName; 242 | if (var2.equals("com.tencent.mobileqq")) { 243 | var1 = 13; 244 | } else if (var2.equals("com.qzone")) { 245 | var1 = 14; 246 | } else if (var2.equals("com.tencent.WBlog")) { 247 | var1 = 15; 248 | } else if (var2.equals("com.tencent.mm")) { 249 | var1 = 24; 250 | } 251 | 252 | return var1; 253 | } 254 | 255 | /** 256 | * 创建 257 | * @param context 258 | * @param file 259 | * @return 260 | */ 261 | private static Uri fromFile(Context context, @NonNull File file) { 262 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 263 | return FileProvider.getUriForFile(context, TbsConstant.FILE_PROVIDER, file); 264 | } else { 265 | return Uri.fromFile(file); 266 | } 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /app/src/main/java/com/windinwork/officeapplication/TbsReaderFragment.java: -------------------------------------------------------------------------------- 1 | package com.windinwork.officeapplication; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.Fragment; 8 | import android.text.TextUtils; 9 | import android.util.Log; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | 14 | import com.tencent.smtt.sdk.QbSdk; 15 | import com.tencent.smtt.sdk.TbsReaderView; 16 | 17 | import java.io.File; 18 | import java.util.HashMap; 19 | 20 | public class TbsReaderFragment extends Fragment { 21 | 22 | private static final String TAG = "TbsReaderFragment"; 23 | private static final String INTENT_PATH = "INTENT_PATH"; 24 | 25 | TbsReaderView mReaderView; 26 | boolean mReaderOpened = false; 27 | 28 | public static TbsReaderFragment newFragment(@NonNull String path) { 29 | TbsReaderFragment fragment = new TbsReaderFragment(); 30 | Bundle arguement = new Bundle(); 31 | arguement.putString(INTENT_PATH, path); 32 | fragment.setArguments(arguement); 33 | return fragment; 34 | } 35 | 36 | @Nullable 37 | @Override 38 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 39 | Context context = getContext(); 40 | mReaderView = new TbsReaderView(context, new TbsReaderView.ReaderCallback() { 41 | @Override 42 | public void onCallBackAction(Integer integer, Object o, Object o1) { 43 | 44 | } 45 | }); 46 | return mReaderView; 47 | } 48 | 49 | @Override 50 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 51 | super.onActivityCreated(savedInstanceState); 52 | 53 | Bundle arguement = getArguments(); 54 | if (arguement != null) { 55 | String path = arguement.getString(INTENT_PATH); 56 | if (!TextUtils.isEmpty(path)) { 57 | tryOpen(new File(path)); 58 | } 59 | } 60 | } 61 | 62 | @Override 63 | public void onDestroy() { 64 | super.onDestroy(); 65 | 66 | if (mReaderView != null) { 67 | mReaderView.onStop(); 68 | } 69 | } 70 | 71 | /** 72 | * @param file 73 | * @return 0: 正常 1: 异常 2: 应用内不支持,需要用QQ插件打开 3: 格式不支持 74 | */ 75 | public int tryOpen(File file) { 76 | if (file == null 77 | || !file.exists()) { 78 | return 1; 79 | } 80 | 81 | if (mReaderOpened) { 82 | resetReaderView(); 83 | } 84 | 85 | int open = open(file); 86 | mReaderOpened = open == 0; 87 | return open; 88 | } 89 | 90 | /** 91 | * 重置状态 92 | */ 93 | private void resetReaderView() { 94 | mReaderView.onStop(); 95 | } 96 | 97 | /** 98 | * @param file 99 | * @return 0: 正常 1: 异常 2: 应用内不支持,使用外部应用打开 3: 不支持的格式 100 | */ 101 | private int open(@NonNull File file) { 102 | if (mReaderView == null) { 103 | return 1; 104 | } 105 | Context context = getContext(); 106 | if (context == null) { 107 | return 1; 108 | } 109 | 110 | String path = file.getPath(); 111 | String format = parseFormat(path); 112 | boolean preOpen = mReaderView.preOpen(format, false); // 该状态标志x5文件能力是否成功初始化并支持打开文件的格式 113 | if (preOpen) { // 使用x5内核打开office文件 114 | Bundle bundle = new Bundle(); 115 | bundle.putString("filePath", path); 116 | bundle.putString("tempPath", StorageUtils.getTempDir(context).getPath()); 117 | mReaderView.openFile(bundle); 118 | return 0; 119 | } else { // 打开文件失败,可能是由于x5内核未成功初始化引起 120 | if (QbSdk.isSuportOpenFile(format, 1)) { // 再次检查文件是否支持 121 | HashMap params = new HashMap<>(); 122 | params.put("style", "1"); 123 | params.put("local", "false"); 124 | TbsReaderAssist.openFileReader(context, path, params, null); // 使用修改后的代码,避免Uri.fromFile(file)在Android7.0及以上的崩溃 125 | return 2; 126 | } else { 127 | Log.e(TAG, "Unsupport format"); 128 | return 3; 129 | } 130 | } 131 | } 132 | 133 | /** 134 | * 解析文件格式 135 | * @param fileName 136 | * @return 137 | */ 138 | private String parseFormat(String fileName) { 139 | return fileName.substring(fileName.lastIndexOf(".") + 1); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/liblbs.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/jniLibs/armeabi/liblbs.so -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OfficeApplication 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/xml/file_provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /app/src/test/java/com/windinwork/officeapplication/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.windinwork.officeapplication; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.2.0' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windinwork/OfficeApplication/d635a301da1c8eca8c2e2b4e77e7f83e723abd56/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------