Android 安卓推特默认共享强制关闭

Android 安卓推特默认共享强制关闭,android,Android,我在通过intent进行twitter共享时遇到问题 我通过intent打开了一个twitter应用程序,一旦我点击登录按钮,就会被强制关闭。我找不到错误报告 推特是安卓系统的默认共享吗?或者需要使用他们的SDK 这是我的默认推特分享代码。你们有什么想法让我知道 试一试 { 这就是我在twitter上分享东西的方式: tweetButton.setOnClickListener(new OnClickListener() { @Override public v

我在通过intent进行twitter共享时遇到问题

我通过intent打开了一个twitter应用程序,一旦我点击登录按钮,就会被强制关闭。我找不到错误报告

推特是安卓系统的默认共享吗?或者需要使用他们的SDK

这是我的默认推特分享代码。你们有什么想法让我知道

试一试

{


这就是我在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"));
    }
}
tweetButton.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
//TODO自动生成的方法存根
initShareIntentTwi(“twi”);
}
});
私有void initShareIntentTwi(字符串类型){
布尔值=false;
意向共享=新意向(android.content.Intent.ACTION\u SEND);
share.setType(“文本/普通”);
//获取可以加载的意图列表。
List resInfo=getPackageManager().queryInputActivities(
份额,0);
如果(!resInfo.isEmpty()){
对于(ResolveInfo:resInfo){
if(info.activityInfo.packageName.toLowerCase()包含(类型)
||info.activityInfo.name.toLowerCase().contains(类型)){
share.putExtra(Intent.EXTRA_文本,标题+“”
+短网址);
share.setPackage(info.activityInfo.packageName);
发现=真;
打破
}
}
如果(!找到){
AlertDialog.Builder=新建AlertDialog.Builder(此);
builder.setTitle(“推特”);
LinearLayout包装器=新的LinearLayout(此);
WebView WebView=新的WebView(此);
EditText keyboardHack=新的EditText(此);
keyboardHack.setVisibility(View.GONE);
webView.loadUrl(“https://twitter.com/intent/tweet?status="
+titulo+“%20”+短URL);
setWebViewClient(新的WebViewClient(){
@凌驾
公共布尔值应覆盖URL加载(WebView视图,
字符串(url){
view.loadUrl(url);
返回true;
}
});
包装器。设置方向(线性布局。垂直);
wrapper.addView(webView,
LinearLayout.LayoutParams.MATCH_父级,
LinearLayout.LayoutParams.MATCH_PARENT);
wrapper.addView(键盘黑客,
LinearLayout.LayoutParams.MATCH_父级,
LinearLayout.LayoutParams.WRAP_内容);
setView(包装器);
builder.setNegativeButton(“关闭”,
新建DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface对话框,int-id){
}
});
builder.create().show();
返回;
}
startActivity(Intent.createChooser(共享,“选择”));
}
}

如果用户有Twitter应用程序,这将打开它,如果没有,它将打开一个带有包含以下内容的webview的警报对话框:“加上您想要共享的文本。如果您愿意,您可以忽略此部分,只需显示一个提示对话框,询问应用程序或类似的内容。

感谢您的回复,我按照您的方式使用默认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"));
    }
}