Access a usb flash drive from the terminal
1.Find what the drive is called
You'll need to know what the drive is called to mount it. To do that fire off:
sudo fdisk -l
You're looking for a partition that should look something like: /dev/sdb1. Remember what it's called.
2.Create a mount point
Create a new directory in /media so you can mount the drive onto the filesystem:
sudo mkdir /media/usb
3.Mount!
sudo mount /dev/sdb1 /media/usb
When you're done, just fire off:
sudo umount /media/usb
Simple example of loader in android
- User.java
public class User { private String mName; public User(String mName) { this.mName = mName; } public String getmName() { return mName; } public void setmName(String mName) { this.mName = mName; } }
- DataLoader.java
public class DataLoader extends Loader<List<User>> { private List<User> mData; public DataLoader(Context context) { super(context); } @Override protected void onStartLoading() { if (mData != null) { deliverResult(mData); } if (takeContentChanged() || mData == null) { forceLoad(); } } @Override public void forceLoad() { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } List<User> data = new ArrayList<>(); data.add(new User("Tuan")); data.add(new User("Thuy")); data.add(new User("Hanh")); data.add(new User("Linh")); data.add(new User("Huyen")); data.add(new User("Dan")); data.add(new User("Tam")); data.add(new User("Thuy")); deliverResult(data); } @Override public void deliverResult(List<User> data) { mData = data; super.deliverResult(data); } @Override protected void onReset() { super.onReset(); mData = null; } }
- activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="16dp" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp"> <TextView android:id="@+id/tvResult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> </ScrollView>
- MainActivity.java
public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<List<User>> { private TextView tvResult; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvResult = (TextView) findViewById(R.id.tvResult); getSupportLoaderManager().initLoader(0, null, this); } @Override public Loader<List<User>> onCreateLoader(int id, Bundle args) { return new DataLoader(MainActivity.this); } @Override public void onLoadFinished(Loader<List<User>> loader, List<User> data) { StringBuilder stringBuilder = new StringBuilder(); for (User user : data) { stringBuilder.append(user.getmName() + "\n"); } tvResult.setText(stringBuilder.toString()); } @Override public void onLoaderReset(Loader<List<User>> loader) { tvResult.setText(""); } }
- Result
Programmatically set the listSelector for a ListView to the default for the current theme
private static void setDefaultListSelector(ListView listView, Context context) { TypedArray typedArray = context .obtainStyledAttributes(null, new int[]{android.R.attr.listSelector}, android.R.attr.listViewStyle, 0); Drawable drawable = typedArray.getDrawable(0); listView.setSelector(drawable); }
Get application version name
adb shell shell@device-name:/ dumpsys package your-package-name | grep version