软录 · 2023年12月9日

安卓intent分享链接|android app怎样实现微信分享

㈠ android 调用系统分享怎样分享一个链接

为了应用的推广、传播,很多的应用中都有“分享”功能,一个按钮,点击后会出现短信、微博等等一切实现了分享功能的应用列表。这一篇文章主要介绍怎么调用分享功能和怎么实现分享接口让自己应用出现分享列表中。Android应用中能很方便的完成这些功能,这也正是Android的伟大之处,他能很简单的完成应用之间的沟通以相互整合。调用分享功能1、分享文本分享功能使用的隐式启动Activity的方法,这里的Action使用的是 ACTION_SEND。[java] view plainprint?在CODE上查看代码片派生到我的代码片Intent sendIntent = new Intent();sendIntent.setAction(Intent.ACTION_SEND);sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");sendIntent.setType("text/plain");startActivity(sendIntent);效果如下图的图一。2、改变分享列表标题使用上面的分享方式分享列表标题为“使用一下内容完成操作”,Android中提供了Intent.createChooser() ,这样能一直显示分享选择列表,并且修改了分享列表标题内容。[java] view plainprint?在CODE上查看代码片派生到我的代码片Intent sendIntent = new Intent();sendIntent.setAction(Intent.ACTION_SEND);sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");sendIntent.setType("text/plain");startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));使用Intent.createChooser()的好处:If you callIntent.createChooser() for the intent, Android will always display the chooser. This has some advantages:Even if the user has previously selected a default action for this intent, the chooser will still be displayed.If no applications match, Android displays a system message.You can specify a title for the chooser dialog.

㈡ android怎么把其他app的内容分享到自己的app里

很多时候我们的应用在使用微信分享内容之后,希望其他用户点击该分享内容能够跳转到我们的App,以实现闭环,这样的分享才是最有价值的。这种需求涉及到不同应用之间的交互,虽然微信提供了分享SDK,但仍然有不少限制,现在总结两种在Android平台上初步认为可行的方案:1.分享网页,从分享的网页跳转回原App。2.分享WXAppExtendObject类型的数据,且只能分享给好友,好友从聊天列表点击收到的分享内容可以直接跳转第三方App(前提是好友手机上已经安装了该App)。下面来详细说明两个方案,由于是在项目中实测的,为了隐私及行文方便,假设我们的应用的名字为MyApp,效果截图也就不再展示。方案一:从WebView(该WebView从属于另一个App,并非我们自己的App)跳转到MyApp的某个界面(这里以跳转到MyApp的Acticity A为例)。具体的实现逻辑如下:(1)该WebView显示的网页内容只是一个超链接,自定义了一个scheme=myapp://,后边可以附加一些参数,如果需要从网页向App传值的话。<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>This is title</title></head><body><a href=’myapp://id=909624′>Jump to MyApp</a></body></html>该网页在WebView打开后就是一个简单的超链接,截图不再附。(2)MyApp中的Activity A需要配置特定的infliter,如下:<activity<intent-filter><data android:scheme="myapp" /><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE"/></intent-filter></activity>(3)当在WebView上点击上述自定义的超链接时就可以打开MyApp的A界面,所传递的参数也可以在所跳转到的Activity中获取,方法如下:getIntent().getScheme();//获得Scheme名称getIntent().getDataString();//获得Uri全部路径,根据自定义的格式解析字符串即可获取我们上面附加的参数。可行的实施方案:MyApp中调用微信分享分享网页内容,只需要在网页中嵌入跟Android客户端约定好的超链接协议scheme,那么点击时就可以跳转到MyApp。问题1:如果用户安装了MyApp,就可以点击网页跳转,如果没有安装MyApp的话,WebView就会提示找不到该页面。制作网页时可以在网页中做检测,没安装MyApp的话,页面就重定向到应用的下载页面。问题2:在普通App的WebView中和浏览器中上述机制是可以的,但是在微信的WebView是不可以点击直接跳转我们的应用的,可能是微信做了某些过滤,且仅仅支持跟微信有深度合作的应用的跳转,如大众点评是可以的。针对这种情况,我们可以引导用户使用浏览器打开所分享的网页,然后点击就可以跳转应用了。方案二:使用微信SDK分享WXAppExtendObject数据给好友,好友点击跳转MyApp的某个页面(需要在分享时传递构造跳转Intent的参数)。1.该类型的分享(具体请参考微信分享SDK)可以带几个参数,参数中必须附带一些构造跳转Intent的数据。2.好友点击分享的内容,回调IWXAPIEventHandler接口的类的onReq方法,具体为ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:这种情况才会调用,此时可以取出分享时附带在参数中的一些数据,构造一个跳转Intent,调用startActivity(intent) 来打开MyApp。由于是项目实测,这种实现方式的截图也就不传了。问题1:该分享方式只能分享给好友,不能分享到朋友圈。问题2:如果好友没安装MyApp,点击微信中好友分享过来的消息后无反应,无法提醒“未安装MyApp,请下载”,因为这些逻辑要实现的话本身就是在MyApp里面写的,原本没装的话根本无法检测。问题3:WXAppExtendObject类型的分享,数据有大小限制,extInfo(String)限制2KB;fileData(byte[])供第三方使用的文件二进制数据,最大10M;filePath:(String)Local directory of the file provided for applications,本身长度最大10KB,文件大小同上,不超过10M。以上就是Android平台好友点击微信分享的内容后跳转来源App的两种实现方案,各有优点和局限性,请根据自身业务需求选择合适的分享方式,由于未能附截图说明,如有哪里表述不清楚的,欢迎留言讨论。

㈢ 如何在Android中调用浏览器打开网页

在安卓代码中我们有时需要调用浏览器来打开相应的网页,此时可以有以下几种实现方式:一:调用默认浏览器Intent intent = new Intent(); //Intent intent = new Intent(Intent.ACTION_VIEW,uri);intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("此处填链接"); intent.setData(content_url); startActivity(intent); 其他浏览器Intent intent = new Intent(); //Intent intent = new Intent(Intent.ACTION_VIEW,uri); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("此处填链接"); intent.setData(content_url); intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");startActivity(intent);uc浏览器":"com.uc.browser", "com.uc.browser.ActivityUpdate“opera:"com.opera.mini.android", "com.opera.mini.android.Browser"qq浏览器:"com.tencent.mtt", "com.tencent.mtt.MainActivity"二:1、自定义一个简单的WebView浏览器,设置下面属性:mWebView = (ProgressWebView) findViewById(R.id.baseweb_webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebViewClient(new WebViewClient());2、指定需要打开的额网页,在自定义的WebViewActivity中打开,如:WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.loadUrl("http://www.hao123.com");3、还可以查看相关的自定义WebView简单浏览器的Demo,《WebView控件实现的简单浏览器效果》,以及对应的TeachCourse介绍怎么使用

㈣ 用 微信的 android SDK 怎么分享信息 到微信

微信官方SDK的分享方法。

//图片

Bitmap bt=BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.erweima); final Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bt, null,null));

//分享到朋友

