Google Accounts Picker Not Showing Up - android

I can not for the life of me figure out why, but my google account intent isn't showing up in a popup dialog. Here is my code and I can provide more of it if needed.
public class MainMenu extends ActionBarActivity implements ActionBar.TabListener {
//... Fragment Code
Intent googlePicker = AccountPicker.newChooseAccountIntent(null, null,
new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null);
startActivityForResult(googlePicker, 1);
}
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (requestCode == 1 && resultCode == RESULT_OK) {
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
Log.d(this.getClass().toString(), "Account Name=" + accountName);
}
}

If you are in a Fragment use
...
getActivity().startActivityForResult(googlePicker, 1);
...

Related

onActivityResult() is not working in fragment " OUTPUT: You haven't picked Image "

This is my code and when i run the code then output will be "**you haven't picked images"**
sdk which i use currently in this app
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.letsget.humanitysavior"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Here is the manifests permissions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Here is the fragment code
public class NewPostPublicFragment extends Fragment {
public NewPostPublicFragment() {
// Required empty public constructor
}
private int PICK_IMAGE_MULTIPLE = 3;
String imageEncoded;
List<String> imagesEncodedList;
private GridView gvGallery;
private NewPostImagesAdapter galleryAdapter;
CarouselView carouselView;
private ArrayList<Uri> mArrayUri;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_new_post_public, container, false);
gvGallery = view.findViewById(R.id.gridview);
ImageView selectimgicon = view.findViewById(R.id.selectimgicon);
ImageView selectvideoicon = view.findViewById(R.id.selectvideoicon);
ImageView selectcameraicon = view.findViewById(R.id.selectcameraicon);
carouselView = view.findViewById(R.id.carouselview);
final TextInputEditText postcategories = view.findViewById(R.id.postcategories);
//carouselView.setPageCount(mThumbIds.length);
//carouselView.setImageListener(imageListener);
//for image selection
selectimgicon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//LOGIC FOR PROFILE PICTURE
selectImagesFromGallery();
}
});
postcategories.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final CharSequence[] items = { "Book", "Cloth", "Electronic", "Furniture", "Bag", "Social Post", "Other" };
AlertDialog.Builder postCategoryBuilder = new AlertDialog.Builder(v.getContext(),AlertDialog.THEME_HOLO_LIGHT);
postCategoryBuilder.setTitle("Select Post Category");
postCategoryBuilder.setIcon(R.mipmap.categoryicon);
postCategoryBuilder.setItems(items, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// the user clicked on colors[which]
postcategories.setText(items[which]);
}
});
postCategoryBuilder.show();
}
});
return view;
}
ImageListener imageListener = new ImageListener() {
#Override
public void setImageForPosition(int position, ImageView imageView) {
//imageView.setImageResource(mThumbIds[position]);
imageView.setImageURI(mArrayUri.get(position));
}
};
private void selectImagesFromGallery() {
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Image"), PICK_IMAGE_MULTIPLE);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
Log.v(TAG, "requestCode=" + requestCode + ", resultCode = "+ resultCode + ", data = " + data);
// When an Image is picked
if (requestCode == PICK_IMAGE_MULTIPLE && resultCode == RESULT_OK && data != null) {
// Get the Image from data
String[] filePathColumn = { MediaStore.Images.Media.DATA };
imagesEncodedList = new ArrayList<String>();
if(data.getData()!=null){
Uri mImageUri = data.getData();
// Get the cursor
Cursor cursor = getActivity().getContentResolver().query(mImageUri,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imageEncoded = cursor.getString(columnIndex);
cursor.close();
ArrayList<Uri> mArrayUri = new ArrayList<Uri>();
mArrayUri.add(mImageUri);
galleryAdapter = new NewPostImagesAdapter(getActivity().getApplicationContext(),mArrayUri);
gvGallery.setAdapter(galleryAdapter);
gvGallery.setVerticalSpacing(gvGallery.getHorizontalSpacing());
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) gvGallery
.getLayoutParams();
mlp.setMargins(0, gvGallery.getHorizontalSpacing(), 0, 0);
carouselView.setPageCount(mArrayUri.size());
carouselView.setImageListener(imageListener);
} else {
if (data.getClipData() != null) {
ClipData mClipData = data.getClipData();
ArrayList<Uri> mArrayUri = new ArrayList<Uri>();
for (int i = 0; i < mClipData.getItemCount(); i++) {
ClipData.Item item = mClipData.getItemAt(i);
Uri uri = item.getUri();
mArrayUri.add(uri);
// Get the cursor
Cursor cursor = getActivity().getContentResolver().query(uri, filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imageEncoded = cursor.getString(columnIndex);
imagesEncodedList.add(imageEncoded);
cursor.close();
galleryAdapter = new NewPostImagesAdapter(getActivity().getApplicationContext(),mArrayUri);
gvGallery.setAdapter(galleryAdapter);
gvGallery.setVerticalSpacing(gvGallery.getHorizontalSpacing());
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) gvGallery
.getLayoutParams();
mlp.setMargins(0, gvGallery.getHorizontalSpacing(), 0, 0);
}
Log.v("LOG_TAG", "Selected Images" + mArrayUri.size());
}
}
} else {
Toast.makeText(getContext(), "You haven't picked Image",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getContext(), "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
}
when I run this app and tap on image button then it open the gallery and select the images after that when i press the done button then it's not display images it just display toast message you haven't picked images
Check these Steps:
Give permission to use camera in AndroidManifest.xml
Use this code to get image properly
String RequestCode=123;
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RequestCode && resultCode== RESULT.OK){
//Here get your image code
}
}
Also Check Toast in your OnActivityResult() method and check if condition is true or false. Probably your if condition is false that's why image is not received from gallery.

