Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wangshengxi committed Mar 7, 2018
0 parents commit f1f93d2
Show file tree
Hide file tree
Showing 44 changed files with 1,689 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
22 changes: 22 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
30 changes: 30 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "cn.samuelnotes.keepalive"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.coolerfall:android-app-daemon:1.2.0'
compile 'com.android.support:appcompat-v7:23.+'
testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /androidsdk/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cn.samuelnotes.keepalive;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("cn.samuelnotes.keepalive", appContext.getPackageName());
}
}
119 changes: 119 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.samuelnotes.keepalive">


<!--SyncAdapter 权限配置 start-->

<!-- Required to register a SyncStatusObserver to display a "syncing..." progress indicator. -->
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<!-- Required to enable our SyncAdapter after it's created. -->
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<!-- Required because we're manually creating a new account. -->
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />

<!--SyncAdapter 权限配置 end-->


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
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>


<!--添加的权限控制只有JobScheduler才能运行它。-->
<service
android:name=".service.JobHandlerService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />


<!--SyncAdapter 配置 start -->

<!--
ContentProvider to store feed data.
The "authorities" here are defined as part of a ContentProvider interface. It's used here
as an attachment point for the SyncAdapter. See res/xml/syncadapter.xml and
SyncService.java.
Since this ContentProvider is not exported, it will not be accessible outside of this app's
package.
-->
<provider
android:name=".syncadapter.FeedProvider"
android:authorities="cn.samuelnotes.android.network.sync.basicsyncadapter"
android:exported="false" />

<!--
This service implements our SyncAdapter. It needs to be exported, so that the system
sync framework can access it.
-->
<service
android:name=".syncadapter.SyncService"
android:exported="true">

<!--
This intent filter is required. It allows the system to launch our sync service
as needed.
-->
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<!-- This points to a required XML file which describes our SyncAdapter. -->
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>

<!--
This implements the account we'll use as an attachment point for our SyncAdapter. Since
our SyncAdapter doesn't need to authenticate the current user (it just fetches a public RSS
feed), this account's implementation is largely empty.
It's also possible to attach a SyncAdapter to an existing account provided by another
package. In that case, this element could be omitted here.
-->
<service android:name=".syncadapter.GenericAccountService">

<!-- Required filter used by the system to launch our account service. -->
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<!-- This points to an XMLfile which describes our account service. -->
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
<!--SyncAdapter 配置 end -->


<service
android:name=".service.DaemonService"
android:exported="true"
android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE"
android:process=":daemon">
<intent-filter>
<action android:name="android.service.chooser.ChooserTargetService" />
<action android:name="com.google.android.gms.iid.InstanceID" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="android.content.SyncAdapter" />
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<!--<intent-filter>-->
<!--<action android:name="android.content.SyncAdapter"/>-->
<!--</intent-filter>-->
</service>

</application>

</manifest>
35 changes: 35 additions & 0 deletions app/src/main/java/cn/samuelnotes/keepalive/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cn.samuelnotes.keepalive;

import android.content.Intent;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import cn.samuelnotes.keepalive.service.DaemonService;
import cn.samuelnotes.keepalive.service.JobHandlerService;
import cn.samuelnotes.keepalive.syncadapter.SyncUtils;
import cn.samuelnotes.keepalive.utils.Config;


/**
* create by samuelnotes
* 这里添加小米机型判断是因为, 当时项目做的这个保活主要就是为了唤醒推送,提高推送到达率。 小米机型有自己的推送sdk ,so,,
*/
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


// if (!Config.PHONETYPE.equals(Build.MANUFACTURER)) {

// startService(new Intent(this, JobHandlerService.class));
startService(new Intent(this, DaemonService.class));
SyncUtils.CreateSyncAccount(getApplicationContext());
// }


}
}
Loading

0 comments on commit f1f93d2

Please sign in to comment.