您的位置:首页 > 移动开发 > Android开发

android开发中调用手机的豌豆荚、应用宝等市场进行评分操作,以及分享功能

2015-08-31 20:50 1776 查看
应用场景:某个手机阅读器程序,读者看到一篇文章,觉得不错,想要与朋友分享


  应用展现:按手机的Menu键,弹出“分享”菜单,点击后显示一系列Android分享功能的方式(短信、E-mail等) 。

  背景知识:Android上不同程序里面的Activity之间可以互相调用 。你可以在自己的程序中,调用短信程序,发送一条短信 。调用的方式就是向系 an统提出请求,系统会去调用适当的程序Activity。

  以下是Android分享功能实现源代码:

Java代码


import java.util.List;

import android.app.Activity;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.content.pm.ResolveInfo;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

public class Main extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);

}

/* 创建菜单 */

public boolean onCreateOptionsMenu(Menu menu) {

  menu.add(0,0,0,"分享");

  return true;

}

public boolean onOptionsItemSelected(MenuItem item){

  switch (item.getItemId()){

  case 0:

    Intent intent=new Intent(Intent.ACTION_SEND);

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

    /*图片分享

    it.setType("image/png");

     //添加图片

     File f = new File(Environment.getExternalStorageDirectory()+"/name.png");

      

     Uri uri = Uri.fromFile(f);

     intent.putExtra(Intent.EXTRA_STREAM, uri);

     */

    intent.putExtra(Intent.EXTRA_SUBJECT, "分享");

    intent.putExtra(Intent.EXTRA_TEXT, "I would like to share this with you...");

    startActivity(Intent.createChooser(intent, getTitle()));

    return true;

  }

  return false;

}

}

我实现的看下面:

Java代码


Intent intent=new Intent(Intent.ACTION_SEND);

intent.setType("image/*");//intent.setType("text/plain");

intent.putExtra(Intent.EXTRA_SUBJECT, "好友推荐");

intent.putExtra(Intent.EXTRA_TEXT, "嗨,我正在使用众意彩购买彩票,你也来试试手气哈!");

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(Intent.createChooser(intent, getTitle()));



Android 调用已安装市场,进行软件评分的功能实现

Java代码


Uri uri = Uri.parse("market://details?id="+getPackageName());

Intent intent = new Intent(Intent.ACTION_VIEW,uri);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);

分享功能:

Java代码


Intent sendIntent = new Intent();

sendIntent.setAction(Intent.ACTION_SEND);

sendIntent.setType("text/*");

sendIntent.putExtra(Intent.EXTRA_TEXT, contentEditText.getText().toString());

startActivity(sendIntent);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: