典型的notification一例——“点击Notification,打开浏览器”
来源:互联网 发布:matlab编程stephen 编辑:程序博客网 时间:2024/04/30 00:04
1. 本例功能: 点击Notification,打开浏览器
2. 代码:
public static void showNotification(Context context, strUrl) {
final int NOTIFY_ID = 999;
NotificationManager manager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification myNoti = new Notification();
myNoti.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = getBrowserAppIntent(context,strUrl);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
myNoti.tickerText = "Notify";
myNoti.icon = R.drawable.ic_launcher;
//myNoti.defaults = Notification.DEFAULT_SOUND;
myNoti.setLatestEventInfo(context,
context.getString(R.string.app_name), strUrl,
pendingIntent);
manager.notify(NOTIFY_ID, myNoti);
//manager.cancel(NOTIFY_ID);
return;
}
private static Intent getBrowserAppIntent(Context context,String strUrl) {
ActivityInfo browserActivity = getBrowserMainActivity(context);
if (browserActivity != null) {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_uri_browsers = Uri.parse(strUrl);
intent.setData(content_uri_browsers);
intent.setClassName(browserActivity.packageName, browserActivity.name);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
return null;
}
private static ActivityInfo getBrowserApp(Context context) {
String default_browser = "android.intent.category.DEFAULT";
String browsable = "android.intent.category.BROWSABLE";
String view = "android.intent.action.VIEW";
Intent intent = new Intent(view);
intent.addCategory(default_browser);
intent.addCategory(browsable);
Uri uri = Uri.parse("http://");
intent.setDataAndType(uri, null);
// 找出手机当前安装的所有浏览器程序
List<ResolveInfo> resolveInfoList = context.getPackageManager()
.queryIntentActivities(intent,
PackageManager.GET_INTENT_FILTERS);
if (resolveInfoList.size() > 0) {
ActivityInfo activityInfo = resolveInfoList.get(0).activityInfo;
String packageName = activityInfo.packageName;
String className = activityInfo.name;
Log.i(TAG, "packageName " + packageName);
Log.i(TAG, "className " + className);
return activityInfo;
} else {
return null;
}
}
3. 补充与说明:
1) intent也可以用setCompnent来设置。
2)注意获取browser应用的方式
3) intent的各种属性的设置。
- 典型的notification一例——“点击Notification,打开浏览器”
- 点击notification不重新打开activity
- Notification(Notification的通知栏常驻、Notification的各种样式、Notification点击无效)
- Notification(一)——基础知识使用示例
- Android——Notification(一)
- Notification(一)
- 关于Notification的一系列问题(一)
- Notification的使用(一)
- ANDROID之路-Android_点击Notification打开一个Activity的两种方式
- 关于点击一个notification后,都会打开Activity的路径设置
- notification点击跳转的两种情况
- android笔记,点击notification时的跳到栈顶
- android-Notification点击跳转指定的Activity
- 通知的点击跳转(Notification)
- Android Notification(一) Notification 的 requestCode 与 id
- Notification —— 通知
- 通知——Notification
- statusbar—NOTIFICATION
- 田亮晒森碟与海豚亲吻照 父女开心超有爱
- Windows下用python备份MySQL数据库
- tornado websocket
- ASIHTTPRequest 详解
- sdadsa
- 典型的notification一例——“点击Notification,打开浏览器”
- 查看 MySQL 数据库中每个表占用的空间大小
- C#学习之接口
- Input Controls-Pickers
- [Unity3D] 关于触屏用Ray来Hit场景中GameObject的笔记
- 工厂模式
- ISO8601:2004 数据存储和交换形式·信息交换·日期和时间的表示方法
- 二、PYTHON 学习笔记之multiprocessing
- intervalSince1970 to String