mirror of
https://github.com/bilde2910/Hauk.git
synced 2026-07-28 10:13:57 +00:00
Return to app from notification; fixes #27
This commit is contained in:
parent
a4e3255cb5
commit
d3a0b02ad9
4 changed files with 34 additions and 3 deletions
|
|
@ -14,7 +14,9 @@
|
|||
android:roundIcon="@drawable/ic_icon"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
|
@ -27,7 +29,7 @@
|
|||
</receiver>
|
||||
<receiver android:name=".notify.StopSharingReceiver" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="info.varden.hauk.RETURN_TO_APP" />
|
||||
<action android:name="info.varden.hauk.STOP_SHARING" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<service android:name=".service.LocationPushService" android:enabled="true">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package info.varden.hauk.notify;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* A intent for tapping the persistent Hauk notification to return to the app.
|
||||
*
|
||||
* @author Marius Lindvall
|
||||
*/
|
||||
public class ReopenIntent {
|
||||
private final Context ctx;
|
||||
private final Class<? extends Activity> activity;
|
||||
|
||||
public ReopenIntent(Context ctx, Class <? extends Activity> activity) {
|
||||
this.ctx = ctx;
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public PendingIntent toPending() {
|
||||
Intent intent = new Intent(this.ctx, this.activity);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
return PendingIntent.getActivity(this.ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import info.varden.hauk.MainActivity;
|
||||
import info.varden.hauk.R;
|
||||
import info.varden.hauk.StopSharingTask;
|
||||
|
||||
|
|
@ -54,6 +55,7 @@ public class SharingNotification extends HaukNotification {
|
|||
// Add "Copy link" and "Stop sharing" buttons to the notification.
|
||||
builder.addAction(R.drawable.ic_notify, getContext().getString(R.string.action_copy), new Receiver<>(getContext(), CopyLinkReceiver.class, this.viewUrl).toPending());
|
||||
builder.addAction(R.drawable.ic_notify, getContext().getString(R.string.action_stop), new Receiver<>(getContext(), StopSharingReceiver.class, this.stopSharingTask).toPending());
|
||||
builder.setContentIntent(new ReopenIntent(getContext(), MainActivity.class).toPending());
|
||||
|
||||
builder.setOngoing(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import info.varden.hauk.StopSharingTask;
|
|||
*/
|
||||
public class StopSharingReceiver extends HaukBroadcastReceiver<StopSharingTask> {
|
||||
|
||||
public static final String ACTION_ID = "info.varden.hauk.RETURN_TO_APP";
|
||||
public static final String ACTION_ID = "info.varden.hauk.STOP_SHARING";
|
||||
|
||||
@Override
|
||||
public String getActionID() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue