SlideShare a Scribd company logo
Android
Assets
What is Assets ?
 Assets provide a way to include arbitrary files like text, xml, fonts, music,
and video in your application. If you try to include these files as "resources",
Android will process them into its resource system and you will not be able to
get the raw data. If you want to access data untouched, Assets are one way to
do it.
 Assets added to your project will show up just like a file system that can read
from by your application using AssetManager.
How to read file .json from Assets?
 Step follow up
 1. Make asset folder .
 2.Cope file .Json ,.xml…. In put Asset folder.(app_info_json.json)
 3.Implement code call file .Json ,.xml from Asset folder in Java class : Example below
 Asset:
 GridAdapter:
 ArrayList:
 JSONObject:
 JSONArray:
 GridView:
 Example
app_info_json.json
 {
 "_app_info":[
 {
 "c_app_id":"com",
 "c_available":"true",
 "c_reason":"2015.",
 "c_name":"dary"
 },
 {
 "c_app_id":"com1",
 "c_available":"true",
 "c_reason":"",
 "c_name":"jaja"
 },
 {
 "c_app_id":"com2",
 "c_available":"true",
 "c_reason":"",
 "c_name":"dada"
 }
 ]
 }
Example Asset(MantActivity.Java)
 public String readJSONFromAsset() {
 String json = "";
 try {
 InputStream is = getAssets().open("app_info_json.json");
 int size = is.available();
 byte[] buffer = new byte[size];
 is.read(buffer);
 is.close();
 json = new String(buffer, "UTF-8");
 } catch (IOException ex) {
 ex.printStackTrace();
 return null;
 }
 return json;
 }
