以前在学习AlarmManager里面会遇到PendingIntent,相信大家都知道Intent是你的意图,比如你想启动一个Activity,就会通过 Intent来描述启动这个Activity的某些特点,让系统找到这个Activity来启动,而不是启动别的 Activity.StartActivity(intent)就会立即启动这个Activity.而PendingIntent呢?Penging中文意思就是:待定,将来发生或来临。PendingIntent的就的意思就是不是像Intent那样立即发生,而是在合适的时候才会去触发对应的
Intent.有人说这个intent不是你的ap来触发而是交给别的ap来触发。你可以看以下的code来理解:
这是在PackageInstaller的代码
java代码:
private class ClearCacheReceiver extends BroadcastReceiver {
public static final String INTENT_CLEAR_CACHE ="com.android.packageinstaller.CLEAR_CACHE";
@Override
public void onReceive(Context context, Intent intent) {
Message msg = mHandler.obtainMessage(FREE_SPACE);
msg.arg1 = (getResultCode() ==1) ? SUCCEEDED : FAILED;
mHandler.sendMessage(msg);
}
}
java代码:
private void checkOutOfSpace(long size) {
if(localLOGV) Log.i(TAG, "Checking for "+size+" number of bytes");
if (mClearCacheReceiver == null) {
mClearCacheReceiver = new ClearCacheReceiver();
}
registerReceiver(mClearCacheReceiver,new IntentFilter(ClearCacheReceiver.INTENT_CLEAR_CACHE));
PendingIntent pi = PendingIntent.getBroadcast(this,0, new Intent(ClearCacheReceiver.INTENT_CLEAR_CACHE), 0);
mPm.freeStorage(size, pi.getIntentSender());
}
以下是在PackageManagerService的:
java代码:
public void freeStorageAndNotify(final long freeStorageSize, final IPackageDataObserver observer) {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.CLEAR_APP_CACHE, null);
// Queue up an async operation since clearing cache may take a little while.
mHandler.post(new Runnable() {
public void run() {
mHandler.removeCallbacks(this);
int retCode = -1;
if (mInstaller != null) {
retCode = mInstaller.freeCache(freeStorageSize);
if (retCode < 0) {
Slog.w(TAG, "Couldn't clear application caches");
}
} //end if mInstaller
if (observer != null) {
try {
observer.onRemoveCompleted(null, (retCode >= 0));
} catch (RemoteException e) {
Slog.w(TAG, "RemoveException when invoking call back");
}
}
}
});
}
相关推荐
主要介绍了Android中pendingIntent的深入分析的相关资料,需要的朋友可以参考下
要用 android.app.PendingIntent.getBroadcast(Context context, int requestCode, Intent intent)来实现控制多个闹钟,关键点在于其中的一个参数requestCode. 举例说明如下: public void setClock(){ if(lva....
Android Proximity Alert 手机接近进警告或提示功能一例 LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); //定义接近区域的大致经度、纬度 double longitude = 113.39; ...
归纳了Intent入 的4种形式:Intent转换与复制、 Action/Component/Data注 、PendingIntent误用与 parseUri注 入 归纳了利用自动化的工具具发现这4类形式的方法,通过批 量的扫描,可以轻易发现这些漏洞 在每种都找到了...
import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; /*必需引用telephony.gsm.SmsManager类才能使用sendTextMessage()*/ import android.telephony.SmsManager; ...
本文实例为大家分享了Intent实现页面跳转的两种的方法,供大家参考,具体内容如下 下图中两个不同的方法就是两种页面之间跳转的情况 1).跳转不返回数据 2).跳转返回数据 实例: 第一种启动方式(跳转不返回数据) ...
Intent itSend = new Intent(SMS_SEND_ACTIOIN); Intent itDeliver = new Intent(SMS_DELIVERED_ACTION); PendingIntent mSendPI = PendingIntent.getBroadcast(context, 0, itSend, 0); ...
import android.app.PendingIntent; import android.app.TimePickerDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.S
pendingIntent=PendingIntent.getActivity(MainActivity.this, 0, intent, 0); calendar=Calendar.getInstance(); alarmManager=(AlarmManager) getSystemService(ALARM_SERVICE); } public void...
double latitude, double longitude, float radius, long expiration, PendingIntent intent) 添加一个趋近警告 getAllProviders() 获得所有的LocationProvider列表 getBestProvider(Criteria criteria, ...
AlarmManager实质是一个全局的定时器,是Android中常用的一种系统级别的提示服务,在指定时间或周期性启动其它组件(包括Activity,Service,BroadcastReceiver)。本文将讲解一下如何使用AlarmManager实现定时提醒...
1.5.6 Android媒体和电话组件 1.5.7 Android Java包 1.6 利用Android源代码 1.7 本书的示例项目 1.8 小结 第2章 设置开发环境 2.1 设置环境 2.1.1 下载JDK 6 2.1.2 下载Eclipse 3.6 ...
Android 创建备忘录的例子,可自定义备忘录内容,自定义时间和自定义提醒闹钟的类型、铃声等。相关代码: c.setTimeInMillis(System.currentTimeMillis());//设置当前时间 c.set(Calendar.HOUR_OF_DAY, ...
另一个是利用Intent传递广播的Intent的时候,传参数的时候,记得设置PendingIntent sender=PendingIntent.getBroadcast(context,0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);的PendingIntent.FLAG_UPDATE_...
8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过网络播放MP3——Runnable存储FileOutputStream技巧 8.9 设置远程下载音乐为手机铃声——RingtoneManager与铃声存放路径 8.10 ...
8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过网络播放MP3——Runnable存储FileOutputStream技巧 8.9 设置远程下载音乐为手机铃声——RingtoneManager与铃声存放路径 8.10 ...
Android 使用TimePickerDialog设置闹钟的例子,dialog=new TimePickerDialog(//创建TimePickerDialog对象 this, new TimePickerDialog.OnTimeSetListener(){ //创建OnTimeSetListener监听器 @Override ...
这个例子演示Android 在状态栏添加Notification信息图标及提示,相信大家对这个功能已经不陌生了,手机中安装的APP,一般都会在后台运行,时不时会在手机顶部的状态栏中显示应用的图标,滑出状态栏会看到详细的信息...
8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过网络播放MP3——Runnable存储FileOutputStream技巧 8.9 设置远程下载音乐为手机铃声——RingtoneManager与铃声存放路径 8.10 ...