private void shareToFriend(Uri uri) {

Intent intent = new Intent();ComponentName comp = new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareImgUI");intent.setComponent(comp);intent.setAction("android.intent.action.SEND");intent.setType("image/*");//intent.setFlags(0x3000001);intent.putExtra(Intent.EXTRA_STREAM,uri);startActivity(intent);}

调用分享文本的android 系统方法。

//分享文字public void shareText(View view) {Intent shareIntent = new Intent();shareIntent.setAction(Intent.ACTION_SEND);shareIntent.putExtra(Intent.EXTRA_TEXT, "This is my Share text.");shareIntent.setType("text/plain");//设置分享列表的标题,并且每次都显示分享列表startActivity(Intent.createChooser(shareIntent, "分享到"));}//分享单张图片public void shareSingleImage(View view) {String imagePath = Environment.getExternalStorageDirectory() + File.separator + "test.jpg";//由文件得到uriUri imageUri = Uri.fromFile(new File(imagePath));Log.d("share", "uri:" + imageUri); //输出:file:///storage/emulated/0/test.jpgIntent shareIntent = new Intent();shareIntent.setAction(Intent.ACTION_SEND);shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);shareIntent.setType("image/*");startActivity(Intent.createChooser(shareIntent, "分享到"));}//分享多张图片public void shareMultipleImage(View view) {ArrayList uriList = new ArrayList<>();String path = Environment.getExternalStorageDirectory() + File.separator;uriList.add(Uri.fromFile(new File(path+"australia_1.jpg")));uriList.add(Uri.fromFile(new File(path+"australia_2.jpg")));uriList.add(Uri.fromFile(new File(path+"australia_3.jpg")));Intent shareIntent = new Intent();shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);shareIntent.setType("image/*");startActivity(Intent.createChooser(shareIntent, "分享到"));}

㈤ 在安卓分享中,如何通过ACTION_SEND进行指定应用分享,比如我想指定微博,qq,微信,朋友圈,最好有代码

//指定分享的应用(type)private void initShareIntent(String type) { boolean found = false; Intent share = new Intent(android.content.Intent.ACTION_SEND); share.setType("image/jpeg"); // 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_SUBJECT, "subject"); share.putExtra(Intent.EXTRA_TEXT, "your text"); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(myPath)) ); // Optional, just if you wanna share an image. share.setPackage(info.activityInfo.packageName); found = true; break; } } if (!found) return; startActivity(Intent.createChooser(share, "Select")); }}//一些常用应用包名:case ID_QQWEIBO: initShareIntent("com.tencent.wblog"); break;case ID_WEIXIN: initShareIntent("com.tencent.mm"); break;case ID_EVERNOTE: initShareIntent("evernote"); break;case ID_SINAWEIBO: initShareIntent("com.sina.weibo"); break;case ID_RENREN: initShareIntent("renren"); break;case ID_QQ: initShareIntent("tencent.mobileqq"); break;

㈥ android app怎样实现微信分享

使用微信SDK分享WXAppExtendObject数据给好友,好友点击跳转MyApp的某个页面(需要在分享时传递构造跳转Intent的参数)。1.该类型的分享(具体请参考微信分享SDK)可以带几个参数,参数中必须附带一些构造跳转Intent的数据。2.好友点击分享的内容,回调IWXAPIEventHandler接口的类的onReq方法,具体为ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:这种情况才会调用,此时可以取出分享时附带在参数中的一些数据,构造一个跳转Intent,调用startActivity(intent) 来打开MyApp。由于是项目实测,这种实现方式的截图也就不传了。问题1:该分享方式只能分享给好友,不能分享到朋友圈。问题2:如果好友没安装MyApp,点击微信中好友分享过来的消息后无反应,无法提醒“未安装MyApp,请下载”,因为这些逻辑要实现的话本身就是在MyApp里面写的,原本没装的话根本无法检测。问题3:WXAppExtendObject类型的分享,数据有大小限制,extInfo(String)限制2KB;fileData(byte[])供第三方使用的文件二进制数据,最大10M;filePath:(String)Local directory of the file provided for applications,本身长度最大10KB,文件大小同上,不超过10M。

㈦ android开发intent怎么传递集合

1、Intent(意图)主要是解决Android应用的各项组件之间的通讯。2、为了实现传递数据这个目的需要以下步骤3、Activity1需要构造一个 Intent,这个Intent用于告诉系统,我们要做“查看”动作intent可调用putExtra来存放想要传递的数据4、然后调用setClass,设置Activity1和欲调用的组件Activity25、最后调用startActivity将构造的Intent传入,系统会根据此Intent中的描述,到Activity1中找到满足此Intent要求的Activity,系统会调用找到的 Activity2最终传入Intent在Activity2中可使用getIntent来获取传递的Intent,并通过获取数据的方法来获取数据代码示例:Intent intent = new Intent(); // Activity1 intent.putExtra("one", num1); intent.putExtra("two", num2); intent.setClass(FirstActivity.this, SecondActivity.class); startActivity(intent); Intent intent = getIntent(); //Activity2 String num1 = intent.getStringExtra("one"); String num2 = intent.getStringExtra("two"); int ret = Integer.parseInt(num1) + Integer.parseInt(num2); result.setText(ret+"");注意:在使用intent的时候可以使用bundle传递复制的数据类型。