Xamarin System Don't know about Android.Graphics.Bitmap

So i was trying to resize images with using android graphics bitmap. There is no error in code but when i build the project it throws out "System.NotSupportedException: Don't know about Android.Graphics.Bitmap" exception.
I tried ticking Common Language Runtime Exceptions and rebuilding the project both didnt work.
Here is my code
[Activity(MainLauncher = false, Theme = "#style/MyTheme")]
public class Duzenle_Activity : ActionBarActivity
{
public static ListView liw;
Intent intent = new Intent();
public Dialog dialog;
public static int toplam_hesap_tutucu;
public static Duzenle_Adapter adapt;
public static TextView toplam;
private BackgroundWorker bw = new BackgroundWorker();
public static int toplam_hesap = 0;
public List<Sepet> gecici_sepet;
List<Yemek_Liste> yemek_ = new List<Yemek_Liste>();
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.menu_duzenle);
var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
SupportActionBar.Title = "Duzenle";
yemek_ = MainActivity.db.selectItem();
liw = FindViewById<ListView>(Resource.Id.listv_duzenle);
adapt = new Duzenle_Adapter(this, Resource.Layout.duzenle_model, yemek_,this);
liw.Adapter = adapt;
var toolbarBottom = FindViewById<Toolbar>(Resource.Id.toolbar_bottom_duzenle);
toolbarBottom.InflateMenu(Resource.Menu.ekle_action);
toolbarBottom.MenuItemClick += (sender, e) =>
{
if (e.Item.TitleFormatted.ToString() == "Ekle")
{
var transaction = FragmentManager.BeginTransaction();
var dialogFragment = new Dialog_Ekle(this);
dialogFragment.Show(transaction, "dialog_fragment");
}
};
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == Result.Ok)
{
Duzenle_Adapter adapter = ((Duzenle_Adapter)liw.Adapter);
Bitmap mBitmap = null;
mBitmap = Android.Provider.MediaStore.Images.Media.GetBitmap(ContentResolver, data.Data);
Bitmap originalImage = BitmapFactory.DecodeByteArray(mBitmap.ToArray<Byte>(), 0, mBitmap.ByteCount);
Bitmap resizedImage = Bitmap.CreateScaledBitmap(originalImage, 25, 25, false);
adapter.al_getir().adresler = resizedImage;
adapter.NotifyDataSetChanged();
Console.WriteLine("ADRES1" + " " + data.Data);
}
}
public void tikla()
{
var imageIntent = new Intent();
imageIntent.SetType("image/*");
imageIntent.SetAction(Intent.ActionGetContent);
StartActivityForResult(
Intent.CreateChooser(imageIntent, "Select photo"), 0);
}
}
And i get the image from gallery as uri.
Edit : Why is it throwing this exception when there is no error in code. Its actually strange. It cant be about the android.graphics library right?
Edit 2 : I save these bitmaps to database and then display it in listview
Bitmap a = sepet[position].adres;
tut.img.SetImageBitmap(a);
Based on what I got earlier from you please try this:
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == Result.Ok)
{
Duzenle_Adapter adapter = ((Duzenle_Adapter)listView1.Adapter);
//adapter.SelectedYemek.ImageUri = data.Data;
var mBitmap = Android.Provider.MediaStore.Images.Media.GetBitmap(ContentResolver, data.Data);
adapter.SelectedYemek.ImageBitmap = Bitmap.CreateScaledBitmap(mBitmap, 80, 80, false);
adapter.NotifyDataSetChanged();
}
}

