我一直在尝试如何为我的应用程序发出通知,以打开不同的应用程序,如收件箱。我只看到如何打开特定的活动,不知道是否可以打开整个应用程序。Android:如何通过我的通知打开其他应用程序?
0
A
回答
1
是的。有可能的。你只需要正确配置你的意图。
注意
最终用户可能没有安装所需的应用程序。所以,你必须实现的方法来控制......
但无论如何,可以打开从您自己的通知
例
不同的应用程序,我创建下面的例子为WhatsApp的。我用this question作为参考。
Notification.Builder notiBuilder = new Notification.Builder(this);
Intent intent = null;
/*
START
Configure your intent here.
Example below opens the whatspp.. I got this example from https://stackoverflow.com/questions/15462874/sending-message-through-whatsapp/15931345#15931345
You must update it to open the app that you want.
If the app is not found, intent is null and then, click in notification won't do anything
*/
PackageManager pm=getPackageManager();
try {
PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.whatsapp");
intent.setType("text/plain");
} catch (PackageManager.NameNotFoundException e) {
// Package not found
intent = null;
e.printStackTrace();
}
/* END */
if(intent != null) {
PendingIntent clickPendingIntent = PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notiBuilder.setContentTitle("Title")
.setSmallIcon(R.drawable.common_google_signin_btn_icon_light)
.setContentText("Message")
.setContentIntent(clickPendingIntent)
.setLights(Color.BLUE, 3000, 3000);
} else {
notiBuilder.setContentTitle("Title")
.setSmallIcon(R.drawable.common_google_signin_btn_icon_light)
.setContentText("Message")
.setLights(Color.BLUE, 3000, 3000);
}
Notification mNotificationBar = notiBuilder.build();
mNotificationBar.flags |= Notification.DEFAULT_SOUND;
mNotificationBar.flags |= Notification.FLAG_SHOW_LIGHTS;
mNotificationBar.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mNotificationBar);
打开拨号
只需配置意图象下面这样:
intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"));
+0
很酷,这个帮了很多! – TCTBO
0
相关问题
- 1. 通过其他应用程序打开Facebook应用程序
- 2. 如何通过我的Android应用程序打开PDF文件?
- 3. 如何打开已通知通知栏的应用程序?
- 4. 从通知中打开其他应用程序
- 5. 通知Android:当应用程序打开时不显示通知?
- 6. Android通知开始时,我曾打开应用程序
- 7. Android - 如何停止显示通知时打开应用程序
- 8. 打开其他Android应用程序
- 9. 如何通过点击Toast通知打开我的应用程序时从Toast通知中获取数据?
- 10. 我们如何才能在android中访问其他应用程序的通知?
- 11. 从通知中打开应用程序
- 12. GCM - 从通知打开应用程序?
- 13. 如何不让用户通过点击通知来打开应用程序?
- 14. 如何通过按keboard键打开我的C#应用程序?
- 15. XAMARIN Android C#如何通过应用程序打开浏览器
- 16. 访问其他应用的android通知
- 17. 如何通过URL方案从应用程序打开通知中心?
- 18. 通过绕过登录打开其他应用程序的内部页面
- 19. 如何获取其他应用程序的通知图标?
- 20. 如何停止从android中的其他应用程序打开应用程序?
- 21. 如何在任何其他应用程序使用或打开相机时通知我
- 22. Android显示应用程序未打开时的通知?
- 23. 通过EMail打开IOS应用程序
- 24. 通过URL打开vimeo应用程序
- 25. 通过URL打开YouKu应用程序
- 26. 如何使用我的应用程序打开其他活动应用程序?
- 27. 如何打开我们的应用程序中的其他应用程序iphone
- 28. 如何通过点击自定义URL来打开我的Android应用程序?
- 29. 打开应用程序时更新应用程序通知
- 30. Trigger.IO:知道什么时候通过推送通知打开应用程序
我认为这是可能的。你只需要正确配置意图...但我从来没有尝试过..所以,我无法确认 – W0rmH0le
Android中没有“完整的应用程序”。这类似于询问如何从您的网页链接到“整个网站”。考虑到您知道与PackageManager一起使用的应用程序ID(“包名称”),您可以为应用程序启动启动器活动。由于并非所有人都使用Google Inbox,因此您需要一些方法让用户决定应该打开哪个应用程序。 – CommonsWare