安卓Instagram分享例外



我正在为一家公司申请,我需要在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使用相同的代码,它运行良好......那么有人可以帮助我解决这个例外吗?

更新

这是清单文件

<?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>

错误消息显示

android.content.ActivityNotFoundException:未找到要处理的活动 Intent { act=android.intent.action.SEND typ=text/plain flg=0x1 pkg=com.instagram.android clip={text/plain T:http://www.google.sk/} (有额外功能( }

这意味着安卓系统找不到 Instagram 应用活动来处理您创建的意图。确保您已在设备上安装了Instagram应用程序。

尝试检查应用程序是否从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;
}

希望对您有所帮助

相关内容

  • 没有找到相关文章

最新更新