I am trying to export a single contact from the address book to .vcf. Where am I going wrong?

package com.example.address_book;import android.app.Activity;import android.content.Intent;import android.database.Cursor;import android.net.Uri;import android.os.Bundle;import android.provider.ContactsContract.CommonDataKinds.Phone;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageButton;import android.widget.Toast;
public class MainActivity extends Activity {
private static final int PICK_CONTACT_REQUEST = 1;
String[] num={" "," "};
String number1;
#Overrideprotected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try{ImageButton add_me = (ImageButton) findViewById(R.id.imageButton1);
add_me.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE);startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
});
}catch (Exception e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
int n=0;int n1=0;
if (requestCode == PICK_CONTACT_REQUEST){
if (resultCode == RESULT_OK){
Uri stuff = data.getData();Intent in = new Intent(android.content.Intent.ACTION_VIEW, stuff);
in.setType("text/x-vcard");
startActivity(in);
String[] projection = {Phone.NUMBER};Cursor cursor = getContentResolver().query(stuff, projection, null, null, null);cursor.moveToFirst();
int column = cursor.getColumnIndex(Phone.NUMBER);
number1 = cursor.getString(column);
n++;number1 = number1.replace("-" ,"");
for(int i=0;i<num.length;i++){num[i]=number1;
}
}
}
}
#Overridepublic boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.main, menu);return true;
}
}
Try with this dude it will open your contact jusr pass contactId in this
Intent intent = new Intent(Intent.ACTION_VIEW);
//pass your contact id
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactId));
intent.setData(uri);
mcntxt.startActivity(intent);

startChildActivity issue when working with TabGroupActivity

