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)
My notification it's here on 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);
not开发者_如何学编程ification.setLatestEventInfo(this, filename+" downloaded", "Click to open folder", contentIntent);
manager.notify(1, notification);
and my Open class it's here:
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.
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. That class should do the action you require, such as opening / displaying a file.
http://developer.android.com/reference/android/app/PendingIntent.html should describe the purpose of the PendingIntent that you have constructed.
If you wanting to find out if a specific intent exists (e.g. the package is installed) you can use something like this...
/**
* 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;
}
精彩评论