SecurityException。 <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
打开前台服务,需要有通知栏体现:
Intent intent = new Intent(this, ForegroundService.class);
ContextCompat.startForegroundService(this, intent);
要请求让服务运行于前台,在ForegroundService.class里需要调用如下方法启动通知栏:
startForeground(NOTIFICATION_ID, notification);
对非Android SDK API的调用做了限制,通常会出现类似NoSuchClassException或NoSuchFieldException异常。
非SDK API包括Android未公开的底层内部实现细节的API反射调用。还有NDK里未公开的方法调用等。
Android 4.4(API 级别 19)引入了存储访问框架 (SAF)。SAF 让用户能够在其所有首选文档存储提供程序中方便地浏览并打开文档、图像以及其他文件。 用户可以通过易用的标准 UI,以统一方式在所有应用和提供程序中浏览文件和访问最近使用的文件。
自API 19引入SAF后,应用程序无法直接通过java 的File API进行写操作了。需要用到Android 的DocumentFile API 进行间接处理文件。
DocumentFile.fromTreeUri(context,uri)Jcenter and MavenCenter are moden time standar maven center. they maintained by Bintray and sonatype respectively.
As the artical , we just talk abut Bintray’s JCenter. Cause Android Studio now support Jcenter as default maven center.
First of all , you need create an accunt of Binray at Bintray.com and generate an API Key at
Editmenu of account profile
buildscript{
dependencies{
//bintray: jcenter publish build plugin
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
}
}
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'// maven publish method to create groups of artifacts
The bintray plugin supports three methods to create groups of artifacts: Configurations, Publications and Copying specific files using filesSpec. For more read, reference gradle-bintray-plugin.
sources.Jar and javadoc.Jar artifactscreate task as below for android gradle:
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
在firebse 上注册登陆账号,之后注册应用,填写包名等信息,下载配置文件。
google-services.json
| 适用于 Gradle 的说明 | UnityC++Gradle 的 Google 服务插件会加载您刚刚下载的 google-services.json 文件。请修改您的 build.gradle 文件以使用该插件。 |
项目级 build.gradle(<项目>/build.gradle):
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:4.0.0' }
}
应用级 build.gradle(<项目>/<应用模块>/build.gradle):
dependencies {
// Add this line
compile 'com.google.firebase:firebase-core:16.0.0'
}
...
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
默认情况下包含 Analytics
最后,按 IDE 中显示的栏中的“立即同步”:

Android APP 构建脚本采用的是Gradle框架。Gradle是一种构建builde编译框架,采用的是groovy语言。谷歌官方有使用自己的一套builde 插件依赖 配置在project.gradle文件里:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
As following:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /home/jaysen/gems/gems/nokogiri-1.8.4/ext/nokogiri
/usr/bin/ruby2.5 -r ./siteconf20180727-12716-1rv24w0.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.3.0
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/$(RUBY_BASE_NAME)2.5
--help
--clean
--use-system-libraries
--enable-static
--disable-static
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--enable-cross-build
--disable-cross-build
To see why this extension failed to compile, please check the mkmf.log which can
be found here:
/home/jaysen/gems/extensions/x86_64-linux/2.5.0/nokogiri-1.8.4/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/jaysen/gems/gems/nokogiri-1.8.4 for
inspection.
Results logged to
/home/jaysen/gems/extensions/x86_64-linux/2.5.0/nokogiri-1.8.4/gem_make.out
An error occurred while installing nokogiri (1.8.4), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.8.4' --source
'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
github-pages was resolved to 188, which depends on
jekyll-mentions was resolved to 1.4.0, which depends on
html-pipeline was resolved to 2.8.3, which depends on
nokogiri