Commit ef6c6a6d authored by Albert Vaca Cintora's avatar Albert Vaca Cintora
Browse files

Fix crash opening notifications settings

We were using the device context, which is not suitable to start an
Activity, causing "android.util.AndroidRuntimeException: Calling
startActivity() from outside of an Activity."
parent 8cf39306
......@@ -20,6 +20,7 @@
package org.kde.kdeconnect.Plugins.FindMyPhonePlugin;
import android.app.Activity;
import android.content.Intent;
import org.kde.kdeconnect.Helpers.DeviceHelper;
......@@ -79,7 +80,7 @@ public class FindMyPhonePlugin extends Plugin {
}
@Override
public PluginSettingsFragment getSettingsFragment() {
public PluginSettingsFragment getSettingsFragment(Activity activity) {
return FindMyPhoneSettingsFragment.newInstance(getPluginKey());
}
}
......@@ -21,6 +21,7 @@
package org.kde.kdeconnect.Plugins.NotificationsPlugin;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.RemoteInput;
......@@ -44,7 +45,6 @@ import org.kde.kdeconnect.NetworkPacket;
import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect.Plugins.PluginFactory;
import org.kde.kdeconnect.UserInterface.AlertDialogFragment;
import org.kde.kdeconnect.UserInterface.MainActivity;
import org.kde.kdeconnect.UserInterface.PluginSettingsFragment;
import org.kde.kdeconnect.UserInterface.StartActivityAlertDialogFragment;
import org.kde.kdeconnect_tp.R;
......@@ -91,13 +91,11 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
}
@Override
public PluginSettingsFragment getSettingsFragment() {
public PluginSettingsFragment getSettingsFragment(Activity activity) {
if (hasPermission()) {
Context context = device.getContext();
Intent intent = new Intent(context, NotificationFilterActivity.class);
context.startActivity(intent);
Intent intent = new Intent(activity, NotificationFilterActivity.class);
activity.startActivity(intent);
}
return null;
}
......
......@@ -127,7 +127,7 @@ public abstract class Plugin {
*
* @return The PluginSettingsFragment used to display this plugins settings
*/
public PluginSettingsFragment getSettingsFragment() {
public PluginSettingsFragment getSettingsFragment(Activity activity) {
return PluginSettingsFragment.newInstance(getPluginKey());
}
......
......@@ -231,7 +231,7 @@ public class SharePlugin extends Plugin {
}
@Override
public PluginSettingsFragment getSettingsFragment() {
public PluginSettingsFragment getSettingsFragment(Activity activity) {
return ShareSettingsFragment.newInstance(getPluginKey());
}
......
......@@ -72,7 +72,7 @@ public class DeviceSettingsActivity
} else {
Device device = BackgroundService.getInstance().getDevice(deviceId);
Plugin plugin = device.getPlugin(pluginKey);
fragment = plugin.getSettingsFragment();
fragment = plugin.getSettingsFragment(this);
}
getSupportFragmentManager()
......@@ -112,7 +112,7 @@ public class DeviceSettingsActivity
public void onStartPluginSettingsFragment(Plugin plugin) {
setTitle(getString(R.string.plugin_settings_with_name, plugin.getDisplayName()));
PluginSettingsFragment fragment = plugin.getSettingsFragment();
PluginSettingsFragment fragment = plugin.getSettingsFragment(this);
//TODO: Remove when NotificationFilterActivity has been turned into a PluginSettingsFragment
if (fragment == null) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment