简体   繁体   English

通知栏 - 单击时,如何打开具有指定位置的文件资源管理器

[英]Notification bar - when clicked, how to open file explorer with specified location

I did a major update of my question because some misunderstandings.由于一些误解,我对我的问题进行了重大更新。

So, I have a notification.所以,我有一个通知。 And when I click that notification, I want the file explorer app (third party app of course) opens.当我单击该通知时,我希望打开文件资源管理器应用程序(当然是第三方应用程序)。 No matter whuch app is, if there's more than on file explorers, it should prompt the "open with" - and then open /sdcard/folder (if possible)无论是哪个应用程序,如果文件资源管理器不止一个,它应该提示“打开方式” - 然后打开 /sdcard/folder(如果可能)

My notification it's here on Listar.class我的通知在 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);

and my Open class it's here:和我的 Open class 它在这里:

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());
    }
    }

}

This opens oi file manager (without "open with" - i didnt chose default app) and to /sdcard, that's why i need your help.这将打开 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

and instead of:而不是:

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Open.class), 0);

write:写:

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, toLaunch , 0);

Notifications are designed to launch activities.通知旨在启动活动。 In your case, you are launching Listar.class.在您的情况下,您将启动 Listar.class。 That class should do the action you require, such as opening / displaying a file. class 应该执行您需要的操作,例如打开/显示文件。

http://developer.android.com/reference/android/app/PendingIntent.html should describe the purpose of the PendingIntent that you have constructed. http://developer.android.com/reference/android/app/PendingIntent.html应该描述您构建的 PendingIntent 的用途。

If you wanting to find out if a specific intent exists (eg the package is installed) you can use something like this...如果您想了解是否存在特定意图(例如安装了 package),您可以使用类似这样的东西......

/**
 * Checks the system to see if the passed intent package exists.
 * 
 * @param pIntent
 *            intent to be checked
 * @return true if the package exists
 */
private final boolean checkIfPackageExists( final Intent pIntent ) {
    // Build package manager
    final PackageManager packageManager = this.getPackageManager();
    final List<ResolveInfo> list = packageManager.queryIntentActivities( pIntent, PackageManager.MATCH_DEFAULT_ONLY );

    return list.size() > 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM