(Please help me) Smartphone is related to screen control.

edited March 9 in Android Mode

Display

PROCESSING GUIDES Hello.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.

I have made this request many times. But there was no answer.

What I want to do is :.

-. Step 1: Execute the application created by processing.

-. Step 2: Press the power button. The screen goes out.

-. Step 3: The screen turns on with an event occurrence.

In other words, how can you make the screen with the cellphone screen turned off?

Requirement 1: I want to turn on when the screen of the cell phone is off.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.

And I ask another one.

-. Step 1: Execute the application created by processing.

-. Step 2: Go to the desktop through the home button.

-. Step 3: A message appears after an event.

Requirement 2: Can I get a message from the home screen instead of the app's screen?

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.

I want the sample code to be available. Thank you very much. Help.

Answers

  • I want the example code to apply immediately.

  • @jeremydouglass

    right. Similar content.

    However, what I want is an example sample with processing language. I want to get even briefly.

  • My guess is that no one has ever done this with Processing so there isn't any sample code.

  • @hudson_m4000=== i have already answered to this question (see the link given by @jeremydouglass) && i have code for that. Yet till now i haven't seen any line of code and cannot help...

  • right. Similar content.

    Identical content! So you've started a new question and ignored all the previous answers. Why?

  • Additionally, this sounds like an assignment (see requirements in previous thread - "You will create an application program to monitor...") Your urgency backs this up. Don't expect us to do your projects.

  • @akenaton, @koogs,

    I really appreciate your answers.

    But I finally answered.

    I want the complete sample code. I want the entire code, not just one block at a time.

    If I had good ability, I would not even ask questions.

    I am missing the full sample code.

    That is why I ask.

    It is not ignoring you. I do not understand.

    So, I will ask. I want to get the example code.

  • and we don't know the example code.

    and if we did, it depends on YOUR CODE which we haven't seen.

    a quick google throws up this: https://play.google.com/store/apps/details?id=com.lukekorth.screennotifications&hl=en_GB

    which is open source and has a github repo in the description.

    the main class of which appears to be this:

    https://github.com/lkorth/screen-notifications/blob/master/ScreenNotifications/src/main/java/com/lukekorth/screennotifications/helpers/ScreenController.java

    line 76 contains a method called 'turnOnScreen()' which uses PowerManager,Wakelock

  • @Gwak

    The expertise for this kind of projects is very limited in this forum as you can see. You are better off using stackoverflow. For your specific case, contributions are done base on provide code.

    @akenaton has provided code fragments/chunks based on Android's current concepts and based on limited information you have provided in your posts. It is very clear you want a full example and the forum does not have any of this kind as yet.

    I can see this topic evolving if you post what you have tried so far. In your case, I suggest you describe your challenge fully once more. Please be very descriptive and also add a link to stackoverflow to have a larger audience contributing to your question.

    Kf

  • @Gwak=== put the code you have already written for what you want.

  • @koogs, @kfrajer, @akenaton

    In conclusion, can not you control through processing?

    Is that right?

    I can only get error messages when I go through processing.

    So, is it not reproducible by processing? If possible, would not it be possible to have a separate library?

    Is my idea wrong?

  • edited March 10
    import android.os.PowerManager.WakeLock;
    import android.os.PowerManager;
    import android.content.Context;
    import android.os.Build;
    
    
    void setup(){  
      size(1000,1000);  
    }
    
    void draw(){  
     int a = second();  println(a);  
     if( a == 30){
    
     PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
     PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");
     wl.acquire();
    
    
    }
        delay(1000);    
    }
    

    Error :

    1. ERROR in C:\Users\wee\AppData\Local\Temp\android3923934803870586499sketch\src\processing\test\tft\tft.java (at line 42) PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); ^^^^^^^^^^^^^^^^ The method getSystemService(String) is undefined for the type tft
  • so tft is your app?

    getSystemService isn't defined.

    it's a method on Context. you need a Context.

  • edited March 10 Answer ✓

    @koogs, & @Gwak===

    you are not in an activity, you are in a fragment, so you have to get the context from the activity which has committed the fragment. So to get rid of this error:

    write:

    PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); 
     PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");
     wl.acquire();
    

    and add to imports::

    import android.app.Activity;
    import android.content.Context;
    

    then i think that it is better to use PARTIAL_WAKE_LOCK (but i am not sure about that as i am not sure to understand what you are coding)

  • @akenaton, Your right.

    The power manager seems to be controlling the CPU.

      For example, you open a smartphone app.   And even if you turn off your smartphone, it continues to perform internal calculations.

      However, the screen can not automatically be turned on.

    First,

    PowerManager pm = (PowerManager)     getActivity().getSystemService(Context.POWER_SERVICE); 
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");
    wl.acquire();
    

    This code only works with the CPU.

    Second,

          PowerManager.WakeLock wakeLock =  mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "Screen Notifications");
                    wakeLock.acquire();
    

    This also does not force the screen.

    Do not you have a command to force your cellphone screen off? Make sure your smartphone's screen is on

  • So, I think

      WindowManager.LayoutParams lp = act.getWindow().getAttributes(); 
      lp.screenBrightness = val; 
      act.getWindow().setAttributes(lp);
    

    But it seems that this is not possible either.

  • qq

    Both methods work when the program is on.

    The screen that I say is turned off is an event when the power of the phone is pressed once.

    When the display is off, it should turn on after an event occurs.

    However, this code can not be executed.

  • @akenaton

    Dear akenaton,

    You are genius. Thank you very much.

    Power manager & setBrightness = success

    You are a great genius.

    By the way, there is one problem. Turn on the application and turn off the screen. And it works after the event occurs.

    However, the problem is not possible even after pressing the home button.

    Is there a way to do this?

    The way you've told me is that the app must be running.

    What I want is that the app is always running. Do you have a way?

  • @Gwak===

    as long your app is running you can reset the screen brightness when any kind of events happens; when you press the back or home button your app is in pause, it cannot capture events except those based upon services: alarm manager for instance.

  • @akenaton

    import android.content.Context;
    import android.app.AlarmManager;
    import android.app.ActivityManager;
    import android.app.ActivityManager.MemoryInfo ;
    import android.app.Activity;
    import java.util.GregorianCalendar;
    import java.util.Calendar;
    
        Long time = new GregorianCalendar().getTimeInMillis()+12*1000;
        intentAlarm = new Intent(Intent.ACTION_SCREEN_ON);
        alarmMgr =  (AlarmManager) act1.getSystemService(Context.ALARM_SERVICE);    
        alarmMgr.set(AlarmManager.RTC_WAKEUP,time, PendingIntent.getBroadcast(act1 ,1,  intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
    

    I tried setting it through an alarm. Not yet. There is no error, but there is no real control.

    What do you think about that?

  • @Gwak=== this code seems to be good; now you have to write a receiver either with an inner class or creating a new one (better but not so simple with P5); dont forget to declare your receiver in the manifest with the intent filter you are using.

Sign In or Register to comment.