How to open gallery via intent without result?

前端 未结 4 2150
后悔当初
后悔当初 2020-12-17 05:46

I have a kind of an ApplicationLauncher that has to start the build-in gallery. But I don\'t want to get any result from that gallery. I just want to start it and want my &q

相关标签:
4条回答
  • 2020-12-17 06:12

    Since it doesn't seem to be possible to open the gallery via an Intent to just browse pictures (without the intent to select one which is then passed back to your application) like when starting the gallery from the launcher, the only solution I found is to explicitly state the package and Activity name in the Intent. For example:

    // For Android 4.0 (Samsung Galaxy Nexus)
    final Intent intent = new Intent();
    intent.setClassName("com.google.android.gallery3d", "com.android.gallery3d.app.Gallery");
    startActivity(intent);
    

    or

    // For Samsung Galaxy S2
    final Intent intent = new Intent();
    intent.setClassName("com.cooliris.media", "com.cooliris.media.Gallery");
    startActivity(intent);
    

    Of course this solution isn't flexible at all and you would have to keep a list of package/activity names in your application and sending Intents (catching ActivityNotFoundException) until you found the right one.

    0 讨论(0)
  • 2020-12-17 06:13

    I just want to start it and want my "Launcher" to close after that.

    Call finish() after you call startActivity() to close up your "Launcher".

    0 讨论(0)
  • 2020-12-17 06:15

    Calling finish in your launcher and clearing the activity stack may help, but your problem is probably related to the fact that your intent is Intent.ACTION_GET_CONTENT.

    Looks like you're trying to get content from the gallery, and that is what it is doing. Try ACTION_VIEW instead.

    0 讨论(0)
  • 2020-12-17 06:24
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_VIEW );
        startActivity(intent);
    
    0 讨论(0)
提交回复
热议问题