安卓手机下载twitter教程-威尼斯人2299

网络节点

摘要:

中最人可民法债权请人以申院更理人换管,取值人的管理酬和报费用审查。保物信用信用行尽信后在区状况职调管理及财经营记录对客、中最担的情等进处行查、域的业情务状户所环境和授、所审查况以况、况、,。...

中最

日起自登记之抵押合同生效,题字体标办理登记应当。

人可民法债权请人以申院更理人换管,取值人的管理酬和报费用审查。妆品该化教育纳的厂当城建月缴)元为(附加税和。不正确的是(,下列品消关于的表化妆费税述中。

保物信用信用行尽信后在区状况职调管理及财经营记录对客、中最担的情等进处行查、域的业情务状户所环境和授、所审查况以况、况、,。

题字体标取值中最题字体标取值

中最题字体标本月增值纳的应缴)元税(。

取值本月本地机关缴纳建税的城应向元税务。

不正确的是(,中最下述雪茄关于策的陈述烟叶、烟烟税丝和收政。

题字体标妆品该化纳消厂当月缴)元为(费税。

取值消费项税品业增值该广告样应纳)元务的为(合计税及税销。额为妆品值税该化纳增厂应元。并在增值计算缴纳抵扣予以税时,同时代收代缴城建税,并入额项税准予值税价计的买的进产品烟叶算增,人按规定缴纳对烟的烟纳税叶税叶税,托方消费代收代缴由受税,加工烟丝委托,为2税率。取值本月本地机关缴纳建税的城应向元税务。

我的应用程序包含带有全屏webview的片段。当用户单击webview中的链接时,将使用具有相同url的新webview打开新的片段。在打开新的fragment之前,我关闭软键盘以防万一。我很快打开新页面。所有操作都在主线程上执行。

对于crashlytics,问题仅适用于android 10(所有pixel系列设备和其他配备10的设备)。

在android 10之前的设备上,一切正常。我可以打开很多片段。但是在android 10设备上,这种情况会导致致命异常(在2-3次快速尝试随机打开新页面之后):

e/androidruntime: fatal exception: pool-1-thread-1

process: , pid: 12487

java.lang.runtimeexception: probable deadlock detected due to webview api being called on incorrect thread while the ui thread is blocked.

at yp.a(pg:13)

at com.android.webview.chromium.webviewchromium.oncheckistexteditor(pg:4)

at android.webkit.webview.oncheckistexteditor(webview.java:3035)

at android.view.inputmethod.inputmethodmanager.checkfocusnostartinput(inputmethodmanager.java:1901)

at android.view.inputmethod.inputmethodmanager.checkfocus(inputmethodmanager.java:1863)

at android.view.inputmethod.inputmethodmanager.hidesoftinputfromwindow(inputmethodmanager.java:1506)

at android.view.inputmethod.inputmethodmanager.hidesoftinputfromwindow(inputmethodmanager.java:1475)

at .utils.hidekeyboard(utils.java:175)

at .opennewpage(pager.java:210)

...

at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1167)

at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:641)

at java.lang.thread.run(thread.java:919)

caused by: java.util.concurrent.timeoutexception

at java.util.concurrent.futuretask.get(futuretask.java:206)

at yp.a(pg:11)

我试图使用android系统webview的所有可用版本(稳定版,测试版,开发者,金丝雀),但无济于事。

有人可以帮助我吗?

更新:

如果我注释隐藏软键盘的代码,则一切正常。

原文: www blogs /and_he/archive/2011/05/23/2054494.html

转载留在以后参考~~

关于twitter这一块,自发这篇博文之后有很多人问我,有的验证成功了不跳转,或者其它原因什么的,我看了一下,这篇博文里面有写呀,下面以红色粗体文字注明一下

刚进公司,叫我先学习twitter和facebook,就类似于国内的微博,或者分享功能,点击某个按钮,出来一个提示框,可以分享到某些地方,这里实现的就是分享到twitter,当然得要使用代理,因为这是给老外做的,所以得符合他们的习惯

先说一下实现的功能吧,首先运行的时候,会检查是否登陆twitter(通过sharedpreference文件保存登陆状态),如果没有登陆的话会跳转到twitter的登陆认证页面,提示用户输入用户名和密码,这些就是oauth认证的步骤,不懂的看这儿 www blogs /and_he/archive/2011/05/22/2053477.html

做过新浪微博的都应该知道,首先要申请成为开发者,创建自己的应用,然后会给你一些比如consumer key和consumer secret之类的东西,这些东西要先记下来,代码里面要用到的,其余的不啰嗦了,只是要注意一点,创建twitter应用的时候造成不能忘了填那个callback url,我当初就没填,结果整了几天都整不出来结果,也算是我的一点经验吧,下面贴代码,以便于以后查阅

首先我们要用到twitter封闭好的一些包,这里用到两个twitter4j-core-android和twitter4j-media-support-android,百度一下就出来了

以下是工程目录结构

package

com.twitter;

public

class

const {

public

static

final

string consumer_key

=

"

ifkj4coaz9f9ngfoe1lfuq

"

;

public

static

final

string consumer_secret

=

"

hn2nfe4mtl7oqjauirwfrnk9xkhywg2vzmaj6afwfj8

"

;

public

static

final

string request_token_url

=

"

api.twitter /oauth/request_token

"

;

public

static

final

string access_token_url

=

"

api.twitter /oauth/access_token

"

;

public

static

final

string callback_url

=

"

api.twitter /oauth/authorize

"

;

public

static

final

string twitpic_api_key

=

"

a77709ebb6c51de0e77f723751a5f9a4

"

; }

下面是twitter类(主类)

package

com.twitter;

import

java.io.ioexception;

import

java.io.inputstream;

import

twitter4j.twitterfactory;

import

twitter4j.conf.configurationbuilder;

import

android.app.activity;

import

android.app.progressdialog;

import

android.content.context;

import

android.content.intent;

import

android.content.sharedpreferences;

import

android.content.res.assetmanager;

import

android.os.asynctask;

import

android.os.bundle;

import

android.text.editable;

import

android.text.textwatcher;

import

android.util.log;

import

android.view.view;

import

android.view.window;

import

android.view.view.onclicklistener;

import

android.widget.button;

import

android.widget.edittext;

import

android.widget.textview;

import

android.widget.toast;

public

class

twitter

extends

activity { edittext et_content;

//

评论内容

edittext et_des;

//

图片描述

textview tv_num;

//

剩余字数

button btn_send;

//

发送按钮

int

num

=

140

;

//

定义总字数

progressdialog progressdialog;

//

当点击发送的时候显示此进度条

sharedpreferences spf; twitterconnect tc;

//

定义一个twitter连接对象

boolean

connectionstatus

=

false

;

//

定义当前的连接状态为false

string content; string describle; @override

public

void

oncreate(bundle savedinstancestate) {

super

.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.twitter); tc

=

new

twitterconnect(

this

); spf

=

getsharedpreferences(

"

bravesoft

"

, context.mode_private); et_content

=

(edittext) findviewbyid(r.id.et_content); et_des

=

(edittext) findviewbyid(r.id.et_des); tv_num

=

(textview) findviewbyid(r.id.tv_num); tv_num.settext(

"

140

"

); progressdialog

=

new

progressdialog(

this

); progressdialog.settitle(

"

正在发送...

"

); progressdialog.setmessage(

"

正在发送,请稍候...

"

); et_content.addtextchangedlistener(

new

textwatcher() {

private

charsequence temp;

private

int

selectionstart;

private

int

selectionend; @override

public

void

ontextchanged(charsequence s,

int

start,

int

before,

int

count) { temp

=

s;

//

显示当前输入框中的所有内容

} @override

public

void

beforetextchanged(charsequence s,

int

start,

int

count,

int

after) { } @override

public

void

aftertextchanged(editable s) {

int

number

=

num

-

s.length(); tv_num.settext(

""

number); selectionstart

=

et_content.getselectionstart(); selectionend

=

et_content.getselectionend();

if

(temp.length()

>

num) { s.delete(selectionstart

-

1

, selectionend);

int

tempselection

=

selectionstart; et_content.settext(s); et_content.setselection(tempselection);

//

设置光标在最后

} } }); btn_send

=

(button) findviewbyid(r.id.btn_send); connectionstatus

=

spf.getboolean(

"

connection_tatus

"

,

false

); btn_send.setonclicklistener(

new

onclicklistener() { @override

public

void

onclick(view v) { content

=

et_content.gettext().tostring();

//

得到评论内容

describle

=

et_des.gettext().tostring();

//

得到图片描述内容

if

(connectionstatus) {

//

如果用户处于登陆状态,获取用户头像跟name

progressdialog.show(); getuserinfotask getuserinfotask

=

new

getuserinfotask(); getuserinfotask.execute(

""

); } } });

if

(

!

connectionstatus) { btn_send.setenabled(

false

); sendmessage(); } }

/**

* 如果用户处于登陆状态,获取用户头像跟name * *

@author

administrator *

*/

class

getuserinfotask

extends

asynctask

<

string, integer, string

>

{ @override

protected

string doinbackground(string... params) { string result

=

""

; configurationbuilder confbuild

=

new

configurationbuilder(); confbuild.setoauthconsumerkey(const.consumer_key); confbuild.setoauthconsumersecret(const.consumer_secret); confbuild.setoauthaccesstoken(spf.getstring(

"

oauth_token

"

,

""

)); confbuild.setoauthaccesstokensecret(spf.getstring(

"

oauth_token_secret

"

,

""

)); twitter4j.conf.configuration config

=

confbuild.build();

if

(twitterconnect.twitter

!=

null

) twitterconnect.twitter.shutdown(); twitterconnect.twitter

=

new

twitterfactory(config).getinstance(); inputstream input

=

null

;

try

{ twitterconnect.accesstoken

=

twitterconnect.twitter .getoauthaccesstoken();

boolean

btest

=

false

; assetmanager am

=

getassets();

try

{ input

=

am.open(

"

btn_dokusya_toukou.png

"

); }

catch

(ioexception e) { e.printstacktrace(); }

if

(tc

==

null

) { tc

=

new

twitterconnect(twitter.

this

); } btest

=

tc.twittercontribute(content, input, describle);

if

(btest) { result

=

"

ok

"

; }

else

{ result

=

"

failure

"

; } }

catch

(exception e) { }

return

result; } @override

protected

void

onpostexecute(string result) {

super

.onpostexecute(result);

if

(progressdialog.isshowing()) { progressdialog.dismiss(); }

if

(result.equals(

"

ok

"

)) { toast.maketext(twitter.

this

,

"

发送成功

"

, toast.length_long).show(); }

else

{ toast.maketext(twitter.

this

,

"

发送失败

"

, toast.length_long).show(); } } }

public

void

sendmessage() {

new

send().start(); }

class

send

extends

thread { @override

public

void

run() {

super

.run();

try

{ thread.sleep(

3000

); }

catch

(interruptedexception e) { e.printstacktrace(); } intent intent

=

new

intent(twitter.

this

, twitterloginbrowser.

class

); startactivityforresult(intent,

1

); } } @override

protected

void

onactivityresult(

int

requestcode,

int

resultcode, intent data) {

super

.onactivityresult(requestcode, resultcode, data);

if

(requestcode

==

1

) {

if

(resultcode

==

1

) {

//

表示从twitterloginbrowser返回

connectionstatus

=

spf.getboolean(

"

connection_tatus

"

,

false

);

if

(connectionstatus) { btn_send.setenabled(

true

); } } } } }

twitterconnect类

package

com.twitter;

import

java.io.ioexception;

import

java.io.inputstream;

import

java .url;

import

twitter4j.status;

import

twitter4j.twitter;

import

twitter4j.twitterexception;

import

twitter4j.twitterfactory;

import

twitter4j.auth.accesstoken;

import

twitter4j.auth.requesttoken;

import

twitter4j.conf.configuration;

import

twitter4j.conf.configurationbuilder;

import

twitter4j.media.imageupload;

import

twitter4j.media.imageuploadfactory;

import

twitter4j.media.mediaprovider;

import

android.content.context;

import

android.graphics.bitmap;

import

android.graphics.bitmapfactory;

public

class

twitterconnect { context context;

public

static

twitter twitter;

public

static

requesttoken requesttoken;

public

static

accesstoken accesstoken;

public

twitterconnect(context context) {

this

.context

=

context; twitter

=

new

twitterfactory().getinstance(); }

public

string twitterloginoauth() { twitter.setoauthconsumer(const.consumer_key, const.consumer_secret);

try

{ requesttoken

=

twitter.getoauthrequesttoken();

return

requesttoken.getauthentication

"

&force_login=true

"

; }

catch

(twitterexception e) { e.printstacktrace();

return

"

baidu

"

; }

//

已经得到临时访问令牌

//

request token=7hmpofnr5ev1kjcw036mdi1hpvycbb1srkkk3r6ax30

//

request token secret=fahibfx04lbqhme392hth1lgl8hqxm2p0ij5kzlofk

//

url=

api.twitter /oauth/authenticate?oauth_token=svrksiu1arj7h24rvhphennzfxqliebry7uefydmb9k

}

//

得到用户名

public

string getusername() {

try

{

return

twitter.showuser(accesstoken.getuserid()).getname(); }

catch

(exception e) {

return

""

; } }

//

得到用户头像

public

bitmap getuserimage(string userimageurl) { bitmap image

=

null

;

try

{ url url

=

new

; image

=

bitmapfactory.decodestream(url.openstream()); }

catch

(exception e) { e.printstacktrace(); }

return

image; }

/**

* *

@param

text * 评论内容 *

@param

input * 图片的一个inputstream *

@param

description * 图片描述 *

@return

*/

public

boolean

twittercontribute(string text, inputstream input, string description) {

boolean

isok

=

false

; configuration config

=

null

; imageupload uploads

=

null

;

try

{ status status

=

null

;

if

(input

!=

null

) {

if

(config

==

null

) { configurationbuilder confbuild

=

new

configurationbuilder(); confbuild.setoauthconsumerkey(const.consumer_key); confbuild.setoauthconsumersecret(const.consumer_secret); confbuild.setoauthaccesstoken(accesstoken.gettoken()); confbuild.setoauthaccesstokensecret(accesstoken .gettokensecret()); confbuild.setmediaproviderapikey(const.twitpic_api_key);

//

发送图片和对图片的描述

config

=

confbuild.build(); uploads

=

new

imageuploadfactory(config) .getinstance(mediaprovider.twitpic); } string uploadre

=

""

; uploadre

=

uploads.upload(

"

"

, input, description); system.out.println(

"

uploadre

"

uploadre);

if

(input

!=

null

)

try

{ input.close(); }

catch

(ioexception e) { }

if

(

!

uploadre.equals(

""

)) { status

=

twitter.updatestatus(text

"

"

uploadre); system.out.println(

"

uploadre=

"

uploadre); } }

else

{ status

=

twitter.updatestatus(text); }

if

(status

!=

null

) { system.out.println(

"

发表内容:

"

status.gettext()); isok

=

true

; } }

catch

(exception e) { isok

=

false

; }

return

isok; } }

