关闭

平台插件化

155人阅读 评论(0) 收藏 举报
package com.example.text;


import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;


import com.ant.liao.GifView;
import com.squareup.picasso.Picasso;


public class MainActivity extends Activity {


private String url="http://t11.baidu.com/it/u=38767480,4056423661&fm=59";
private String path="http://img2.imgtn.bdimg.com/it/u=3853115189,3802116727&fm=21&gp=0.jpg";
private ImageView imageview;
private GifView gf1;
private List<PluginBean> plugins;
private LinearLayout line;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
line = (LinearLayout) findViewById(R.id.line);
attachPlugin(findPlugins());
}

/**
* 加载插件列表
* @param plugins
*/
private void attachPlugin(final List<PluginBean> plugins){
Log.e("ydt", "   ");
Log.e("ydt", "----- 列出插件");
this.plugins=plugins;
for(final PluginBean plugin:plugins){
Button btn=new Button(this);
line.addView(btn);
btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent it=new Intent();
System.out.println("======");
it.setAction(plugin.getPakageName());
//这里,不会把插件的窗体附加到主程序中,纯粹无用的演示
startActivity(it);
}
});
}
}
/**
* 查找插件
* @return
*/
private List<PluginBean> findPlugins(){
plugins = new ArrayList<PluginBean>();
//遍历包名,来获取插件
PackageManager pm=getPackageManager();
List<PackageInfo> pkgs=pm.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for(PackageInfo pkg :pkgs){
//包名
String packageName=pkg.packageName;
String sharedUserId= pkg.sharedUserId;
//sharedUserId是开发时约定好的,这样判断是否为自己人2
if(!"org.igeek.plugintest".equals(sharedUserId)||"com.example.text".equals(packageName))
continue;
//进程名
//String prcessName=pkg.applicationInfo.processName;
//label,也就是appName了
String label=pm.getApplicationLabel(pkg.applicationInfo).toString();
System.out.println(label+"=======");
PluginBean plug=new PluginBean();
plug.setLabel(label);
plug.setPakageName(packageName);
plugins.add(plug);
}
return plugins;
}
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2078次
    • 积分:180
    • 等级:
    • 排名:千里之外
    • 原创:16篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类