使用Intent启动第三方应用程序 Android 学习 之 用getIdentifier()获取资源Id

Intent intent=new Intent(Intent.ACTION_SEND);

intent.setClassName("jp.naver.line.android", "jp.naver.line.android.activity.selectchat.SelectChatActivity");

intent.setFlags(Intent. FLAG_ACTIVITY_NEW_TASK);

intent.setType("image/*");

intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(mBean.getAbsolutePath())));

startActivity(intent);

发送到LINE

Java代码   收藏代码
  1. 做项目过程中遇到一个问题,从数据库里读取图片名称,然后调用图片。直接用R.drawable.?无法调用。查了好多地方最后找到了个方法,分享给大家,希望有帮助。   
  2. 主要由两种方法,个人建议第二种。   
  3. 1. 不把图片放在res/drawable下,而是存放在src某个package中(如:com.drawable.resource),这种情况下的调用方法为:   
  4. String path = "com/drawable/resource/imageName.png";   
  5. InputStream is = getClassLoader().getResourceAsStream(path);   
  6. Drawable.createFromStream(is, "src");   
  7.   
  8. 2. 如果还是希望直接使用res/drawable中的图片,就需要通过下面的方法了:   
  9. 假设创建工程的时候,填写的package名字为:com.test.image   
  10. int resID = getResources().getIdentifier("imageName""drawable""com.test.image");   
  11. Drawable image = getResources().getDrawable(resID);   

猜你喜欢

转载自gybin.iteye.com/blog/1930008