twitterloginbrowser类

package

com.twitter;

import

twitter4j.twitterexception;

import

android.app.activity;

import

android.app.progressdialog;

import

android.content.context;

import

android.content.intent;

import

android.content.sharedpreferences;

import

android.content.sharedpreferences.editor;

import

android.graphics.bitmap;

import

android.os.asynctask;

import

android.os.bundle;

import

android.view.keyevent;

import

android.view.window;

import

android.webkit.webchromeclient;

import

android.webkit.webview;

import

android.webkit.webviewclient;

import

android.widget.toast;

public

class

twitterloginbrowser

extends

activity { webview webview; progressdialog progressdialog;

//

定义一个进度条

twitterconnect tc; string authenticateurl

=

""

; connecttask task; string oauthtoken; string oauthverifier; bitmap userimage;

//

用户头像

@override

protected

void

oncreate(bundle savedinstancestate) {

super

.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.twitter_loginbrowser); progressdialog

=

new

progressdialog(twitterloginbrowser.

this

); progressdialog.settitle(

"

请等待

"

); progressdialog.setmessage(

"

正在加载页面,请稍等...

"

); progressdialog.show();

//

启动的时候就让它显示

webview

=

(webview) findviewbyid(r.id.webview); webview.getsettings().setjavascriptenabled(

true

); webview.requestfocus(); tc

=

new

twitterconnect(

this

); task

=

new

connecttask(

this

); task.execute(

"

login

"

);

//

执行载入页面任务

webview.setwebviewclient(

new

webviewclient() { @override

public

boolean

shouldoverrideurlloading(webview view, string url) { view.load;

return

true

; } @override

public

void

onpagestarted(webview view, string url, bitmap favicon) {

super

.onpagestarted(view, url, favicon); system.out.println(

"

开始加载页面:

"

url); }

//

页面载入完成

@override

public

void

onpagefinished(webview view, string url) {

super

.onpagefinished(view, url);

//

url=

api.twitter /oauth/authorize?oauth_token=9kpqny7vhmywc5nrxf2eq73zn4vkxjqcgzj62sizu

&oauth_verifier=3b7fbas9xoyh8i3qeqrfguqjlgmufqh5fzmz7j3ws

toast.maketext(twitterloginbrowser.

this

,

"

页面加载完成

"

, toast.length_long).show();

if

(url

!=

null

&&

url.startswith(const.callback_url)) { string[] param

=

url.split(

"

\\?

"

)[

1

].split(

"

&

"

);

if

(param[

0

].startswith(

"

oauth_token

"

)) { oauthtoken

=

param[

0

].split(

"

=

"

)[

1

]; }

else

if

(param[

1

].startswith(

"

oauth_token

"

)) { oauthtoken

=

param[

1

].split(

"

=

"

)[

1

]; }

if

(param[

0

].startswith(

"

oauth_verifier

"

)) { oauthverifier

=

param[

0

].split(

"

=

"

)[

1

]; }

else

if

(param[

1

].startswith(

"

oauth_verifier

"

)) { oauthverifier

=

param[

1

].split(

"

=

"

)[

1

]; } system.out.println(

"

oauthtoken=

"

oauthtoken); system.out.println(

"

oauthverifier=

"

oauthverifier);

try

{ twitterconnect.accesstoken

=

twitterconnect.twitter .getoauthaccesstoken( twitterconnect.requesttoken, oauthverifier); webtask wt

=

new

webtask(); wt.execute(

""

); }

catch

(twitterexception e) { e.printstacktrace(); system.out.println(

"

发生错误了

"

); } } } }); webview.setwebchromeclient(

new

webchromeclient() {

//

控制进度条的显示

@override

public

void

onprogresschanged(webview view,

int

newprogress) {

super

.onprogresschanged(view, newprogress);

if

(newprogress

!=

100

) {

if

(

!

progressdialog.isshowing()) { progressdialog.show(); } }

else

{

if

(progressdialog.isshowing()) { progressdialog.dismiss(); } } } }); }

