How can I do in Xcode the java code mentioned in the question?

Asked

Viewed 92 times

1

This class on Android when enabled, I can close the app that keeps it running and keep Cell’s screen lit this way

Keep the screen on:

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "watever");
    wl.acquire();

//Complete code:

public class StreamService extends Service {
private static final String TAG = "StreamService";


SharedPreferences prefs;
SharedPreferences.Editor editor;
Notification n;
NotificationManager notificationManager;
int notifId = 5315;
PowerManager.WakeLock wl;
IBinder b;

@Override
public IBinder onBind(Intent arg0) {
    int x = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
    arg0.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    return b;

}

@SuppressWarnings("deprecation")
@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "onCreate");
    //FAZ A TELA FICAR LIGADA. . ._
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "watever");
    wl.acquire();
    //__
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    editor = prefs.edit();
    notificationManager = (NotificationManager) getApplicationContext()
            .getSystemService(NOTIFICATION_SERVICE);
    Context context = getApplicationContext();
    String notifTitle = context.getResources().getString(R.string.app_name);
    String notifMessage = context.getResources().getString(R.string.buffering);
    n = new Notification();
    n.icon = R.drawable.icon;
    n.tickerText = "screen ON";
    n.when = System.currentTimeMillis();
    Intent nIntent = new Intent(context, MainActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(context, 0, nIntent, 0);
    n.setLatestEventInfo(context, notifTitle, notifMessage, pIntent);
    notificationManager.notify(notifId, n);
}
@SuppressWarnings("deprecation")
@Override
public void onStart(Intent intent, int startId) {
    Log.d(TAG, "onStart");
    editor.putBoolean("isPlaying", true);
    editor.commit();
    Context context = getApplicationContext();
    String notifMessage = context.getResources().getString(R.string.now_playing);
    n.icon = R.drawable.icon;
    n.tickerText = notifMessage;
    n.flags = Notification.FLAG_NO_CLEAR;
    n.when = System.currentTimeMillis();
    Intent nIntent = new Intent(context, MainActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(context, 0, nIntent, 0);
}

@Override
public void onDestroy() {
    Log.d(TAG, "onDestroy");
    notificationManager.cancel(notifId);
}
}

The goal is to close the app and keep the screen on, remaining in the notifications an option to re-open the app and deny this process when desired..

If someone can help me how can I do something similar to a class extends servise in Xcode and a method similar to keeping the screen on, every hint is valid.

  • try to post what you have already managed to do or what part of the code is most difficult so we can help you effectively.

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.