編輯:關於Android編程
[java]
Intent intent = new Intent("cn.pocketdigi.update.alarm");
intent.setClass(this, AlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(this, 0, intent,0);
//設置一個PendingIntent對象,發送廣播
AlarmManager am=(AlarmManager)getSystemService(ALARM_SERVICE);
//獲取AlarmManager對象
// am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+3500, pi);//只執行一次
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+3500, 10000, pi); //重復執行
Intent intent = new Intent("cn.pocketdigi.update.alarm");
intent.setClass(this, AlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(this, 0, intent,0);
//設置一個PendingIntent對象,發送廣播
AlarmManager am=(AlarmManager)getSystemService(ALARM_SERVICE);
//獲取AlarmManager對象
// am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+3500, pi);//只執行一次
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+3500, 10000, pi); //重復執行
[html]
<receiver android:name=".AlarmReceiver">
<intent-filter>
<action android:name="cn.pocketdigi.update.alarm" />
</intent-filter>
</receiver>
<receiver android:name=".AlarmReceiver">
<intent-filter>
<action android:name="cn.pocketdigi.update.alarm" />
</intent-filter>
</receiver>
[java]
public class AlarmReceiver extends BroadcastReceiver {
private static final String TAG = "AlarmReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.v(TAG, "收到廣播");
// Intent it=new Intent(context,AlarmActivity.class);
// it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(it);
//收到廣播後啟動Activity,簡單起見,直接就跳到了設置alarm的Activity
//intent必須加上Intent.FLAG_ACTIVITY_NEW_TASK flag
}
}
public class AlarmReceiver extends BroadcastReceiver {
private static final String TAG = "AlarmReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.v(TAG, "收到廣播");
// Intent it=new Intent(context,AlarmActivity.class);
// it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(it);
//收到廣播後啟動Activity,簡單起見,直接就跳到了設置alarm的Activity
//intent必須加上Intent.FLAG_ACTIVITY_NEW_TASK flag
}
}
取消方式:
[java]
Intent intent = new Intent("cn.pocketdigi.update.alarm");
intent.setClass(this, AlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(this, 0, intent,0);
AlarmManager alarm=(AlarmManager)getSystemService(ALARM_SERVICE);
alarm.cancel(pi);
Intent intent = new Intent("cn.pocketdigi.update.alarm");
intent.setClass(this, AlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(this, 0, intent,0);
AlarmManager alarm=(AlarmManager)getSystemService(ALARM_SERVICE);
alarm.cancel(pi);
另外一種intent方式
[java]
代碼
Intent intent =new Intent(Main.this, alarmreceiver.class);
intent.setAction("repeating");
PendingIntent sender=PendingIntent
.getBroadcast(Main.this, 0, intent, 0);
//開始時間
long firstime=SystemClock.elapsedRealtime();
AlarmManager am=(AlarmManager)getSystemService(ALARM_SERVICE); //5秒一個周期,不停的發送廣播
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP
, firstime, 5*1000, sender);
代碼
Intent intent =new Intent(Main.this, alarmreceiver.class);
intent.setAction("repeating");
PendingIntent sender=PendingIntent
.getBroadcast(Main.this, 0, intent, 0);
//開始時間
long firstime=SystemClock.elapsedRealtime();
AlarmManager am=(AlarmManager)getSystemService(ALARM_SERVICE); //5秒一個周期,不停的發送廣播
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP
, firstime, 5*1000, sender);
本文實例介紹的Android的Gallery控件是個很不錯的看圖控件,可以大大減輕開發者對於看圖功能的開發,並且效果也很美觀。本文實例中的Gallery的用法,主要實現用
介紹一些, 在Android開發中, 會經常使用的小知識點.1. Download文件夾絕對路徑/storage/emulated/0/Download/xxx遍歷
第1節 ContentProvider介紹ContentProvider是安卓系統的四大組件之一,可以向其他組件提供數據訪問的能力。它就像是一個網站,其他組件(或者其他應
前言在H5火熱的時代,許多框架都出了底部彈窗的控件,在H5被稱為彈出菜單ActionSheet,今天我們也來模仿一個ios的底部彈窗,取材於蘋果QQ的選擇頭像功能。正文廢