android line分享代码,Android实现Line登录分享

一、获取参数

1、注册登录Line开发者账号

在Line官网并找不到注册地方,可以通过Line APP进行注册,注册之后进入Line开发者官网:

2、创建应用

3、创建完成在Channel settings下获取Channel ID和Channel secrt

4、在AppSettings下配置包名和签名

allprojects {

repositories {

...

flatDir {

dirs 'libs'

}

...

}

}

compile(name: 'line_sdk_4.0.8', ext: 'aar')

二、登录实现

1.APP-APP

int REQUEST_CODE=1;

LineApiClient lineApiClient;

LineApiClientBuilder apiBuilder= new LineApiClientBuilder(activity,lineChannelID);

lineApiClient=apiBuilder.build();

if(checkApkExist(activity,"jp.naver.line.android")){//App-to-App

Log.d(tag,"Login-App-to-App");

Intent loginIntent= LineLoginApi.getLoginIntent(activity,lineChannelID);

} else{

//浏览器中的LINE登录界面

Log.d(tag,"Login-web");

loginIntent=LineLoginApi.getLoginIntentWithoutLineAppAuth(activity,lineChannelID);

}

activity.startActivityForResult(loginIntent,REQUEST_CODE);

public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode != REQUEST_CODE) {

Log.e("ERROR", "Unsupported Request");

return;

}

try {

LineLoginResult result = LineLoginApi.getLoginResultFromIntent(data);

Log.e(tag,"msg="+result.getErrorData().getMessage());

switch (result.getResponseCode()) {

case SUCCESS:

// Login successful

Log.d(tag,"loginSuccess");

String user_id=result.getLineProfile().getUserId();

String user_name=result.getLineProfile().getDisplayName();

String accessToken = result.getLineCredential().getAccessToken().getAccessToken();

break;

case CANCEL:

// Login canceled by user

Log.e(tag, "LINE Login Canceled by user!!");

Log.e(tag,"msg="+result.getErrorData().getMessage());

break;

default:

// Login canceled due to other error

Log.e(tag, "Login FAILED!"+result.getErrorData().toString());

}

}catch (Exception e){

e.printStackTrace();

}

}

//检查是否安装了app

public boolean checkApkExist(Context context, String packageName){

if(packageName==null){

return false;

}

try{

ApplicationInfo applicationInfo=context.getPackageManager()

.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);

return true;

}catch (Exception e){

e.printStackTrace();

return false;

}

}

三、分享实现

public void shareToLine(Activity activity,String uriString,String title,String text){

Log.d(tag,"share to Line");

String linePackageName="jp.naver.line.android";

String lineClassName="jp.naver.line.android.activity.selectchat.SelectChatActivityLaunchActivity";

ComponentName componentName=new ComponentName(linePackageName,lineClassName);

Intent shareIntent=new Intent();

shareIntent.setAction(Intent.ACTION_SEND);

Uri uri = Uri.parse(uriString);

shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

// shareIntent.setType("image/jpeg"); //图片分享

shareIntent.setType("text/plain"); // 纯文本

shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);//分享的标题

shareIntent.putExtra(Intent.EXTRA_TEXT, text);//分享内容

shareIntent.setComponent(componentName);//跳到指定APP的Activity

activity.startActivity(Intent.createChooser(shareIntent,""));

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值