Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay here's my final code if it can help, thanks to Egor.</p> <p>Note: Two solution are possible to force stopping the player activity:</p> <ol> <li>using <code>startActivityForResult(intent, rq)</code> / <code>finishActivity(rq)</code></li> <li>using <code>FLAG_ACTIVITY_CLEAR_TOP</code></li> </ol> <p>Be careful using <code>finishActivity()</code>, some external apps won't close because of their behavior. For me it worked well when I open videos using VLC player, but not working when I open videos with Dailymotion app.</p> <p><em>ActivityThatLaunchesPlayer.java</em></p> <pre><code>public class ActivityThatLaunchesPlayer extends Activity { private BroadcastReceiver brdreceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { System.out.println("broadcast signal received"); //either finishActivity(57); //57 is my arbitrary requestcode //or either : Intent intentback = new Intent(getApplicationContext(), ActivityThatLaunchesPlayer.class); intentback.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intentback); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //set the brdcstreceiver to listen to the slot getApplicationContext().registerReceiver(brdreceiver, new IntentFilter("com.example.portail10.timeElapsed")); //here we launch the player (android opens a new appropriate activity) Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setData(Uri.parse(uri)); startActivityForResult(intent, 57); //again arbitrary rqstcode //here we start the service that watch the time elapsed watching the video intentServ = new Intent(this, TimeWatcher.class); startService(intentServ); } } </code></pre> <p><em>TimeWatcher.java</em></p> <pre><code>public class TimeWatcher extends Service { //... some code is missing, but the main idea is here @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); timer.scheduleAtFixedRate(new TimerTask() { public void run() { //send the broadcast when time's up Intent intentbrd = new Intent(); intentbrd.setAction("com.example.portail10.timeElapsed"); sendBroadcast(intentbrd); System.out.println("Brdcast sent"); stopSelf(); } }, 0, 600000); //in ms = 10min return START_NOT_STICKY; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload