1

我正在为一家公司申请,我需要在 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>
4

2 回答 2

2

错误信息显示

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/ }(有附加功能)}

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

于 2017-05-07T15:20:32.843 回答
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;
}

希望对你有帮助

于 2017-05-22T20:39:38.100 回答