安卓叽叽喳喳默认分享力关闭
问题描述:
我有一个问题在Twitter分享通过意图。安卓叽叽喳喳默认分享力关闭
我打开了一个慌张的应用程序通过意图,一旦我点击登录按钮获取强制closed.I无法找到错误报告。
Twitter是严格的默认在Android的份额?或者需要使用他们的SDK。
这是我默认Twitter的代码share.can u人任何想法,让我知道...
尝试
{
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();
}
答
这是我做分享的东西推特:
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"));
}
}
如果用户有Twitter应用程序,这将打开它,如果不会用webview打开一个警告对话框,其中包含以下内容:“https://twitter.com/intent/tweet?status=”以及您想要共享的文本。如果你愿意,你可以忽略这个部分,只显示一个警告对话框询问应用程序或类似的东西。
感谢您的回复,我按照默认twitter的方式分享其工作非常感谢!... –