Android Twitter默认股权关闭

Gan*_*hik 7 android

我通过意图在twitter分享中遇到问题.

我通过意图打开了一个Twitter应用程序,一旦我点击登录按钮强行关闭.我无法找到错误报告.

Twitter严格是android中的默认共享吗?或者需要使用他们的SDK.

这是我默认推特分享的代码.大家好,让我知道......

尝试

{

   Intent shareIntent = ShareCompat.IntentBuilder
   .from(Activity.this).setType("text/plain")
   .setText("Shopup" + review).getIntent()
   .setPackage("com.twitter.android");
   startActivity(shareIntent);

   } catch (Exception e) 
     { 
     // TODO: handle exception
        Toast.makeText(Activity.this, "Need twitter application",
                                            Toast.LENGTH_SHORT).show();

     }
Run Code Online (Sandbox Code Playgroud)

Car*_*los 2

这就是我在 Twitter 上分享内容时所做的事情:

tweetButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            initShareIntentTwi("twi");
        }
    });

private void initShareIntentTwi(String type) {
    boolean found = false;
    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("text/plain");

    // gets the list of intents that can be loaded.
    List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(
            share, 0);
    if (!resInfo.isEmpty()) {
        for (ResolveInfo info : resInfo) {
            if (info.activityInfo.packageName.toLowerCase().contains(type)
                    || info.activityInfo.name.toLowerCase().contains(type)) {
                share.putExtra(Intent.EXTRA_TEXT, title + " "
                        + shorturl);
                share.setPackage(info.activityInfo.packageName);
                found = true;
                break;
            }
        }
        if (!found) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Twitter");

            LinearLayout wrapper = new LinearLayout(this);
            WebView webView = new WebView(this);
            EditText keyboardHack = new EditText(this);

            keyboardHack.setVisibility(View.GONE);

            webView.loadUrl("https://twitter.com/intent/tweet?status="
                    + titulo + "%20" + shorturl);

            webView.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view,
                        String url) {
                    view.loadUrl(url);
                    return true;
                }
            });

            wrapper.setOrientation(LinearLayout.VERTICAL);
            wrapper.addView(webView,
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT);
            wrapper.addView(keyboardHack,
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);

            builder.setView(wrapper);

            builder.setNegativeButton("Close",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                        }
                    });

            builder.create().show();

            return;
        }
        startActivity(Intent.createChooser(share, "Select"));
    }
}
Run Code Online (Sandbox Code Playgroud)

如果用户有 Twitter 应用程序,这将打开它,如果没有,它将打开一个警报对话框,其中包含一个包含以下内容的 Web 视图:“ https://twitter.com/intent/tweet?status= ” 加上您输入的文本想要分享。如果您愿意,您可以忽略这部分,只显示一个警告对话框,询问应用程序或类似的内容。