2017-05-07 73 views
1

我正在爲一家公司申請,我需要在Instagram上分享。Android Instagram分享例外

我使用的代碼是:

public void SharingToSocialMedia(String application) { 

    Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_SEND); 
    intent.setType("text/plain"); 
    intent.putExtra(Intent.EXTRA_TEXT, "http://www.google.sk/"); 

    boolean installed = checkAppInstall(application); 
    if (installed) { 
     intent.setPackage(application); 
     startActivity(intent); 
    } else { 
     Toast.makeText(getApplicationContext(), 
       "Nie je nainštalovaná aplikácia", Toast.LENGTH_LONG).show(); 
    } 

} 
private boolean checkAppInstall(String uri) { 
    PackageManager pm = getPackageManager(); 
    try { 
     pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); 
     return true; 
    } catch (PackageManager.NameNotFoundException e) { 
    } 

    return false; 
} 

其中

application = "com.instagram.android" 

的問題是,我收到此錯誤

05-07 16:48:50.728 6192-6192/eu.maweb.lodkanadeje.lodkanadeje E/AndroidRuntime: FATAL EXCEPTION: main 
Process: eu.maweb.lodkanadeje.lodkanadeje, PID: 6192 
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/plain flg=0x1 pkg=com.instagram.android clip={text/plain T:http://www.google.sk/} (has extras) } 
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1854) 
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1544) 
    at android.app.Activity.startActivityForResult(Activity.java:4391) 
    at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50) 
    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79) 
    at android.app.Activity.startActivityForResult(Activity.java:4335) 
    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859) 
    at android.app.Activity.startActivity(Activity.java:4697) 
    at android.app.Activity.startActivity(Activity.java:4665) 
    at eu.maweb.lodkanadeje.lodkanadeje.MainActivity.SharingToSocialMedia(MainActivity.java:134) 
    at eu.maweb.lodkanadeje.lodkanadeje.MainActivity.onNavigationItemSelected(MainActivity.java:117) 
    at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:156) 
    at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822) 
    at android.support.v7.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:88) 
    at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156) 
    at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:969) 
    at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:342) 
    at android.view.View.performClick(View.java:5646) 
    at android.view.View$PerformClick.run(View.java:22450) 
    at android.os.Handler.handleCallback(Handler.java:755) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:156) 
    at android.app.ActivityThread.main(ActivityThread.java:6524) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831) 

我使用Facebook的相同的代碼併爲Twitter和它完美的作品......所以有人可以幫助我這個異常?

UPDATE

這裏是清單文件

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

    package="eu.maweb.lodkanadeje.lodkanadeje"> 

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

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/lodka" 
     android:label="Loďka Nádeje" 
     android:roundIcon="@mipmap/lodka" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <provider 
      android:authorities="com.facebook.app.FacebookContentProvider2295668910658614" 
      android:name="com.facebook.FacebookContentProvider" 
      android:exported="true"/> 
     <activity 
      android:configChanges="orientation|screenSize" 
      android:name=".MainActivity" 
      android:label="Loďka nádeje" 
      android:theme="@style/AppTheme.NoActionBar"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

</manifest> 
+0

的[安卓的Instagram]可能的複製(http://stackoverflow.com/questions/13177677/android-instagram) –

+1

請參閱(文檔)[https://www.instagram.com/developer/mobile-sharing/android-intents/]查看應該包含哪些內容(快速提示:instagram是關於共享圖像的) – njzk2

回答

1

錯誤消息顯示

android.content.ActivityNotFoundException:無活動處理 意向{行動=機器人。 intent.action.SEND typ = text/plain flg = 0x1 pkg = com.instagram.android clip = {text/plain T:http://www.google.sk/} (有演員)}

這意味着Android系統的犯規發現Instagram的應用程序的活動,以處理you.Make確保已安裝Instagram的應用程序在設備上創建的意圖。

+0

這是問題...我有我的設備上的instagram – Apuna12

+0

@ Apuna12你可以顯示你的清單文件PLZ .. – Jeeva

+0

@ Apuna12檢查官方鏈接的instagram使用意圖。[鏈接](https://www.instagram.com/developer/mobile-sharing/android-intents/)而你的意圖設置類型是文本,而instagram恰好支持無論是視頻還是圖像..儘管它有幫助.. – Jeeva

1

嘗試檢查應用程序,如果它從PackageManager.getApplicationInfo,而不是getPackageInfo安裝。

這是我用

private boolean verifyInstagram() { 
    boolean installed; 
    // The application info gets correctly == true 
    try { 
     ApplicationInfo info = getActivity().getPackageManager().getApplicationInfo("com.instagram.android", 0); 
     installed = true; 
    } catch (PackageManager.NameNotFoundException e) { 
     installed = false; 
    } 
    return installed; 
} 

希望的代碼,可以幫助你