Fallowing is Home class. I am going to call Pick_contact intent. When ContactNumber view is clicked, device contact list is shown. And the result of picked contact is getting on TabGroupActivity.
public class Home extends Activity{
private static int PICK_CONTACT= 1;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
}
public void ContactNumber(View v)
{
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
parentActivity = (TabGroupActivity)getParent();
parentActivity.startActivityForResult(intent, PICK_CONTACT);
}
}
My TabGroupActivity code is shown below.
public class TabGroupActivity extends ActivityGroup {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == PICK_CONTACT)
{
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
String cNumber="";
if (c.moveToFirst()) {
String id =c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
String hasPhone =c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone.equalsIgnoreCase("1")) {
Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ id,
null, null);
phones.moveToFirst();
cNumber = phones.getString(phones.getColumnIndex("data1"));
System.out.println("number is:"+cNumber);
}
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
QRCodeStaticData.qr_contents=name;
}
}
}
}
}
In this above code when user pick up contact from list, I want to open other child activity. But if user does not pick up contact and just cancel it, user will leave on the home activity. I am not getting how to call child activity inside TabGroupActivity after picking contact. I used below code to call child activity.
Intent intent = new Intent(getParent(), CreateQRCode.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.startChildActivity("CreateQRCode", intent);
But it does not work inside onActivityResult of TabGroupActivity.
Try this...Sorry for the Late Answer
In your TabGroupActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
// Adding the Activities to the tab view
// Blah Blah
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
System.out.println("Success");
if (requestCode == PICK_CONTACT) {
//Here you can launch the Child Activity according to the index
//Here CreateQRCode Activity index is 1 in the TabView
tabHost.setCurrentTab(1);
}
} else {
System.out.println("Fail");
}
}
In your HomeActivity
public void ContactNumber(View view) {
Intent intent = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}

Call onActivityResult for contact in OnCreate() Android

I got this code from another question but I don't know how to call this onActivityResult() class in my onCreate() activity to display the first contact from my phone. Also, what does "if (requestCode == RQS_PICKCONTACT){" and "RQS_PICKCONTACT" stand for? Could someone please clarify?
public class MainActivity extends Activity {
Button buttonReadContact;
TextView textPhone;
final int RQS_PICKCONTACT = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonReadContact = (Button)findViewById(R.id.readcontact);
textPhone = (TextView)findViewById(R.id.phone);
buttonReadContact.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
//Start activity to get contact
/*final Uri uriContact = ContactsContract.Contacts.CONTENT_URI;
Intent intentPickContact = new Intent(Intent.ACTION_PICK, uriContact);
startActivityForResult(intentPickContact, RQS_PICKCONTACT);
*/
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// BoD con't: CONTENT_TYPE instead of CONTENT_ITEM_TYPE
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, RQS_PICKCONTACT);
}});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode == RESULT_OK) {
if(requestCode == RQS_PICKCONTACT) {
Uri returnUri = data.getData();
Cursor cursor = getContentResolver().query(returnUri, null, null, null, null);
if (cursor.moveToNext()) {
int columnIndex_ID = cursor.getColumnIndex(ContactsContract.Contacts._ID);
String contactID = cursor.getString(columnIndex_ID);
int columnIndex_HASPHONENUMBER = cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
String stringHasPhoneNumber = cursor.getString(columnIndex_HASPHONENUMBER);
if(stringHasPhoneNumber.equalsIgnoreCase("1")){
Cursor cursorNum = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactID,
null,
null);
//Get the first phone number
if(cursorNum.moveToNext()){
int columnIndex_number = cursorNum.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String stringNumber = cursorNum.getString(columnIndex_number);
textPhone.setText("0"+stringNumber);
}
} else {
textPhone.setText("NO Phone Number");
}
} else {
Toast.makeText(getApplicationContext(), "NO data!", Toast.LENGTH_LONG).show();
}
}
}
}
When you call startActivityForResult(intent,requestCode)
onActivityResult is called when user comes back to calling activity with
requestCode
//You can start multiple activities by calling startActivityForResult so this value is to differentiate between them
resultCode
//This value is set by the called activity to indicate whether the intended operation was a success or not.
data
//this is an object of type Intent which contains data returned by called activity.
in your code when this part is executed:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// BoD con't: CONTENT_TYPE instead of CONTENT_ITEM_TYPE
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, RQS_PICKCONTACT);
New activity is started and when user comes back from that activity by selecting a contact onActivityResult is called
onActivityResult is called after u startIntent or u select an contact.
RQS_PICK_CONTACT u can change as u want. like 2 , 3,4 or another number.
it just identity for requestCode in onActivityResult so u can do as u need.

Categories

Resources