Android imports mobile phone Images

Source: Internet
Author: User

Android imports mobile phone Images
User behavior users use mobile phones to take photos. Users can download photos on webpages, online storage, Weibo photos, and mobile phones to import photos to SD cards, import the added photos to the program and upload the Implementation ideas to listen to the camera app. If a user takes a photo, an Intent may be triggered, send Broadcast notifications to other programs public static final String ACTION_NEW_PICTUREAdded in API level 14 Broadcast Action: A new picture is taken by the camera, and the entry of the picture has been added to the media store. getData () is URI of the picture. constant Value: "android. hardware. action. NEW_PICTURE "pub Lic static final String ACTION_NEW_VIDEO Added in API level 14 Broadcast Action: A new video is recorded by the camera, and the entry of the video has been added to the media store. getData () is URI of the video. constant Value: "android. hardware. action. NEW_VIDEO "code public class CameraEventReciver extends BroadcastReceiver {@ Overridepublic void onReceive (Context context, Intent intent) {Cursor c Ursor = context. getContentResolver (). query (intent. getData (), null, null); cursor. moveToFirst (); String image_path = cursor. getString (cursor. getColumnIndex ("_ data"); Toast. makeText (context, "New Photo is Saved as:-" + image_path, 1000 ). show () ;}< er android: name = "sample. grass. category. mediastore. cameraEventReciver "android: enabled =" true "android: exported =" true "> <intent-filter> <Action android: name = "android. hardware. action. NEW_PICTURE "/> <category android: name =" android. intent. category. DEFAULT "/> <data android: mimeType =" image/* "/> </intent-filter> </receiver> test result: the user can listen to the photo taken by the user, however, only the system camera can be used. Other camera apk may receive broadcasts, and may not receive the advantage. Even if the application is not started, notifications can be received, the wake-up feature. Some camera applications do not enable broadcasting, so they are not completely dependent. Users cannot monitor downloading images or importing photos to the Meida database. No matter which camera the user uses to take photos, whether the user imports an image to the SD card or downloads a photo to the mobile phone will cause changes in the Media database, listen to this change, and import the photo to the Trunx code Ss UriObserver extends ContentObserver {public UriObserver (Handler handler) {super (handler); // TODO Auto-generated constructor stub} @ Override public void onChange (boolean selfChange) {// TODO Auto-generated method stub super. onChange (selfChange); Log. d ("INSTANT", "getting changes") ;}} UriObserver observer = new UriObserver (new Handler (); this. getApplicationContext (). getContentResolver (). re GisterContentObserver (MediaStore. images. media. EXTERNAL_CONTENT_URI, false, observer); advantage: You can listen to the user to Import images, the user downloads images, the user uses a variety of third-party cameras to take pictures disadvantages depend on the program is started, if the program is killed, the file directory code FileObserver observer = new FileObserver (android. OS. environment. getExternalStorageDirectory (). toString () + "/DCIM/100 MEDIA") {// set up a file observer to watch this directory on sd card @ Override public void onEvent (int event, String file) {I F (event = FileObserver. CREATE &&! File. equals (". probe ") {// check if its a" create "and not equal. probe because thats created every time camera is launched Log. d (TAG, "File created [" + android. OS. environment. getExternalStorageDirectory (). toString () + "/DCIM/100 MEDIA/" + file + "]"); fileSaved = "New photo Saved:" + file ;}}; observer. startWatching (); // start the observer advantages: it can listen to all the above user behavior disadvantages need to be hard-coded, and there are too many directories to listen to, which is half the effort

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.