GridAdapter(MantActivity.Java)
 GridAdapter adapter = new GridAdapter(this, appList);
 public class GridAdapter extends BaseAdapter {
 Context context;
 List<AppInfo> appList;
 public GridAdapter(Context context, List<AppInfo> menuList) {
 this.context = context;
 this.appList = menuList;
 }
ArrayList,JSONObject,JSONArray
 appList = new ArrayList<AppInfo>();
 JSONObject obj = new JSONObject(readJSONFromAsset());
 Log.d("JSON", "JSON >>> " + obj.getString("_app_info"));

 JSONArray formArray = obj.getJSONArray("_app_info");
 for (int i = 0; i < formArray.length(); i++){
 JSONObject object =formArray.getJSONObject(i);
 String c_app_id = object.getString("c_app_id");
 boolean c_available = object.getBoolean("c_available");
 String c_reason = object.getString("c_reason");
 String c_name = object.getString("c_name");
 appList.add(new AppInfo(i, getResources().getIdentifier(
 getResources().getStringArray(R.array.app_icon)[i],
 "drawable", getPackageName()),getResources().getIdentifier(getResources().getStringArray(R.array.grey_app_icon)[i], "drawable",
getPackageName()), c_name, c_app_id, c_available,c_reason));
GridView
 GridAdapter adapter = new GridAdapter(this, appList);
 mAppGridView = new GridView(this);
 mAppGridView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
 mAppGridView.setPadding(19, 45, 19, 0);
 mAppGridView.setVerticalSpacing(21);
 mAppGridView.setHorizontalSpacing(23);
 mAppGridView = (GridView) findViewById(R.id.more_app_gridview);
 mAppGridView.setNumColumns(4);
 mAppGridView.setAdapter(adapter);
 mAppGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
 @Override
 public void onItemClick(AdapterView<?> parent,
 View view, int position, long id) {
 try {
Data of .Json
 public class AppInfo {
 int app_no;
 int app_icon;
 int grey_app_icon;
 String app_name;
 String app_pakage;
 Boolean c_available;
 String c_reason;
Data of .Json
 AppInfo(int app_no, int app_icon, int grey_app_icon, String app_name,
 String app_pakage, Boolean c_available, String c_reason) {
 this.app_no = app_no;
 this.app_icon = app_icon;
 this.grey_app_icon = grey_app_icon;
 this.app_name = app_name;
 this.app_pakage = app_pakage;
 this.c_available = c_available;
 this.c_reason = c_reason;
 }
 public String getApp_pakage() {
 return app_pakage;
 }
 public void setApp_pakage(String app_pakage) {
 this.app_pakage = app_pakage;
 }
MantActivity.XML
 <GridView
 android:id="@+id/more_app_gridview"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_marginBottom="30dp"
 android:columnWidth="175dp"
 android:listSelector="@drawable/selector_grid_view_btn_basic"
 android:gravity="center"
 android:stretchMode="columnWidth" >
 </GridView>
The end

More Related Content

What's hot (19)

PPTX
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
PDF
Android crashcourse
Alexey Buzdin
 
PDF
자마린.안드로이드 기본 내장레이아웃(Built-In List Item Layouts)
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
PDF
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
PPT
Android Bootcamp Tanzania:intents
Denis Minja
 
PPTX
Presentation1
Anand Grewal
 
PPTX
PostgreSQL's Secret NoSQL Superpowers
Amanda Gilmore
 
PPTX
Cloud native programming model comparison
Emily Jiang
 
PDF
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
DEEPANSHU GUPTA
 
PDF
Hash set (java platform se 8 )
charan kumar
 
DOCX
Animal Project
Ahmed Ali
 
PDF
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
DicodingEvent
 
PPTX
Ian 2014.10.24 weekly report
LearningTech
 
PPT
Web api's
umesh patil
 
PPTX
FUNctional Programming in Java 8
Richard Walker
 
PDF
Android Lesson 3 - Intent
Daniela Da Cruz
 
PDF
Radgrid
Aravindharamanan S
 
PPT
PyCon India 2010 Building Scalable apps using appengine
Pranav Prakash
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
Android crashcourse
Alexey Buzdin
 
자마린.안드로이드 기본 내장레이아웃(Built-In List Item Layouts)
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Android Bootcamp Tanzania:intents
Denis Minja
 
Presentation1
Anand Grewal
 
PostgreSQL's Secret NoSQL Superpowers
Amanda Gilmore
 
Cloud native programming model comparison
Emily Jiang
 
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
DEEPANSHU GUPTA
 
Hash set (java platform se 8 )
charan kumar
 
Animal Project
Ahmed Ali
 
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
DicodingEvent
 
Ian 2014.10.24 weekly report
LearningTech
 
Web api's
umesh patil
 
FUNctional Programming in Java 8
Richard Walker
 
Android Lesson 3 - Intent
Daniela Da Cruz
 
PyCon India 2010 Building Scalable apps using appengine
Pranav Prakash
 

Similar to Example asset (20)

KEY
CouchDB on Android
Sven Haiges
 
PDF
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
PPT
Synapseindia android apps introduction hello world
Tarunsingh198
 
PDF
Minicurso Android
Mario Jorge Pereira
 
PPTX
Android Application Fundamentals.
Skillwise Consulting
 
PDF
第一次用Parse就深入淺出
Ymow Wu
 
PDF
JavaScript Lessons 2023 V2
Laurence Svekis ✔
 
DOC
Android Application DevlopmentManual-1.doc
KiranmaiBejjam1
 
DOCX
Android resources in android-chapter9
Dr. Ramkumar Lakshminarayanan
 
PDF
Cross-Platform Native Mobile Development with Eclipse
Peter Friese
 
PDF
Cross-Platform Data Access for Android and iPhone
Peter Friese
 
DOCX
Leture5 exercise onactivities
maamir farooq
 
DOCX
Lecture exercise on activities
maamir farooq
 
KEY
Android開発の基礎_20101218
Takahiro (Poly) Horikawa
 
PDF
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Red Hat Developers
 
PDF
Android stepbystep
Krazy Koder
 
PDF
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Alberto Ruibal
 
PPTX
Android Tutorials - Powering with Selection Widget
Prajyot Mainkar
 
PDF
Mini curso Android
Mario Jorge Pereira
 
CouchDB on Android
Sven Haiges
 
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
Synapseindia android apps introduction hello world
Tarunsingh198
 
Minicurso Android
Mario Jorge Pereira
 
Android Application Fundamentals.
Skillwise Consulting
 
第一次用Parse就深入淺出
Ymow Wu
 
JavaScript Lessons 2023 V2
Laurence Svekis ✔
 
Android Application DevlopmentManual-1.doc
KiranmaiBejjam1
 
Android resources in android-chapter9
Dr. Ramkumar Lakshminarayanan
 
Cross-Platform Native Mobile Development with Eclipse
Peter Friese
 
Cross-Platform Data Access for Android and iPhone
Peter Friese
 
Leture5 exercise onactivities
maamir farooq
 
Lecture exercise on activities
maamir farooq
 
Android開発の基礎_20101218
Takahiro (Poly) Horikawa
 
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Red Hat Developers
 
Android stepbystep
Krazy Koder
 
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Alberto Ruibal
 
Android Tutorials - Powering with Selection Widget
Prajyot Mainkar
 
Mini curso Android
Mario Jorge Pereira
 
Ad

Recently uploaded (20)

PPTX
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
PPTX
Networking_Essentials_version_3.0_-_Module_3.pptx
ryan622010
 
PDF
AI security AI security AI security AI security
elite44
 
PDF
Strategic Plan New and Completed Templeted
alvi932317
 
PDF
Empowering Local Language Email with IDN & EAI – Powered by XgenPlus
XgenPlus Technologies
 
PPTX
CHAPTER 1 - PART 3 FOR GRADE 11 STUDENTS
FSBTLEDNathanVince
 
PDF
web application development company in bangalore.pdf
https://dkpractice.co.in/seo.html tech
 
PDF
BRKAPP-1102 - Proactive Network and Application Monitoring.pdf
fcesargonca
 
PPTX
美国电子毕业证帕克大学电子版成绩单UMCP学费发票办理学历认证
Taqyea
 
PPTX
Academic Debate: Creation vs Evolution.pptx
JOHNPATRICKMARTINEZ5
 
PPTX
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
PDF
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
PDF
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
PPTX
原版一样(LHU毕业证书)英国利物浦希望大学毕业证办理方法
Taqyea
 
PPTX
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
PPTX
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
Meloniusk_Communication_Template_best.pptx
howesix147
 
PDF
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
PDF
The Internet - By the numbers, presented at npNOG 11
APNIC
 
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
Networking_Essentials_version_3.0_-_Module_3.pptx
ryan622010
 
AI security AI security AI security AI security
elite44
 
Strategic Plan New and Completed Templeted
alvi932317
 
Empowering Local Language Email with IDN & EAI – Powered by XgenPlus
XgenPlus Technologies
 
CHAPTER 1 - PART 3 FOR GRADE 11 STUDENTS
FSBTLEDNathanVince
 
web application development company in bangalore.pdf
https://dkpractice.co.in/seo.html tech
 
BRKAPP-1102 - Proactive Network and Application Monitoring.pdf
fcesargonca
 
美国电子毕业证帕克大学电子版成绩单UMCP学费发票办理学历认证
Taqyea
 
Academic Debate: Creation vs Evolution.pptx
JOHNPATRICKMARTINEZ5
 
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
原版一样(LHU毕业证书)英国利物浦希望大学毕业证办理方法
Taqyea
 
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
Meloniusk_Communication_Template_best.pptx
howesix147
 
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
The Internet - By the numbers, presented at npNOG 11
APNIC
 
Ad

Example asset

  • 2. What is Assets ?  Assets provide a way to include arbitrary files like text, xml, fonts, music, and video in your application. If you try to include these files as "resources", Android will process them into its resource system and you will not be able to get the raw data. If you want to access data untouched, Assets are one way to do it.  Assets added to your project will show up just like a file system that can read from by your application using AssetManager.
  • 3. How to read file .json from Assets?  Step follow up  1. Make asset folder .  2.Cope file .Json ,.xml…. In put Asset folder.(app_info_json.json)  3.Implement code call file .Json ,.xml from Asset folder in Java class : Example below  Asset:  GridAdapter:  ArrayList:  JSONObject:  JSONArray:  GridView:  Example
  • 4. app_info_json.json  {  "_app_info":[  {  "c_app_id":"com",  "c_available":"true",  "c_reason":"2015.",  "c_name":"dary"  },  {  "c_app_id":"com1",  "c_available":"true",  "c_reason":"",  "c_name":"jaja"  },  {  "c_app_id":"com2",  "c_available":"true",  "c_reason":"",  "c_name":"dada"  }  ]  }
  • 5. Example Asset(MantActivity.Java)  public String readJSONFromAsset() {  String json = "";  try {  InputStream is = getAssets().open("app_info_json.json");  int size = is.available();  byte[] buffer = new byte[size];  is.read(buffer);  is.close();  json = new String(buffer, "UTF-8");  } catch (IOException ex) {  ex.printStackTrace();  return null;  }  return json;  }
  • 6. GridAdapter(MantActivity.Java)  GridAdapter adapter = new GridAdapter(this, appList);  public class GridAdapter extends BaseAdapter {  Context context;  List<AppInfo> appList;  public GridAdapter(Context context, List<AppInfo> menuList) {  this.context = context;  this.appList = menuList;  }
  • 7. ArrayList,JSONObject,JSONArray  appList = new ArrayList<AppInfo>();  JSONObject obj = new JSONObject(readJSONFromAsset());  Log.d("JSON", "JSON >>> " + obj.getString("_app_info"));   JSONArray formArray = obj.getJSONArray("_app_info");  for (int i = 0; i < formArray.length(); i++){  JSONObject object =formArray.getJSONObject(i);  String c_app_id = object.getString("c_app_id");  boolean c_available = object.getBoolean("c_available");  String c_reason = object.getString("c_reason");  String c_name = object.getString("c_name");  appList.add(new AppInfo(i, getResources().getIdentifier(  getResources().getStringArray(R.array.app_icon)[i],  "drawable", getPackageName()),getResources().getIdentifier(getResources().getStringArray(R.array.grey_app_icon)[i], "drawable", getPackageName()), c_name, c_app_id, c_available,c_reason));
  • 8. GridView  GridAdapter adapter = new GridAdapter(this, appList);  mAppGridView = new GridView(this);  mAppGridView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  mAppGridView.setPadding(19, 45, 19, 0);  mAppGridView.setVerticalSpacing(21);  mAppGridView.setHorizontalSpacing(23);  mAppGridView = (GridView) findViewById(R.id.more_app_gridview);  mAppGridView.setNumColumns(4);  mAppGridView.setAdapter(adapter);  mAppGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {  @Override  public void onItemClick(AdapterView<?> parent,  View view, int position, long id) {  try {
  • 9. Data of .Json  public class AppInfo {  int app_no;  int app_icon;  int grey_app_icon;  String app_name;  String app_pakage;  Boolean c_available;  String c_reason;
  • 10. Data of .Json  AppInfo(int app_no, int app_icon, int grey_app_icon, String app_name,  String app_pakage, Boolean c_available, String c_reason) {  this.app_no = app_no;  this.app_icon = app_icon;  this.grey_app_icon = grey_app_icon;  this.app_name = app_name;  this.app_pakage = app_pakage;  this.c_available = c_available;  this.c_reason = c_reason;  }  public String getApp_pakage() {  return app_pakage;  }  public void setApp_pakage(String app_pakage) {  this.app_pakage = app_pakage;  }
  • 11. MantActivity.XML  <GridView  android:id="@+id/more_app_gridview"  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:layout_marginBottom="30dp"  android:columnWidth="175dp"  android:listSelector="@drawable/selector_grid_view_btn_basic"  android:gravity="center"  android:stretchMode="columnWidth" >  </GridView>