2013-01-21 58 views
8

में एक छवि डालने की अनुमति देता है मेरा प्रश्न है: छवि बटन कैसे बनाएं जिससे उपयोगकर्ता अपने फोन से छवि अपलोड कर सके और उसे चित्र प्रोफ़ाइल के रूप में एप्लिकेशन में डालने की अनुमति दे? उदाहरण के लिए व्हाट्सएप की तरह यह उपयोगकर्ता को फोन से छवि चुनने और एक तस्वीर प्रोफाइल के रूप में सेट करने की अनुमति देता है।उपयोगकर्ता को एंड्रॉइड ऐप

धन्यवाद

+0

अगर मेरा उत्तर मदद आप तो जवाब – Janmejoy

उत्तर

7

यहाँ लिंक का अनुसरण कर रहे हैं ..

create image button

छवि अपलोड

example 1

example 2

example 3

+0

लिंक के लिए धन्यवाद स्वीकार करते हैं। मैंने आपके द्वारा प्रदान किए गए उदाहरणों में कोड चलाने में कामयाब रहे। कैसे किसी एप्लिकेशन को किसी खाते के लिए साइन-अप करने की आवश्यकता होती है और उपयोगकर्ता को प्रोफ़ाइल चित्र के रूप में छवि डालना पड़ता है, इसलिए जब उपयोगकर्ता अपने खाते में लॉगिन करता है तो उपयोगकर्ता प्रोफ़ाइल चित्र देख सकता है। तो यह कैसे किया जा सकता है? व्हाट्सएप की तरह ही; वे प्रोफ़ाइल को अपलोड करने वाले चित्रों को कैसे संग्रहीत करते हैं? – Mack

+0

@ मैक का मतलब है कि चित्र अपलोड करें, इसे कई तरीकों से किया जा सकता है, जैसे फेसबुक या ट्विटर से या गैलरी से पार्सिंग – Janmejoy

+0

मेरे पास एक ऐप है जो उपयोगकर्ता को प्रोफ़ाइल के लिए एक तस्वीर डालने के लिए कहता है। मेरा सवाल है: मुझे उपयोगकर्ता चित्र को स्टोर करने की आवश्यकता कहां है? MySQL डीबी, स्क्लाइट डीबी, आंतरिक भंडारण या बाहरी भंडारण? – Mack

0

मेरी एक्सएमएल फ़ाइल

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

<ImageView 
    android:id="@android:id/icon" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:onClick="selectImage" 
    /> 

मेरी फाइल

public class Test extends AppCompatActivity { 
private static final int SELECT_PICTURE = 0; 
private ImageView imageView; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_test); 
    imageView = (ImageView) findViewById(android.R.id.icon); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (resultCode == RESULT_OK) { 
     Bitmap bitmap = getPath(data.getData()); 
     imageView.setImageBitmap(bitmap); 
    } 
} 

private Bitmap getPath(Uri uri) { 

    String[] projection = {MediaStore.Images.Media.DATA}; 
    Cursor cursor = managedQuery(uri, projection, null, null, null); 
    int column_index = cursor 
      .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
    cursor.moveToFirst(); 
    String filePath = cursor.getString(column_index); 
    // cursor.close(); 
    // Convert file path into bitmap image using below line. 
    Bitmap bitmap = BitmapFactory.decodeFile(filePath); 

    return bitmap; 
} 

private void selectImage() { 

    Intent intent = new Intent(); 
    intent.setType("image/*"); 
    intent.setAction(Intent.ACTION_GET_CONTENT); 
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE); 
} 

} 

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^