Search code examples
androidandroid-intentinstagramappcelerator

Instagram crashes when my android app trying post on it using intent


I am developing an app for Android which should share image to the Instagram app. The app opens up the camera, takes a picture and then the Instagram app is opened with the "Crop photo" window active. It seems to be loading the picture, but after a couple of seconds the app crashes, i can't see that the image ever gets loaded.

Don't understand where i am going wrong.

Thanks..!!!

 var intent = Ti.Android.createIntent({
    action: Ti.Android.ACTION_SEND,
    packageName:"com.instagram.android",
    type: "image/*"
});

intent.putExtraUri(intent.EXTRA_STREAM,MediaPath);
intent.putExtra(Ti.Android.EXTRA_TEXT, "Posting via My Andorid App... Testing");
intent.FLAG_ACTIVITY_CLEAR_TOP;
Ti.Android.currentActivity.startActivity(intent);

Solution

  • i think you should use this code that i already implemented in my code:

    String type = "image/*";
    String filename = "/myPhoto.jpg";
    String mediaPath = Environment.getExternalStorageDirectory() + filename;
    

    and call a method to open Instagram.

    createInstagramIntent(type, mediaPath);
    

    and method body like:

    private void createInstagramIntent(String type, String mediaPath){
    
    // Create the new Intent using the 'Send' action.
    Intent share = new Intent(Intent.ACTION_SEND);
    
    // Set the MIME type
    share.setType(type);
    
    // Create the URI from the media
    File media = new File(mediaPath);
    Uri uri = Uri.fromFile(media);
    
    // Add the URI to the Intent.
    share.putExtra(Intent.EXTRA_STREAM, uri);
    
    // Broadcast the Intent.
        startActivity(Intent.createChooser(share, "Share to"));
    }
    

    and dear for more information you can see Instagram official site to share image and video here. enjoy your code:)