add foreground service permission / run download web pages in other process

This commit is contained in:
David Luhmer 2018-10-30 22:00:11 +01:00
parent da5d1f873b
commit 0ec6b16602
3 changed files with 29 additions and 17 deletions

View file

@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="de.luhmer.owncloudnewsreader" package="de.luhmer.owncloudnewsreader"
android:installLocation="internalOnly" android:installLocation="internalOnly"
android:versionCode="134" android:versionCode="135"
android:versionName="0.9.9.19"> android:versionName="0.9.9.19.1">
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
@ -18,6 +18,7 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" /> <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" /> --> <!-- <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" /> -->
<application <application
@ -46,15 +47,15 @@
<activity <activity
android:name=".NewsDetailActivity" android:name=".NewsDetailActivity"
android:configChanges="keyboardHidden|orientation|screenSize" android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_news_detail"></activity> android:label="@string/title_activity_news_detail" />
<activity <activity
android:name=".SettingsActivity" android:name=".SettingsActivity"
android:configChanges="keyboardHidden|orientation|screenSize" android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_settings"></activity> android:label="@string/title_activity_settings" />
<activity android:name=".DownloadImagesActivity"></activity> <activity android:name=".DownloadImagesActivity" />
<activity <activity
android:name=".SyncIntervalSelectorActivity" android:name=".SyncIntervalSelectorActivity"
android:label="@string/title_activity_sync_interval_selector"></activity> android:label="@string/title_activity_sync_interval_selector" />
<activity <activity
android:name=".NewFeedActivity" android:name=".NewFeedActivity"
android:label="@string/title_activity_new_feed" android:label="@string/title_activity_new_feed"
@ -119,9 +120,6 @@
<service <service
android:name=".services.SyncItemStateService" android:name=".services.SyncItemStateService"
android:permission="android.permission.BIND_JOB_SERVICE" /> android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name=".services.DownloadWebPageService"
android:permission="android.permission.BIND_JOB_SERVICE" />
<service <service
android:name=".services.OwnCloudAuthenticatorService" android:name=".services.OwnCloudAuthenticatorService"
android:exported="true"> android:exported="true">
@ -150,7 +148,7 @@
android:name=".providers.OwnCloudSyncProvider" android:name=".providers.OwnCloudSyncProvider"
android:authorities="de.luhmer.owncloudnewsreader" android:authorities="de.luhmer.owncloudnewsreader"
android:label="@string/auto_sync_string" android:label="@string/auto_sync_string"
android:syncable="true"></provider> android:syncable="true" />
<provider <provider
android:name="android.support.v4.content.FileProvider" android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider" android:authorities="${applicationId}.provider"
@ -170,7 +168,13 @@
<!-- android:theme="@style/Theme.Transparent" > --> <!-- android:theme="@style/Theme.Transparent" > -->
<!-- </activity> --> <!-- </activity> -->
<receiver android:name=".helper.NotificationActionReceiver"> <service
android:name=".services.DownloadWebPageService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:process=":downloadWebPageProcess"/>
<receiver
android:name=".helper.NotificationActionReceiver"
android:process=":downloadWebPageProcess">
<intent-filter> <intent-filter>
<action android:name="YES_ACTION"/> <action android:name="YES_ACTION"/>
<action android:name="STOP_ACTION"/> <action android:name="STOP_ACTION"/>

View file

@ -833,26 +833,30 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
return true; return true;
case R.id.menu_download_web_archive: case R.id.menu_download_web_archive:
startDownloadWebPagesForOfflineReading(); checkAndStartDownloadWebPagesForOfflineReadingPermission();
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void startDownloadWebPagesForOfflineReading() { private void checkAndStartDownloadWebPagesForOfflineReadingPermission() {
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(Manifest.permission.FOREGROUND_SERVICE) == PackageManager.PERMISSION_GRANTED) {
Log.v("Permission error","You have permission"); Log.v("Permission error","You have permission");
startDownloadWebPagesForOfflineReading();
} else { } else {
Log.e("Permission error","Asking for permission"); Log.e("Permission error","Asking for permission");
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_PERMISSION_DOWNLOAD_WEB_ARCHIVE); requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.FOREGROUND_SERVICE}, REQUEST_CODE_PERMISSION_DOWNLOAD_WEB_ARCHIVE);
return; return;
} }
} } else { //you dont need to worry about these stuff below api level 23
else { //you dont need to worry about these stuff below api level 23
Log.v("Permission error","You already have the permission"); Log.v("Permission error","You already have the permission");
startDownloadWebPagesForOfflineReading();
}
} }
private void startDownloadWebPagesForOfflineReading() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(new Intent(this, DownloadWebPageService.class)); startForegroundService(new Intent(this, DownloadWebPageService.class));
} else { } else {

View file

@ -106,6 +106,10 @@ public class PodcastPlaybackService extends Service {
mHandler.postDelayed(mUpdateTimeTask, 0); mHandler.postDelayed(mUpdateTimeTask, 0);
// TODO: add
// startForeground(NOTIFICATION_ID, podcastNotification);
super.onCreate(); super.onCreate();
} }