以grep -r 來遞迴式搜尋字串,但grep -r 其實無法非常完整的遞迴,
下面利用xargs將前面使用的資料傳遞到後面當作參數的特性,
來進行較快速且較完整的字串搜尋。
find -iname "*"|xargs grep "reboot" // reboot替代成你想要搜尋的字串
在*處進行一些處理就可以進行其他簡單的篩選。
比如只找c語言的檔案: "*.c"
find -iname "*"|xargs grep "reboot" // reboot替代成你想要搜尋的字串
<?xml version="1.0" encoding="utf-8"?> <manifest ... > <application android:icon="@drawable/app_icon.png" ... > <activity android:name="com.example.project.ExampleActivity" android:label="@string/example_label" ... > </activity> ... </application> </manifest>在
<application> 元素裡,android:icon屬性指向一個用以辨認這個app的圖示的資源。BroadcastReceiver 物件),registerReceiver()來向系統進行註冊。<intent-filter>元素,作為組件的聲明元素的子元素,echo "c" > /proc/sysrq-trigger // 讓系統當機
echo "b" > /proc/sysrq-trigger // 重啟
echo "m" > /proc/sysrq-trigger // 送出memory information (view /val/log/message)
echo "p" > /proc/sysrq-trigger // 送出當下的CPU暫存器和flag的值
echo "t" > /proc/sysrq-trigger // 送出thread information
echo "s" > /proc/sysrq-trigger // 重新掛載所有的文件系統
echo "u" > /proc/sysrq-trigger // 重新掛載所有的文件系統成唯讀
fastboot devices #查看處在fastboot模式的裝置 fastboot reboot #讓裝置重新開機 fastboot flash recovery recovery.img #將要刷機的.img檔刷到對應的分區
cu: open (/dev/ttyUSB0): Permission denied cu: /dev/ttyUSB0: Line in use
sudo rm /var/lock/LCK..ttyUSB02. 將目標的port的擁有者改成uucp(cu的上層指令)
sudo chown uucp /dev/ttyUSB03. 最後再使用cu -l來觀看
sudo cu -l /dev/ttyUSB0但說實在的,如果沒有需要將東西寫到port去的話,
sudo cat /dev/ttyUSB0
adb root // 取得root權限 // 這兩行在當你需要從device將檔案進行讀寫時需要設定 adb remount adb shell mount -o remount,rw rootfs // 將當前的Kernel Log輸出到檔案 adb shell dmesg > kernelLog.txt // 當mBootCompleted=true時,代表已經開機完成進待機畫面了! adb shell dumpsys power|grep "mBootCompleted=true"
adb devices // 如果順利連線應可以看到有列出裝置 adb reboot // 將裝置重開 adb shell dumpsys power|grep -i mBootCompleted最後一行代表將資訊裡的mBootCompleted的該行抓出,
SpellCheckerService的subclassSpellCheckerService實作了Service class,SpellCheckerService.Session物件SpellCheckerService.Session的實作SentenceSuggestionsInfo的陣列,onCancel(),以處理requests來取消拼字檢查;onGetSuggestionsMultiple(),<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.samplespellcheckerservice" > <application android:label="@string/app_name" > <service android:label="@string/app_name" android:name=".SampleSpellCheckerService" android:permission="android.permission.BIND_TEXT_SERVICE" > <intent-filter > <action android:name="android.service.textservice.SpellCheckerService" /> </intent-filter> <meta-data android:name="android.view.textservice.scs" android:resource="@xml/spellchecker" /> </service> <activity android:label="@string/sample_settings" android:name="SpellCheckerSettingsActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> </intent-filter> </activity> </application> </manifest>
BIND_TEXT_SERVICE的permission ,<spell-checker xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/spellchecker_name" android:settingsActivity="com.example.SpellCheckerSettingsActivity"> <subtype android:label="@string/subtype_generic" android:subtypeLocale="en” /> <subtype android:label="@string/subtype_generic" android:subtypeLocale="fr” /> </spell-checker>
action.view.InputMethod的intent filter,BIND_INPUT_METHOD的權限許可,<!-- Declares the input method service --> <service android:name="FastInputIME" android:label="@string/fast_input_label" android:permission="android.permission.BIND_INPUT_METHOD"> <intent-filter> <action android:name="android.view.InputMethod" /> </intent-filter> <meta-data android:name="android.view.im" android:resource="@xml/method" /> </service>
ACTION_MAIN的intent filter,<!-- Optional: an activity for controlling the IME settings --> <activity android:name="FastInputIMESettings" android:label="@string/fast_input_settings"> <intent-filter> <action android:name="android.intent.action.MAIN"/> </intent-filter> </activity>
KeyEvent的class對於處理鍵盤字元來說很重要。InputMethodService的class。InputMethodService的class提供了大多數的實作,InputConnection。View的延伸,render了鍵盤,Keyboard實例所指定,onCreateInputView() method的範例:@Override public View onCreateInputView() { MyKeyboardView inputView = (MyKeyboardView) getLayoutInflater().inflate( R.layout.input, null); inputView.setOnKeyboardActionListener(this); inputView.setKeyboard(mLatinKeyboard); return mInputView; }
KeyboardView的實作的實例,onStartInputView(),inputType field包含了text field的input type。inputType field是一個int,TYPE_MASK_CLASS來做遮罩(mask),像這樣:inputType & InputType.TYPE_MASK_CLASS
TYPE_CLASS_TEXT的變數,作為輸入密碼用。CharSequence,CharSequence,CharSequence到text field,並且設定一個新的游標位置。InputConnection ic = getCurrentInputConnection(); ic.deleteSurroundingText(4, 0); ic.commitText("Hello", 1); ic.commitText("!", 1);
InputConnection ic = getCurrentInputConnection(); ic.setComposingText("Composi", 1); ... ic.setComposingText("Composin", 1); ... ic.commitText("Composing ", 1);
<input-method xmlns:android="http://schemas.android.com/apk/res/android" android:settingsActivity="com.example.softkeyboard.Settings" android:icon="@drawable/ime_icon" <subtype android:name="@string/display_name_english_keyboard_ime" android:icon="@drawable/subtype_icon_english_keyboard_ime" android:imeSubtypeLanguage="en_US" android:imeSubtypeMode="keyboard" android:imeSubtypeExtraValue="somePrivateOption=true" /> <subtype android:name="@string/display_name_french_keyboard_ime" android:icon="@drawable/subtype_icon_french_keyboard_ime" android:imeSubtypeLanguage="fr_FR" android:imeSubtypeMode="keyboard" android:imeSubtypeExtraValue="foobar=30,someInternalOption=false" /> <subtype android:name="@string/display_name_german_keyboard_ime" ... /> />
<subtype android:label="@string/label_subtype_generic" android:imeSubtypeLocale="en_US" android:icon="@drawable/icon_en_us" android:imeSubtypeMode="keyboard" />
<string name="label_subtype_generic">%s</string>
InputMethodSettingsFragment.java的檔案Intent。這支援了複製app捷徑。ClipData物件。ClipData。ClipData包含一個ClipDescription物件,ClipData.Item物件。ClipDescription物件,ClipData物件,當中單一個物件包含了一個文字string。ClipDescription裡。content: URI的URI,MIMETYPE_TEXT_URILIST。ClipData.Item 物件包含一個Intent。MIMETYPE_TEXT_INTENT。newIntent()來從一個Intent物件來製作一個clip。ClipData.Item.coerceToText()的method,ClipData.Item裡的資料轉換成文字,CharSequence。getText()不為null),coerceToText()回傳其文字。getUri()不為null),coerceToText()嘗試使用它來當作一個content URI:coerceToText()回傳一個文字串流。Uri.toString()所回傳的是相同的。coerceToText()回傳一個URI的表示式。Uri.toString()所回傳的是相同的。coerceToText()將它轉換成一個Intent URI並回傳之。Intent.toUri(URI_INTENT_SCHEME)回傳的是一樣的。ClipboardManager的全域剪貼簿。ClipData.Item物件,ClipDescription。ClipData,ClipData.Item,ClipData.Item所指向的content provider取得資料。ClipboardManager物件,ClipData物件,加上一個ClipDescription,ClipData.Item物件上去,ClipData物件到ClipboardManager物件。... // if the user selects copy case R.id.menu_copy: // Gets a handle to the clipboard service. ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
// Creates a new text clip to put on the clipboard ClipData clip = ClipData.newPlainText("simple text","Hello, World!");
// Creates a Uri based on a base Uri and a record ID based on the contact's last name // Declares the base URI string private static final String CONTACTS = "content://com.example.contacts"; // Declares a path string for URIs that you use to copy data private static final String COPY_PATH = "/copy"; // Declares the Uri to paste to the clipboard Uri copyUri = Uri.parse(CONTACTS + COPY_PATH + "/" + lastName); ... // Creates a new URI clip object. The system uses the anonymous getContentResolver() object to // get MIME types from provider. The clip object's label is "URI", and its data is // the Uri previously created. ClipData clip = ClipData.newUri(getContentResolver(),"URI",copyUri);
// Creates the Intent Intent appIntent = new Intent(this, com.example.demo.myapplication.class); ... // Creates a clip object with the Intent in it. Its label is "Intent" and its data is // the Intent object created previously ClipData clip = ClipData.newIntent("Intent",appIntent);
// Set the clipboard's primary clip. clipboard.setPrimaryClip(clip);
getSystemService(CLIPBOARD_SERVICE),ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); String pasteData = "";
// Gets the ID of the "paste" menu item MenuItem mPasteItem = menu.findItem(R.id.menu_paste); // If the clipboard doesn't contain data, disable the paste menu item. // If it does contain data, decide if you can handle the data. if (!(clipboard.hasPrimaryClip())) { mPasteItem.setEnabled(false); } else if (!(clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN))) { // This disables the paste menu item, since the clipboard has data but it is not plain text mPasteItem.setEnabled(false); } else { // This enables the paste menu item, since the clipboard contains plain text. mPasteItem.setEnabled(true); } }
// Responds to the user selecting "paste" case R.id.menu_paste: // Examines the item on the clipboard. If getText() does not return null, the clip item contains the // text. Assumes that this application can only handle one item at a time. ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); // Gets the clipboard as text. pasteData = item.getText(); // If the string contains data, then the paste operation is done if (pasteData != null) { return; // The clipboard does not contain text. If it contains a URI, attempts to get data from it } else { Uri pasteUri = item.getUri(); // If the URI contains something, try to get text from it if (pasteUri != null) { // calls a routine to resolve the URI and get data from it. This routine is not // presented here. pasteData = resolveUri(Uri); return; } else { // Something is wrong. The MIME type was plain text, but the clipboard does not contain either // text or a Uri. Report an error. Log.e("Clipboard contains an invalid data type"); return; } }
ClipData.Item物件包含了一個content URI,ContentResolver然後呼叫適合的content provider程序來取得資料。// Declares a MIME type constant to match against the MIME types offered by the provider public static final String MIME_TYPE_CONTACT = "vnd.android.cursor.item/vnd.example.contact"
// Gets a handle to the Clipboard Manager ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); // Gets a content resolver instance ContentResolver cr = getContentResolver();
// Gets the clipboard data from the clipboard ClipData clip = clipboard.getPrimaryClip(); if (clip != null) { // Gets the first item from the clipboard data ClipData.Item item = clip.getItemAt(0); // Tries to get the item's contents as a URI Uri pasteUri = item.getUri();
// If the clipboard contains a URI reference if (pasteUri != null) { // Is this a content URI? String uriMimeType = cr.getType(pasteUri);
ContentResolver.query()來取得資料。Cursor:// If the return value is not null, the Uri is a content Uri if (uriMimeType != null) { // Does the content provider offer a MIME type that the current application can use? if (uriMimeType.equals(MIME_TYPE_CONTACT)) { // Get the data from the content provider. Cursor pasteCursor = cr.query(uri, null, null, null, null); // If the Cursor contains data, move to the first record if (pasteCursor != null) { if (pasteCursor.moveToFirst()) { // get the data from the Cursor here. The code will vary according to the // format of the data model. } } // close the Cursor pasteCursor.close(); } } } }
// Gets a handle to the Clipboard Manager ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); // Checks to see if the clip item contains an Intent, by testing to see if getIntent() returns null Intent pasteIntent = clipboard.getPrimaryClip().getItemAt(0).getIntent(); if (pasteIntent != null) { // handle the Intent } else { // ignore the clipboard, or issue an error if your application was expecting an Intent to be // on the clipboard }
"content://com.example.contacts"
String uriString = "content://com.example.contacts" + "/" + "Smith" // uriString now contains content://com.example.contacts/Smith. // Generates a uri object from the string representation Uri copyUri = Uri.parse(uriString);
"content://com.example.contacts"/people"content://com.example.contacts"/people/detail"content://com.example.contacts"/people/images
"content://com.example.contacts/copying"
ContentProvider的subclass。newUri()會呼叫getType(),insert()或update()。// Declares the base URI string private static final String CONTACTS = "content://com.example.contacts"; // Declares a path string for URIs that you use to copy data private static final String COPY_PATH = "/copy"; // Declares a MIME type for the copied data public static final String MIME_TYPE_CONTACT = "vnd.android.cursor.item/vnd.example.contact"
public class MyCopyActivity extends Activity { ... // The user has selected a name and is requesting a copy. case R.id.menu_copy: // Appends the last name to the base URI // The name is stored in "lastName" uriString = CONTACTS + COPY_PATH + "/" + lastName; // Parses the string into a URI Uri copyUri = Uri.parse(uriString); // Gets a handle to the clipboard service. ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newUri(getContentResolver(), "URI", copyUri); // Set the clipboard's primary clip. clipboard.setPrimaryClip(clip);
public class MyCopyProvider extends ContentProvider { ... // A Uri Match object that simplifies matching content URIs to patterns. private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH); // An integer to use in switching based on the incoming URI pattern private static final int GET_SINGLE_CONTACT = 0; ... // Adds a matcher for the content URI. It matches // "content://com.example.contacts/copy/*" sUriMatcher.addURI(CONTACTS, "names/*", GET_SINGLE_CONTACT);
query()的method設定好。這個method可以處理不同的URI樣式,// Sets up your provider's query() method. public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { ... // Switch based on the incoming content URI switch (sUriMatcher.match(uri)) { case GET_SINGLE_CONTACT: // query and return the contact for the requested name. Here you would decode // the incoming URI, query the data model based on the last name, and return the result // as a Cursor. ... }
// Sets up your provider's getType() method. public String getType(Uri uri) { ... switch (sUriMatcher.match(uri)) { case GET_SINGLE_CONTACT: return (MIME_TYPE_CONTACT);
Cursor物件。ContentProvider methods來回傳一個file descriptor給串流。ContentResolver method呼叫了對應ContentProvider的 method。ContentResolver method,ContentResolver裡openAssetFile()的analog,openAssetFileDescriptor():AssetFileDescriptor檔案handleopenTypedAssetFile()更普遍的的格式。openTypedAssetFile()更普遍的格式。openPipeHelper()這個method,ContentProvider.PipeDataWriter的介面。ClipData.Item物件的意圖,ClipData.Item物件在相同一個cilp裡,ClipDescription,coerceToText()。