mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-03 17:02:13 +01:00
Pebble: Fix screenshots for Android N
This was a regression only in master since we switched to SDK 25 This commit also fixes all other warnings with AbstractDeviceSupport.java
This commit is contained in:
parent
e392fbfd80
commit
05a28cc580
@ -347,6 +347,16 @@
|
|||||||
android:authorities="com.getpebble.android.provider"
|
android:authorities="com.getpebble.android.provider"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="android.support.v4.content.FileProvider"
|
||||||
|
android:authorities="${applicationId}.screenshot_provider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/screenshot_provider_paths"/>
|
||||||
|
</provider>
|
||||||
|
|
||||||
<receiver android:name=".SleepAlarmWidget">
|
<receiver android:name=".SleepAlarmWidget">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
|
@ -26,6 +26,8 @@ import android.content.Intent;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.support.v4.content.FileProvider;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.telephony.SmsManager;
|
import android.telephony.SmsManager;
|
||||||
|
|
||||||
@ -37,6 +39,7 @@ import java.io.IOException;
|
|||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
@ -145,7 +148,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleGBDeviceEvent(GBDeviceEventMusicControl musicEvent) {
|
private void handleGBDeviceEvent(GBDeviceEventMusicControl musicEvent) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got event for MUSIC_CONTROL");
|
LOG.info("Got event for MUSIC_CONTROL");
|
||||||
Intent musicIntent = new Intent(GBMusicControlReceiver.ACTION_MUSICCONTROL);
|
Intent musicIntent = new Intent(GBMusicControlReceiver.ACTION_MUSICCONTROL);
|
||||||
@ -154,7 +157,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
context.sendBroadcast(musicIntent);
|
context.sendBroadcast(musicIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleGBDeviceEvent(GBDeviceEventCallControl callEvent) {
|
private void handleGBDeviceEvent(GBDeviceEventCallControl callEvent) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got event for CALL_CONTROL");
|
LOG.info("Got event for CALL_CONTROL");
|
||||||
Intent callIntent = new Intent(GBCallControlReceiver.ACTION_CALLCONTROL);
|
Intent callIntent = new Intent(GBCallControlReceiver.ACTION_CALLCONTROL);
|
||||||
@ -163,7 +166,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
context.sendBroadcast(callIntent);
|
context.sendBroadcast(callIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleGBDeviceEvent(GBDeviceEventVersionInfo infoEvent) {
|
protected void handleGBDeviceEvent(GBDeviceEventVersionInfo infoEvent) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got event for VERSION_INFO");
|
LOG.info("Got event for VERSION_INFO");
|
||||||
if (gbDevice == null) {
|
if (gbDevice == null) {
|
||||||
@ -174,7 +177,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
gbDevice.sendDeviceUpdateIntent(context);
|
gbDevice.sendDeviceUpdateIntent(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleGBDeviceEvent(GBDeviceEventAppInfo appInfoEvent) {
|
private void handleGBDeviceEvent(GBDeviceEventAppInfo appInfoEvent) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got event for APP_INFO");
|
LOG.info("Got event for APP_INFO");
|
||||||
|
|
||||||
@ -190,7 +193,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(appInfoIntent);
|
LocalBroadcastManager.getInstance(context).sendBroadcast(appInfoIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleGBDeviceEvent(GBDeviceEventSleepMonitorResult sleepMonitorResult) {
|
private void handleGBDeviceEvent(GBDeviceEventSleepMonitorResult sleepMonitorResult) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got event for SLEEP_MONIOR_RES");
|
LOG.info("Got event for SLEEP_MONIOR_RES");
|
||||||
Intent sleepMontiorIntent = new Intent(ChartsHost.REFRESH);
|
Intent sleepMontiorIntent = new Intent(ChartsHost.REFRESH);
|
||||||
@ -203,7 +206,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleGBDeviceEvent(GBDeviceEventScreenshot screenshot) {
|
private void handleGBDeviceEvent(GBDeviceEventScreenshot screenshot) {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss", Locale.US);
|
||||||
String filename = "screenshot_" + dateFormat.format(new Date()) + ".bmp";
|
String filename = "screenshot_" + dateFormat.format(new Date()) + ".bmp";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -211,7 +214,8 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
Bitmap bmp = BitmapFactory.decodeFile(fullpath);
|
Bitmap bmp = BitmapFactory.decodeFile(fullpath);
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(android.content.Intent.ACTION_VIEW);
|
intent.setAction(android.content.Intent.ACTION_VIEW);
|
||||||
intent.setDataAndType(Uri.fromFile(new File(fullpath)), "image/*");
|
Uri screenshotURI = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".screenshot_provider", new File(fullpath));
|
||||||
|
intent.setDataAndType(screenshotURI, "image/*");
|
||||||
|
|
||||||
PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
|
|
||||||
@ -222,20 +226,20 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
PendingIntent pendingShareIntent = PendingIntent.getActivity(context, 0, Intent.createChooser(shareIntent, "share screenshot"),
|
PendingIntent pendingShareIntent = PendingIntent.getActivity(context, 0, Intent.createChooser(shareIntent, "share screenshot"),
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
Notification notif = new Notification.Builder(context)
|
NotificationCompat.Action action = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_share, "share", pendingShareIntent).build();
|
||||||
|
|
||||||
|
Notification notif = new NotificationCompat.Builder(context)
|
||||||
.setContentTitle("Screenshot taken")
|
.setContentTitle("Screenshot taken")
|
||||||
.setTicker("Screenshot taken")
|
.setTicker("Screenshot taken")
|
||||||
.setContentText(filename)
|
.setContentText(filename)
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setStyle(new Notification.BigPictureStyle()
|
.setStyle(new NotificationCompat.BigPictureStyle()
|
||||||
.bigPicture(bmp))
|
.bigPicture(bmp))
|
||||||
.setContentIntent(pIntent)
|
.setContentIntent(pIntent)
|
||||||
.addAction(android.R.drawable.ic_menu_share, "share", pendingShareIntent)
|
.addAction(action)
|
||||||
|
.setAutoCancel(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
notif.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
||||||
|
|
||||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.notify(NOTIFICATION_ID_SCREENSHOT, notif);
|
nm.notify(NOTIFICATION_ID_SCREENSHOT, notif);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@ -288,7 +292,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleGBDeviceEvent(GBDeviceEventBatteryInfo deviceEvent) {
|
protected void handleGBDeviceEvent(GBDeviceEventBatteryInfo deviceEvent) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got BATTERY_INFO device event");
|
LOG.info("Got BATTERY_INFO device event");
|
||||||
gbDevice.setBatteryLevel(deviceEvent.level);
|
gbDevice.setBatteryLevel(deviceEvent.level);
|
||||||
|
4
app/src/main/res/xml/screenshot_provider_paths.xml
Normal file
4
app/src/main/res/xml/screenshot_provider_paths.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<external-path name="external_files" path="."/>
|
||||||
|
</paths>
|
Loading…
Reference in New Issue
Block a user