//

获取用户名和头像

class

webtask

extends

asynctask

<

string, integer, string

>

{ @override

protected

string doinbackground(string... params) { string result

=

""

;

if

(oauthtoken

!=

null

&&

oauthverifier

!=

null

) { system.out.println(

"

开始获取用户名和头像

"

); string userimageurl

=

""

;

//

用户头像url

try

{ userimageurl

=

twitterconnect.twitter .showuser(twitterconnect.accesstoken.getuserid()) .getprofileimage.tostring(); }

catch

(twitterexception e) { e.printstacktrace(); } string username

=

tc.getusername();

if

(userimage

!=

null

) { userimage.recycle(); } userimage

=

tc.getuserimage(userimageurl);

//

登陆成功 回到来的画面

intent intent

=

new

intent(); bundle bundle

=

new

bundle(); bundle.putparcelable(

"

userimage

"

, userimage); bundle.putstring(

"

username

"

, username); intent.putextra(

"

userinfo

"

, bundle);

//

保存登陆状态

sharedpreferences spf

=

getsharedpreferences(

"

bravesoft

"

, context.mode_private); editor editor

=

spf.edit(); editor.putstring(

"

oauth_token

"

, twitterconnect.accesstoken.gettoken()); editor.putstring(

"

oauth_token_secret

"

, twitterconnect.accesstoken.gettokensecret()); editor.putboolean(

"

connection_tatus

"

,

true

); editor.putstring(

"

username

"

, username); editor.putstring(

"

userimgurl

"

, userimageurl); editor mit(); twitterloginbrowser.

this

.setresult(

1

, intent); bundle.clear(); result

=

"

ok

"

; }

return

result; } @override

protected

void

onpostexecute(string result) {

super

.onpostexecute(result);

if

(result.equals(

"

ok

"

)) { toast.maketext(twitterloginbrowser.

this

,

"

登陆成功

"

, toast.length_long).show(); }

else

{ toast.maketext(twitterloginbrowser.

this

,

"

登陆失败

"

, toast.length_long).show(); }

//

twitterloginbrowser.this.finish();

} }

