我对我的问题进行了重大更新,因为有些误解.
所以,我有一个通知.当我点击该通知时,我希望文件浏览器应用程序(当然是第三方应用程序)打开.无论应用程序是什么,如果有超过文件浏览器,它应该提示“打开” – 然后打开/ sdcard /文件夹(如果可能)
我在Listar.class上的通知
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_menu_save, msg, System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Open.class), 0);
notification.setLatestEventInfo(this, filename+" downloaded", "Click to open folder", contentIntent);
manager.notify(1, notification);
我的Open课程就在这里:
public class Open extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
Intent intent = new Intent("org.openintents.action.PICK_FILE");
startActivityForResult(intent, 1);
}
catch(Exception e)
{
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
Log.v("EX",e.toString());
}
}
}
这打开了oi文件管理器(没有“打开” – 我没有选择默认应用程序)和/ sdcard,这就是我需要你帮助的原因.
解决方法:
Intent toLaunch = new Intent();
toLaunch.setAction(android.content.Intent.ACTION_VIEW);
toLaunch.setDataAndType(Uri.fromFile(new File("file_path")), MimeTypeMap.getSingleton().getMimeTypeFromExtension("jpeg")); // you can also change jpeg to other types
而不是:
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Open.class), 0);
写:
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, toLaunch , 0);
标签:android,java,notifications
来源: https://codeday.me/bug/20190903/1795728.html