Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>If</strong> you have the correct permission (see below), you can do this with the <code>AlarmManager</code>. For example, to set the time to 2013/08/15 12:34:56, you could do:</p> <pre><code>Calendar c = Calendar.getInstance(); c.set(2013, 8, 15, 12, 34, 56); AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.setTime(c.getTimeInMillis()); </code></pre> <hr> <p>You need the permission <code>SET_TIME</code> to do this. Unfortunately, this is a <a href="http://developer.android.com/guide/topics/manifest/permission-element.html" rel="noreferrer"><code>signatureOrSystem</code></a> permission.</p> <p>Definition in <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2.2_r1/frameworks/base/core/res/AndroidManifest.xml/" rel="noreferrer">AndroidManifest.xml:</a></p> <pre><code> &lt;!-- Allows applications to set the system time --&gt; &lt;permission android:name="android.permission.SET_TIME" android:protectionLevel="signature|system" android:label="@string/permlab_setTime" android:description="@string/permdesc_setTime" /&gt; </code></pre> <hr> <p>The only apps that can use this permission are:</p> <ul> <li>Signed with the system image</li> <li>Installed to the <code>/system/</code> folder</li> </ul> <p>Unless you build custom ROMs, you're out of luck with the first. </p> <p>For the second, it depends on what you are doing. </p> <ul> <li><p>If you're building an app for wide distribution (<a href="https://en.wikipedia.org/wiki/Google_Play" rel="noreferrer">Google Play</a>, etc.), you probably shouldn't. It's only an option for root users, and you'll only be able to install it manually. Any marketplace would not install it to the correct location.</p></li> <li><p>If you're building an app for yourself (or just as a learning exercise), go for it. You'll need a rooted phone, though, so do that first. You can then install the application straight to <code>/system/app/</code> with <a href="http://en.wikipedia.org/wiki/Android_Debug_Bridge" rel="noreferrer">ADB</a> or a file manager. See articles <a href="http://www.androidauthority.com/install-user-app-as-system-app-how-to-93522/" rel="noreferrer">like this</a> for more detail.</p></li> </ul> <hr> <p>One final note: The <code>SET_TIME</code> permission and <code>AlarmManager#setTime()</code> were added in Android 2.2 (<code>API 8</code>). If you're trying to do this on a previous version, I'm not sure it will work at all.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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