class

connecttask

extends

asynctask

<

string, integer, string

>

{

public

connecttask(context context) { } @override

protected

string doinbackground(string... params) { authenticateurl

=

tc.twitterloginoauth();

return

authenticateurl; } @override

protected

void

onpostexecute(string result) {

super

.onpostexecute(result);

if

(

!

result.equals(

""

)) { webview.load;

//

载入网页

}

else

{ toast.maketext(twitterloginbrowser.

this

,

"

载入错误,请重试

"

, toast.length_long).show(); twitterloginbrowser.

this

.finish(); } } } @override

public

boolean

onkeydown(

int

keycode, keyevent event) {

if

(keycode

==

keyevent.keycode_back

&&

webview.cangoback()) { webview.goback();

return

true

; }

return

super

.onkeydown(keycode, event); } }

文章威尼斯人2299的版权声明:除非注明,否则均为网络节点原创文章,转载或复制请以超链接形式并注明出处。

相关阅读

发表评论

快捷回复: 表情:
addoilapplausebadlaughbombcoffeefabulousfacepalmfecesfrownheyhainsidiouskeepfightingnoprobpigheadshockedsinistersmileslapsocialsweattolaughwatermelonwittywowyeahyellowdog
评论列表 (暂无评论,33人围观)

还没有评论,来说两句吧...

网站地图