2015-09-29 3 views
0

Я разработал приложение, которое позволяет обмениваться изображениями в Instagram. Приложение не имеет ошибок при выполнении, но я не могу обмениваться/загружать изображения в Instagram. Я не мог понять, где все пошло не так. Может кто-то помочь мне с этим. Мои кодировок заключаются в следующем:Не удается открыть изображение на Instagram

MainActivity.java:

package com.example.dothis.instagram; 

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.os.Environment; 
import android.view.View; 

import java.io.File; 

public class MainActivity extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 


    // listeners of our two buttons 
    View.OnClickListener handler = new View.OnClickListener() { 
     public void onClick(View v) { 
      switch (v.getId()) { 

       case R.id.btnConnect: 
        createInstagramIntent(); 
        break; 


      } 
     } 
    }; 

    // our buttons 
    findViewById(R.id.btnConnect).setOnClickListener(handler); 


} 



private void createInstagramIntent() { 

    Intent share = new Intent(Intent.ACTION_SEND); 

    // If you want to share a png image only, you can do: 
    // setType("image/png"); OR for jpeg: setType("image/jpeg"); 
    share.setType("image/*"); 

    // Make sure you put example png image named myImage.png in your 
    // directory 
    String imagePath = Environment.getExternalStorageDirectory() 
      + "/myImage.png"; 

    File imageFileToShare = new File(imagePath); 

    Uri uri = Uri.fromFile(imageFileToShare); 
    share.putExtra(Intent.EXTRA_STREAM, uri); 

    // Broadcast the Intent. 
    startActivity(Intent.createChooser(share, "Share to")); 
} 
} 

ApplicationData.java:

package com.example.dothis.instagram; 

import android.app.Activity; 

public class ApplicationData extends Activity { 
public static final String CLIENT_ID = "###########"; 
public static final String CLIENT_SECRET = "########"; 
public static final String CALLBACK_URL = "instagram:http://######/"; 
} 

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.dothis.instagram" > 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

<uses-permission android:name="android.permission.INTERNET"></uses- permission> 

</manifest> 

strings.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

<string name="app_name">Instagram OAuth</string> 
<string name="hello_world">Hello world!</string> 
<string name="action_settings">Settings</string> 


</resources> 

build.gradle:

apply plugin: 'com.android.application' 

android { 
compileSdkVersion 21 
buildToolsVersion "21.1.2" 

defaultConfig { 
    applicationId "com.example.dothis.instagram" 
    minSdkVersion 16 
    targetSdkVersion 21 
    versionCode 1 
    versionName "1.0" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
} 

dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
compile 'com.android.support:appcompat-v7:21.0.3' 
} 

Любые предложения/руководство было бы очень полезно. Спасибо

+0

у вас есть изображение с именем myImage.png? в вашем каталоге –

+0

да, у меня есть .. до невозможности загрузить изображение. @mina fawzy – marian

+0

право на запись разрешено to

ответ

1

попробуйте это.

private void postinstagraminbackground() { 
     // TODO Auto-generated method stub 

     String type = "image/*"; 
     Intent intent = getPackageManager().getLaunchIntentForPackage(
       "com.instagram.android"); 
     if (intent != null) { 

      try { 
       Intent shareIntent = new Intent(Intent.ACTION_SEND); 
       shareIntent.setPackage("com.instagram.android"); 
       shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       if (file != null) { 

        Uri uri = Uri.fromFile(file); 
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 
       } else if (image_value != null) { 
//incase of image url 
        shareIntent.putExtra(Intent.EXTRA_STREAM, image_value); 
       } 
       shareIntent.setType(type); 
       shareIntent.putExtra(Intent.EXTRA_TEXT, mfinalmsg); 
       // Broadcast the Intent. 

       startActivity(shareIntent); 

       // startActivity(Intent.createChooser(shareIntent, 
       // "Share to")); 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

     } else { 
      // bring user to the market to download the app. 
      // or let them choose an app? 
      intent = new Intent(Intent.ACTION_VIEW); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      intent.setData(Uri.parse("market://details?id=" 
        + "com.instagram.android")); 
      startActivity(intent); 
     } 
    } 
Смежные вопросы