Inflation Issue in Recycler view - android-recyclerview

I am using a recycler view in android to show the list of data.I am using link preview also in the view holder class. but my recycler view is not showing any data the page is null.
and its is showing error -
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
I have tried many things but not getting any output from there.I have checked my xml file code. which is correct. I have checked the code also but not getting the issue anywhere.
custom row items -
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp"
android:paddingBottom="15dp">
<LinearLayout
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<com.pkmmte.view.CircularImageView
android:id="#+id/user_profile_image_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:src="#drawable/user_icon"
android:adjustViewBounds="true"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="4"
android:orientation="vertical"
android:layout_marginStart="15dp">
<TextView
android:id="#+id/post_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:textStyle="bold"
android:textColor="#000"
android:padding="3dp"
android:textSize="15sp"/>
<TextView
android:id="#+id/post_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:padding="3dp"
android:textSize="12sp"/>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/post_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User Text"
android:padding="2dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="20dp"
android:textColor="#000"
android:textSize="13sp"
android:visibility="gone"/>
<FrameLayout
android:id="#+id/media_frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
>
<com.google.android.youtube.player.YouTubeThumbnailView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:src="#drawable/jellyfish"
android:scaleType="fitXY"
android:visibility="gone"/>
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/media_youtube_player_view"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</com.google.android.youtube.player.YouTubePlayerView>
<ImageView
android:id="#+id/media_video_image_view"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="fitXY"
android:visibility="gone"
/>
<VideoView
android:id="#+id/media_video_view"
android:layout_height="200dp"
android:layout_width="match_parent"
android:layout_gravity="center_horizontal"
android:visibility="gone"
/>
<ImageView
android:id="#+id/media_image_view"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="fitXY"
android:visibility="gone"
/>
<ImageView
android:id="#+id/video_play_button"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal|center_vertical"
android:src="#drawable/video_play_button_black"
android:visibility="gone"
android:clickable="true"
android:focusable="true" />
</FrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/link_textView"
android:padding="10dp"
android:textSize="15sp"
android:background="#cdc9c9"
android:clickable="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:textColor="#000"
android:visibility="gone"/>
<android.support.v7.widget.CardView
android:id="#+id/twitter_link_card_view"
android:layout_height="150dp"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:visibility="gone"
>
<com.freesoulapps.preview.android.Preview
android:id="#+id/link_preview"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:gravity="center_vertical"
android:clickable="true"
android:focusable="true">
</com.freesoulapps.preview.android.Preview>
</android.support.v7.widget.CardView>
<View
android:layout_width="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_height="1dp"
android:background="#CFD8DC" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp">
<ImageView
android:id="#+id/post_like_image_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/like_heart_icon"
android:padding="2dp"
android:focusable="true" />
<ImageView
android:id = "#+id/post_liked_image_view"
android:layout_width="0dp"
android:clickable="true"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/like_blue_image_icon"
android:padding="2dp"
android:visibility="gone"
android:focusable="true" />
<ImageView
android:id="#+id/post_comment_image_view"
android:layout_width="0dp"
android:clickable="true"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/comment_icon"
android:padding="2dp"
android:focusable="true" />
<ImageView
android:id="#+id/post_sharing_imageView"
android:clickable="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/share_icon"
android:padding="2dp"
android:focusable="true" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/comment_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_text_style1"
android:padding="5dp"
android:layout_margin="10dp"
android:visibility="gone"
android:hint="Type your Comment"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
code for my adapter class -
public class AdapterRecyclerView extends RecyclerView.Adapter<MyViewHolder> implements Preview.PreviewListener {
private List<AllDataModel> allDataArrayList;
private Context context;
private int resource;
Preview linkPreview;
public AdapterRecyclerView(TwitterDataTest allDataActivity, int custom_data_main_layout , List<AllDataModel> allDataArrayList) {
this.context = allDataActivity;
this.resource = custom_data_main_layout;
this.allDataArrayList = allDataArrayList;
}
public AdapterRecyclerView(FacebookDataActivity facebookDataActivity, int custom_data_main_layout , List<AllDataModel> allDataArrayList) {
this.context = facebookDataActivity;
this.resource = custom_data_main_layout;
this.allDataArrayList = allDataArrayList;
}
public AdapterRecyclerView(YoutubeDataActivity youtubeDataActivity, int custom_data_main_layout , List<AllDataModel> allDataArrayList) {
this.context = youtubeDataActivity;
this.resource = custom_data_main_layout;
this.allDataArrayList = allDataArrayList;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int i) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(resource, parent, false);
linkPreview = itemView.findViewById(R.id.link_preview);
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(#NonNull final MyViewHolder myViewHolder, int position) {
final AllDataModel allDataModel = allDataArrayList.get(position);
//get values from dataModel
final String username = allDataModel.getUsername();
myViewHolder.UserName.setText(allDataModel.getUsername());
myViewHolder.PostTime.setText(allDataModel.getPost_creation_time());
String post_time = allDataModel.getPost_creation_time();
String post_text = allDataModel.getPost_text();
String status_type = allDataModel.getStatus_type();
final String link_Title = allDataModel.getLink_title();
if(status_type != null) {
Log.e("#444", status_type);
}
// setting source images
final String source = allDataModel.getSource();
String profileimageURL = allDataModel.getProfile_image_url();
String PostImageURL = allDataModel.getPost_image_url();
String postThuumbnailImageURL = allDataModel.getPost_video_thumbnail();
final String videoId = allDataModel.getVideo_id();
final String VideoUrl = allDataModel.getPost_video();
final String link_url = allDataModel.getLink_url();
if(profileimageURL != null){
Picasso.with(getContext()).load(profileimageURL).into(myViewHolder.profileCircularImage);
}
if(post_text != null){
myViewHolder.PostText.setVisibility(View.VISIBLE);
myViewHolder.PostText.setText(allDataModel.getPost_text());
}
if(PostImageURL != null){
myViewHolder.mediaFrameLayout.setVisibility(View.VISIBLE);
myViewHolder.postMediaImage.setVisibility(View.VISIBLE);
Picasso.with(getContext()).load(PostImageURL).into( myViewHolder.postMediaImage);
}
if(postThuumbnailImageURL != null) {
myViewHolder.mediaFrameLayout.setVisibility(View.VISIBLE);
myViewHolder.postVideoThumbnailImage.setVisibility(View.VISIBLE);
Picasso.with(getContext()).load(PostImageURL).into( myViewHolder.postMediaImage);
Picasso.with(getContext()).load(postThuumbnailImageURL).into( myViewHolder.postVideoThumbnailImage);
myViewHolder.play_button_image.setVisibility(View.VISIBLE);
if(videoId != null) {
myViewHolder.mediaFrameLayout.setVisibility(View.VISIBLE);
myViewHolder.play_button_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
myViewHolder.postMediaImage.setVisibility(View.GONE);
myViewHolder.play_button_image.setVisibility(View.GONE);
myViewHolder.postVideoThumbnailImage.setVisibility(View.GONE);
Intent youtubePlayerIntent = new Intent((Activity)context, YoutubePlayerActivity.class);
youtubePlayerIntent.putExtra("video_id", videoId);
context.startActivity(youtubePlayerIntent);
}
}
);
}
if (VideoUrl != null) {
myViewHolder. play_button_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
myViewHolder.postVideoThumbnailImage.setVisibility(View.GONE);
myViewHolder.play_button_image.setVisibility(View.GONE);
myViewHolder.postVideoView.setVisibility(View.VISIBLE);
try {
MediaController mediaController = new MediaController(getContext());
mediaController.setAnchorView( myViewHolder.postVideoView);
Uri video = Uri.parse(VideoUrl);
myViewHolder.postVideoView.setMediaController(mediaController);
myViewHolder.postVideoView.setVideoURI(video);
myViewHolder.postVideoView.requestFocus();
myViewHolder.postVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
myViewHolder.postVideoView.start();
}
});
} catch (Exception e) {
Log.e("Video Play Error :" , e.toString());
}
}
});
}
if(status_type != null){
if(status_type.equals("album") || status_type.equals("share") && source.equals("facebook")){
Log.e("STA2",status_type);
myViewHolder.play_button_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
myViewHolder. play_button_image.setVisibility(View.GONE);
myViewHolder.postVideoThumbnailImage.setVisibility(View.GONE);
Intent webViewIntent = new Intent(context, WebViewActivity.class);
webViewIntent.putExtra("link_url", link_url);
context.startActivity(webViewIntent);
}
});
}
}
}
if(status_type != null){
if(status_type.equals("share") && source.equals("twitter") && link_Title!=null ){
myViewHolder.linkCardView.setVisibility(View.VISIBLE);
myViewHolder.linkPreview.setData(link_Title);
myViewHolder.linkPreview.setListener((Preview.PreviewListener) this);
myViewHolder.linkPreview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent webViewIntent = new Intent(context, WebViewActivity.class);
webViewIntent.putExtra("link_url", link_Title);
context.startActivity(webViewIntent);
}
});
}
}
myViewHolder.shareutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.share_dialogue);
dialog.show();
Button fbShareBtn = (Button)dialog.findViewById(R.id.share_facebook_button);
Button twitterShareBtn = (Button)dialog.findViewById(R.id.share_twitter_button);
Button cancel = (Button)dialog.findViewById(R.id.cancel_share);
final String link_url = allDataModel.getLink_url();
fbShareBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent facebookIntent = new Intent(context, FacebookLoginActivity.class);
facebookIntent.putExtra("link_url", link_url);
facebookIntent.putExtra("source", source);
context.startActivity(facebookIntent);
}
});
twitterShareBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent twitterLoginIntent = new Intent(context, MainActivity.class);
twitterLoginIntent.putExtra("link_url", link_url);
context.startActivity(twitterLoginIntent);
}
});
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
});
myViewHolder.postComment.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
myViewHolder.commentET.setVisibility(View.VISIBLE);
}
});
myViewHolder.postLike.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
myViewHolder.postLiked.setVisibility(View.VISIBLE);
myViewHolder.postLike.setVisibility(View.GONE);
}
});
myViewHolder.postLiked.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
myViewHolder. postLike.setVisibility(View.VISIBLE);
myViewHolder.postLiked.setVisibility(View.GONE);
}
});
}
#Override
public int getItemCount() {
return allDataArrayList.size();
}
#Override
public void onDataReady(Preview preview) {
linkPreview .setMessage(preview.getLink());
}
}
code for main activity -
public class TwitterDataTest extends AppCompatActivity {
RecyclerView recyclerView;
AdapterRecyclerView adapterRecyclerView;
public List<AllDataModel> allDataArrayList;
ProgressDialog pd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_twitter_test);
allDataArrayList = new ArrayList<>();
recyclerView = findViewById(R.id.twitter_recycler_view);
recyclerView.setHasFixedSize(true);
pd = new ProgressDialog(this);
pd.setTitle("Loading......");
pd.show();
if(isOnline()){
Api apiService =
ApiClient.getClient().create(Api.class);
Call<ResponseBody> call = apiService.getTwitterData();
call.enqueue(new Callback<ResponseBody>() {
#Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if(response.isSuccessful()){
try {
assert response.body() != null;
String s = response.body().string();
LoadIntoListView(s);
recyclerView.setAdapter(adapterRecyclerView);
} catch (IOException e) {
e.printStackTrace();
}
}
else{
Toast.makeText(TwitterDataTest.this, "No response", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
}
else{
Toast.makeText(TwitterDataTest.this, "Please check your internet connection", Toast.LENGTH_LONG).show();
}
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
adapterRecyclerView = new AdapterRecyclerView(TwitterDataTest.this, R.layout.custom_data_main_layout, allDataArrayList);
adapterRecyclerView.notifyDataSetChanged();
recyclerView.setAdapter(adapterRecyclerView);
}
public void LoadIntoListView(String s) {
pd.dismiss();
try {
JSONArray jsonArray1 = new JSONArray(s);
int ja1length = jsonArray1.length();
for (int i = 0; i < ja1length; i++) {
String source = "twitter";
String videoThumbnailImageUrl = null;
String TweetVideoUrl = null;
String TweetImageUrl = null;
String expanded_url = null;
String url = null;
String link_url = null;
JSONObject jsonObject1 = jsonArray1.getJSONObject(i);
// String TweetTime = jsonObject1.getString("created_at");
String TweetText = jsonObject1.getString("full_text");
String id = jsonObject1.getString("id");
link_url = "https://twitter.com/AmritDki/status/" + id;
String createdTime = jsonObject1.getString("created_at");
final String TWITTER = "EEE MMM dd HH:mm:ss ZZZZZ yyyy";
SimpleDateFormat sf = new SimpleDateFormat(TWITTER);
sf.setLenient(true);
String TwitterCreationDateIST = String.valueOf(sf.parse(createdTime));
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("dd-M-yyyy hh:mm:ss a");
String dateIST_customFormat = formatter.format(sf.parse(createdTime));
if (TweetText.contains("http") == true) {
int index = TweetText.indexOf("https");
TweetText = TweetText.substring(0, index );
}
// user json object
JSONObject userJO = jsonObject1.getJSONObject("user");
String UserName = userJO.getString("name");
String ScreenName = userJO.getString("screen_name");
String ProfileImageUrl = userJO.getString("profile_image_url_https");
// getting entities object
if (jsonObject1.has("extended_entities")) {
JSONObject ExtendedEntitiesJO = jsonObject1.getJSONObject("extended_entities");
///////
JSONArray MediaJA = ExtendedEntitiesJO.getJSONArray("media");
for (int j = 0; j < MediaJA.length(); j++) {
JSONObject insideMediaJO = MediaJA.getJSONObject(j);
if (insideMediaJO.has("video_info")) {
videoThumbnailImageUrl = insideMediaJO.getString("media_url_https");
JSONObject VideoInfoJO = insideMediaJO.getJSONObject("video_info");
JSONArray variantsArray = VideoInfoJO.getJSONArray("variants");
JSONObject videoUrlJO = variantsArray.getJSONObject(0);
TweetVideoUrl = videoUrlJO.getString("url");
//allDataArrayList.add(new TwitterDataModel(ProfileImageUrl, UserName,TweetVideoUrl, TweetImageUrl, TweetText));
allDataArrayList.add(new AllDataModel(source, UserName, ProfileImageUrl,
TweetText, TweetImageUrl, videoThumbnailImageUrl, TweetVideoUrl, dateIST_customFormat, null,link_url,null, null));
} else {
TweetImageUrl = insideMediaJO.getString("media_url_https");
allDataArrayList.add(new AllDataModel(source, UserName, ProfileImageUrl,
TweetText, TweetImageUrl, videoThumbnailImageUrl, TweetVideoUrl, dateIST_customFormat, null,link_url,null, null));
}
}
}
else{
JSONObject entitiesJO = jsonObject1.getJSONObject("entities");
if(entitiesJO.has("urls")){
JSONArray urlsArray = entitiesJO.getJSONArray("urls");
if(urlsArray.length() > 0){
JSONObject insideUrlsJO = urlsArray.getJSONObject(0);
if(insideUrlsJO.has("expanded_url")){
expanded_url = insideUrlsJO.getString("expanded_url");
allDataArrayList.add(new AllDataModel(source, UserName, ProfileImageUrl,
TweetText, TweetImageUrl, videoThumbnailImageUrl, TweetVideoUrl, dateIST_customFormat,
null,link_url, "share",expanded_url));
}
}else{
allDataArrayList.add(new AllDataModel(source, UserName, ProfileImageUrl,
TweetText, TweetImageUrl, videoThumbnailImageUrl, TweetVideoUrl, dateIST_customFormat,
null,link_url, null,null
));
}
}
}
Log.e("#**", String.valueOf(allDataArrayList.size()));
// adapterRecyclerView = new AdapterRecyclerView(TwitterDataTest.this, R.layout.custom_data_main_layout, allDataArrayList);
// adapterRecyclerView.notifyDataSetChanged();
//recyclerView.setAdapter(adapterRecyclerView);
}
} catch (JSONException e) {
e.printStackTrace();
} catch (ParseException e) {
Log.e("parsingError", String.valueOf(e));
}
}

I got the solution of my problem after investing 3-4 hours. I was using the getContext() instead of context (Comes through the constructor)in inflating the layout.Small stupid mistake.

Related

android webview java.lang.NullPointerException: Attempt to invoke virtual method 'android.webkit.WebSettings on a null object reference

I'm trying to implement swipe in a customized WebView, but when the app tries to call getSettings(), a null pointer exception is thrown. Here are the particulars:
First, the extended WebView class:
package com.chiaramail.opencomments;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.webkit.WebView;
import android.widget.Toast;
public class OpenCommentsWebView extends WebView {
Context context;
GestureDetector gd;
public OpenCommentsWebView(Context context, AttributeSet attrs) {
super(context);
this.context = context;
gd = new GestureDetector(context, sogl);
}
GestureDetector.SimpleOnGestureListener sogl = new GestureDetector.SimpleOnGestureListener() {
public boolean onDown(MotionEvent event) {
return true;
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e1 == null || e2 == null) return false;
if (e1.getPointerCount() > 1 || e2.getPointerCount() > 1) return false;
else {
try { // Swipe down, so set
if (e2.getY() - e1.getY() > 100 && Math.abs(velocityY) > 800) {
MainActivity.recentCommentsShown = false;
return true;
}
} catch (Exception e) { // nothing
Log.e("OpenCommentsWebView", "Swipe error: " + e.getLocalizedMessage());
// Toast.makeText(this, getString(R.string.update_flow_failed) + BLANK + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
return false;
}
}
};
void show_toast(final String text) {
Toast t = Toast.makeText(context, text, Toast.LENGTH_SHORT);
t.show();
}
}
The relevant part of the main layout file:
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.chiaramail.opencomments.OpenCommentsWebView
android:id="#+id/browser_page"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Instantiating the extended WebView object:
private OpenCommentsWebView browser_page;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = this;
try {
setContentView(R.layout.main);
} catch (RuntimeException ex) {
ex.printStackTrace();
Toast.makeText(activity, getString(R.string.install_from_google_play), Toast.LENGTH_LONG).show();
finish();
return;
}
current_page = "https://www.google.com/";
browser_page = findViewById(R.id.browser_page);
#Override
public void onStart() {
super.onStart();
WebAction();
}
.
.
.
public void WebAction() {
// Fails here.
browser_page.getSettings().setJavaScriptEnabled(true);
}

android.hardware.camera2 on react-native

I'm trying to make a react-native project where i can enter the camera on the native side by clicking on a button on the react side.
it needs to click a single pic and send the path of file back to react Everything works fine. the file is being saved (1600X1200 resolution) but its not returning to react side and an error is coming i.e.:-
2019-05-30 15:32:49.497 28080-28132/com.gjcamera E/BufferItemConsumer: [ImageReader-1600x1200f100m1-28080-0] Failed to release buffer: Unknown error -1 (1).
I don't know where i am making a mistake.
here's my code:-
App.js:-
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, TouchableOpacity, NativeModules } from 'react-native';
const GJC = NativeModules.GJCamera;
type Props = {};
export default class App extends Component<Props> {
constructor() {
super();
this.state = {
imagePathh: "empty",
}
this.OpenMyCamera = this.OpenMyCamera.bind();
}
OpenMyCamera = async () => {
const result = await GJC.openCamera();
this.setState({ imagePathh: result });
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To enter camera, click on the "Camera" below</Text>
<Text style={styles.instructions}>The path of image will be shown below...</Text>
<TouchableOpacity style={{ backgroundColor: 'green' }} onPress={() => this.OpenMyCamera()}>
<Text style={{ color: '#fff' }}>Camera</Text>
</TouchableOpacity>
<Text style={{ paddingTop: 300 }}>The Path of image is </Text>
<Text style={{ color: "skyblue" }}>{this.state.imagePathh}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
GJCameraModule.java:-
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.widget.Toast;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.util.HashMap;
import java.util.Map;
import static android.support.v4.content.ContextCompat.startActivity;
public class GJCameraModule extends ReactContextBaseJavaModule {
private Promise promise;
public GJCameraModule(ReactApplicationContext reactContext) {
super(reactContext);
}
#ReactMethod
public String show() {
String imagePath = "";
String imageName = "";
imageName = "";//GJCamera.sendPath();
imagePath = Environment.getExternalStorageDirectory() + "/DCIM/Camera/" + imageName + ".jpg";
return imagePath.toString();
}
#ReactMethod
public void openCamera(final Promise promise) {
Toast.makeText(getReactApplicationContext(), "LOLZ", Toast.LENGTH_SHORT).show();
try {
GJCamera gjc = GJCamera.newInstance();
gjc.setPromise(promise);
Intent intent = new Intent(getCurrentActivity(), GJCamera.class);
getCurrentActivity().startActivity(intent);
Toast.makeText(getReactApplicationContext(), "LOLZ--Return", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
promise.reject(e.getMessage(), e.getMessage());
}
}
#Override
public String getName() {
return "GJCamera";
}
#Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
String android_id = Settings.System.getString(getReactApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
constants.put("uniqueId", android_id);
return constants;
}
}
GJCamera.java:-
package com.gjcamera;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.TotalCaptureResult;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.Image;
import android.media.ImageReader;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Size;
import android.util.SparseIntArray;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.WritableMap;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.UUID;
public class GJCamera extends AppCompatActivity {
private ImageButton btnCapture;
private TextureView textureView;
public static String imgName;
private static Promise promise;
//Check state orientation of output image
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
static {
ORIENTATIONS.append(Surface.ROTATION_0, 90);
ORIENTATIONS.append(Surface.ROTATION_90, 0);
ORIENTATIONS.append(Surface.ROTATION_180, 270);
ORIENTATIONS.append(Surface.ROTATION_270, 180);
}
private String cameraId;
private CameraDevice cameraDevice;
private CameraCaptureSession cameraCaptureSessions;
private CaptureRequest.Builder captureRequestBuilder;
private Size imageDimension;
private ImageReader imageReader;
//Save to FILE
private File file;
private static final int REQUEST_CAMERA_PERMISSION = 200;
private boolean mFlashSupported;
private Handler mBackgroundHandler;
private HandlerThread mBackgroundThread;
SurfaceTexture texture;
public static GJCamera newInstance() {
GJCamera a = new GJCamera();
return a;
}
CameraDevice.StateCallback stateCallback = new CameraDevice.StateCallback() {
#Override
public void onOpened(#NonNull CameraDevice camera) {
cameraDevice = camera;
createCameraPreview();
}
#Override
public void onDisconnected(#NonNull CameraDevice camera) {
// if (promise!=null) { promise.reject("Error");}
// promise = null;
cameraDevice = camera;
returnHome();
}
#Override
public void onError(#NonNull CameraDevice camera, int i) {
// if (promise!=null) { promise.reject("Error");}
// promise = null;
cameraDevice = camera;
returnHome();
}
};
public void setPromise(Promise promise) {
this.promise = promise;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gjcamera);
textureView = findViewById(R.id.textureView);
//From Java 1.4 , you can use keyword 'assert' to check expression true or false
assert textureView != null;
textureView.setSurfaceTextureListener(textureListener);
btnCapture = findViewById(R.id.clickButton);
btnCapture.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
takePicture();
}
});
}
private void takePicture() {
if (cameraDevice == null)
return;
CameraManager manager = null;
manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraDevice.getId());
Size[] jpegSizes = null;
if (characteristics != null)
jpegSizes = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
.getOutputSizes(ImageFormat.JPEG);
//Capture image with custom size
int width = 1600;
int height = 1200;
imageReader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
List<Surface> outputSurface = new ArrayList<>(2);
outputSurface.add(imageReader.getSurface());
outputSurface.add(new Surface(textureView.getSurfaceTexture()));
final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(imageReader.getSurface());
captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
//Check orientation base on device
int rotation = getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
file = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/IMG_" + calendar.get(Calendar.YEAR) + calendar.get(Calendar.MONTH) + calendar.get(Calendar.DATE) + "_" + calendar.get(Calendar.HOUR_OF_DAY) + calendar.get(Calendar.MINUTE) + calendar.get(Calendar.SECOND) + ".jpg");
ImageReader.OnImageAvailableListener readerListener = null;
readerListener = new ImageReader.OnImageAvailableListener() {
#Override
public void onImageAvailable(ImageReader imageReadr) {
Image image = null;
try {
image = imageReader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
save(bytes);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
{
if (image != null)
image.close();
}
}
}
private void save(byte[] bytes) throws IOException {
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
outputStream.write(bytes);
} finally {
if (outputStream != null)
outputStream.close();
}
}
};
imageReader.setOnImageAvailableListener(readerListener, mBackgroundHandler);
final CameraCaptureSession.CaptureCallback captureListener = new CameraCaptureSession.CaptureCallback() {
#Override
public void onCaptureCompleted(#NonNull CameraCaptureSession session, #NonNull CaptureRequest request, #NonNull TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
Toast.makeText(GJCamera.this, "Saved " + file, Toast.LENGTH_SHORT).show();
returnHome();
}
};
cameraDevice.createCaptureSession(outputSurface, new CameraCaptureSession.StateCallback() {
#Override
public void onConfigured(#NonNull CameraCaptureSession cameraCaptureSession) {
try {
cameraCaptureSession.capture(captureBuilder.build(), captureListener, mBackgroundHandler);
// cameraDevice.close();
//convertFileToWritableMap(file));
// promise = null;
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
#Override
public void onConfigureFailed(#NonNull CameraCaptureSession cameraCaptureSession) {
}
}, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
private void returnHome() {
texture.release();
// if(imageReader != null) {
// imageReader.close();
// imageReader = null;
// }
if (cameraDevice != null) {
cameraDevice.close();
cameraDevice = null;
}
if (cameraCaptureSessions != null) {
cameraCaptureSessions.close();
cameraCaptureSessions = null;
}
if (promise != null) {
promise.resolve(convertFileToWritableMap(file));
promise = null;
}
}
private void createCameraPreview() {
try {
texture = textureView.getSurfaceTexture();
assert texture != null;
texture.setDefaultBufferSize(1600, 1200);
Surface surface = new Surface(texture);
captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureRequestBuilder.addTarget(surface);
cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {
#Override
public void onConfigured(#NonNull CameraCaptureSession cameraCaptureSession) {
if (cameraDevice == null)
return;
cameraCaptureSessions = cameraCaptureSession;
updatePreview();
}
#Override
public void onConfigureFailed(#NonNull CameraCaptureSession cameraCaptureSession) {
Toast.makeText(GJCamera.this, "Changed", Toast.LENGTH_SHORT).show();
}
}, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
private void updatePreview() {
if (cameraDevice == null)
Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
captureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);
try {
cameraCaptureSessions.setRepeatingRequest(captureRequestBuilder.build(), null, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
private void openCamera() {
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
cameraId = manager.getCameraIdList()[0];
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
assert map != null;
imageDimension = map.getOutputSizes(SurfaceTexture.class)[0];
//Check realtime permission if run higher API 23
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE
}, REQUEST_CAMERA_PERMISSION);
return;
}
manager.openCamera(cameraId, stateCallback, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
TextureView.SurfaceTextureListener textureListener = new TextureView.SurfaceTextureListener() {
#Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
openCamera();
}
#Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {
}
#Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
return false;
}
#Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
};
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
if (requestCode == REQUEST_CAMERA_PERMISSION) {
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "You can't use camera without permission", Toast.LENGTH_SHORT).show();
finish();
}
}
}
#Override
protected void onResume() {
super.onResume();
startBackgroundThread();
if (textureView.isAvailable())
openCamera();
else
textureView.setSurfaceTextureListener(textureListener);
}
#Override
protected void onPause() {
stopBackgroundThread();
super.onPause();
}
private void stopBackgroundThread() {
mBackgroundThread.quitSafely();
try {
mBackgroundThread.join();
mBackgroundThread = null;
mBackgroundHandler = null;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void startBackgroundThread() {
mBackgroundThread = new HandlerThread("Camera Background");
mBackgroundThread.start();
mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
}
public static WritableMap convertFileToWritableMap(File fileLocation) {
WritableMap newFile = Arguments.createMap();
if (fileLocation == null) return newFile;
newFile.putString("imgPath", fileLocation.getPath());
return newFile;
}
}
activity_gjcamera.xml:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gjcamera.MainActivity">
<TextureView
android:id="#+id/textureView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/clickButton"
/>
<ImageButton
android:id="#+id/clickButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/camera_click" />
</RelativeLayout>
BTW, Thanks for the help.
finally, found it:-
in GJCamera.java within returnHome() Method:-
if (promise != null) {
promise.resolve(convertFileToWritableMap(file));
promise = null;
}
change it to:-
if (promise != null) {
promise.resolve(convertFileToWritableMap(file));
promise = null;
finish(); // in order to finish the activity.
}
The entire project is present Here.

place picker closes immediately

my PlacePicker is closing when I open it, it stays open for about 3 seconds, I can see the location and I can move it, but it closes, I already tried everything already activated the api in google console, I changed the key, it does not give any error in logcat and neither in the RUN tab help me!
MY ANDROID MANIFEST
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCD70mX9tljEfiDiLaCdHEUNMvq40AJDyI"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name=".activity.TelefoneActivity" />
<activity android:name=".activity.CadastrarActivity" />
<activity android:name=".activity.MainActivity" />
<activity android:name=".activity.PassageiroActivity" />
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<meta-data
android:name="com.facebook.sdk.App.Application"
android:value="#string/facebook_app_id" />
<!-- Facebook API Key -->
<meta-data
tools:replace="android:value"
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<activity
android:name=".activity.SplashActivity"
android:theme="#style/AppCompat.TelaCheia">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
ACTIVITY WHERE PLACE PICKER IS IMPLEMENTED
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
public class PassageiroActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
int PLACE_PICKER_REQUEST = 1;
private String placeId;
TextView btnChamarMoto;
/**
* Mapa da aplicação
*/
private GoogleMap mMap;
/**
* Responsável por disponibilizar a localização do smartphone
*/
private GoogleApiClient mGoogleApiClient;
/**
* Guarda a ultima posição do smartphone.
*/
private Location mLastLocation;
private TextInputEditText editMeuLocal;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_passageiro);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
iniciaComponentes();
placesApi();
btnChamarMoto = (TextView) findViewById(R.id.btnChamarMoto);
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this) // Interface ConnectionCallbacks
.addOnConnectionFailedListener(this) //Interface OnConnectionFailedListener
.addApi(LocationServices.API) // Vamos a API do LocationServices
.build();
}
}
public void placePiker(View view) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
try {
startActivityForResult(builder.build(PassageiroActivity.this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = (Place) PlacePicker.getPlace(PassageiroActivity.this, data);
btnChamarMoto.setText(place.getAddress());
}
}
}
protected void onStart() {
mGoogleApiClient.connect();
super.onStart();
}
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
#Override
public void onConnected(Bundle bundle) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mLastLocation != null) {
if (mMap != null) {
// Criamos o LatLng através do Location
final LatLng latLng = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
// Adicionamos um Marker com a posição...
mMap.addMarker(new MarkerOptions().position(latLng).title("Minha Posição"));
// Um zoom no mapa para a seua posição atual...
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18));
}
}
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
//Place Api
private void placesApi() {
Places.initialize(getApplicationContext(), "AIzaSyDxFTRAaJ-FecUs8SZj6MBYwwzD447Nces");
final PlacesClient placesClient = Places.createClient(this);
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
#Override
public void onPlaceSelected(Place place) {
//
// Double latitude = place.getLatLng().latitude;
Log.i("Places", "Place: " + place.getName() + ", " + place.getId());
placeId = place.getId();
}
#Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i("errorOccurred", "An error occurred: " + status);
}
});
}
private void meuLocal(PlacesClient placesClient) {
List < Place.Field > placeFields = Arrays.asList(Place.Field.NAME);
FindCurrentPlaceRequest request =
FindCurrentPlaceRequest.builder(placeFields).build();
if (ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Task < FindCurrentPlaceResponse > placeResponse = placesClient.findCurrentPlace(request);
placeResponse.addOnCompleteListener(task - > {
if (task.isSuccessful()) {
FindCurrentPlaceResponse response = task.getResult();
for (PlaceLikelihood placeLikelihood: response.getPlaceLikelihoods()) {
Log.i("likelihood", String.format("Place '%s' has likelihood: %f",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
LatLng nome = placeLikelihood.getPlace().getLatLng();
double latitude = nome.latitude;
double longitude = nome.longitude;
Toast.makeText(this, "latitude: " + latitude + "longitude: " + longitude, Toast.LENGTH_SHORT).show();
}
} else {
Exception exception = task.getException();
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.e("notFound", "Place not found: " + apiException.getStatusCode());
}
}
});
} else {
}
}
private void verificaIdPlaces(PlacesClient placesClient) {
List < Place.Field > placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
FetchPlaceRequest request = FetchPlaceRequest.builder(placeId, placeFields).build();
String nome = request.getPlaceId();
placesClient.fetchPlace(request).addOnSuccessListener((response) - > {
Place place = response.getPlace();
Log.i("PlaceFOund", "Place found: " + place.getName() + "," + place.getLatLng());
}).addOnFailureListener((exception) - > {
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
int statusCode = apiException.getStatusCode();
// Handle error with given status code.
Log.e("Place not found", "Place not found: " + exception.getMessage());
}
});
}
private void iniciaComponentes() {
btnChamarMoto = findViewById(R.id.btnChamarMoto);
}
Please check your api key
Note there is two api key , one for the debug and the other for the release , so make you sure you are using the right one for the right version

MyCustomPage.xaml is not loading webView in xamarin.Forms portable

I am beginner in xamarin.forms portable, i am working on xamainr.forms portable project, there i am facing issue. I have a .xaml page in my portable project and i am navigating to this .xaml page from App.cs using following line of code.
var ep = new CustomWebViewPage(dbPath);
var MainEv = new NavigationPage(ep);
Here in CustomWebViewPage i am using WebView in following way to load Url but after successful execution above lines emulator does not load webView. I don't know why it is happening.
I am pasting code of CustomWebViewPage as following.
CustomWebViewPage.xaml.cs
using XamarinDbokReader.SQLite_AppSample;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.IO;
namespace MyDummyProject
{
public partial class CustomWebViewPage : ContentPage
{
public string dbPath = "";
public CustomWebViewPage(string folderPath)
{
this.dbPath = folderPath;
HttpHelperClass helperClass = new HttpHelperClass();
InitializeComponent();
var webView = new WebView();
UrlWebViewSource urlWebViewSource = new UrlWebViewSource()
{
Url = UrlsList.FindUrl("ProEportalLoginPage") + UrlsList.ApiKeys(AppMode.ProductionMode.ToString())
};
webView.Source = urlWebViewSource;
webView.Navigated += (s, e) =>
{
if (e.Url.StartsWith("http://userInfo/?"))
{
string token = "";
try
{
string value_string = Uri.UnescapeDataString(e.Url.ToString());
token = value_string.Split('=')[1];
if (!string.IsNullOrEmpty(token))
{
string path = Path.Combine(dbPath.ToString(), "dBookStore.db3");
helperClass.SaveUserInformation(token, path);
}
}
catch (Exception ss)
{
}
}
};
wvEportalPage = webView;
}
public CustomWebViewPage()
{
}
}
}
CustomWebViewPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinDbokReader.EportalPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<WebView x:Name="wvEportalPage"></WebView>
</ContentPage>
App.cs
public App(bool isSqliteDbExist, string sPath)
{
isDbExist = isSqliteDbExist;
dbPath = sPath;
if (isDbExist)
{
if (isLoggedIn)
{
NavigationPage navPage = new NavigationPage(new BooksView());
App.Current.MainPage = navPage;
}
else
{
var tdlx = new CustomWebViewPage(dbPath);
var MainNave = new NavigationPage(tdlx);
}
}
else
{
//When cursor is coming from MainActivity then following line executes. And then OnStart() method executes.
ssd.CreateTablesInDb();
isDbExist = true;
}
}
protected override void OnStart()
{
if (isDbExist)
{
if (isLoggedIn)
{
NavigationPage navPage = new NavigationPage(new BooksView());
App.Current.MainPage = navPage;
}
else
{
var ep = new CustomWebViewPage(dbPath);
var MainEv = new NavigationPage(ep);
}
}
}
MainActivity
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
var documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var bookCoverFolder = Path.Combine(documents, "BooksCover");
var booksCollection = Path.Combine(documents, "Books");
var bookResource = Path.Combine(documents, "Resource");
if(!Directory.Exists(bookCoverFolder))
Directory.CreateDirectory(bookCoverFolder);
if (!Directory.Exists(booksCollection))
Directory.CreateDirectory(booksCollection);
if(!Directory.Exists(bookResource))
Directory.CreateDirectory(bookResource);
SQLite_Android androidDb = new SQLite_Android();
if (androidDb.IsExist())
{
LoadApplication(new App(true, androidDb.dbStorePath));
}
else
{
LoadApplication(new App(false, androidDb.dbStorePath));
}
}
The WebView probably isn't getting any Width or Height.
Try setting the VerticalOptions and HorizontalOptions properties to FillAndExpand.
So like this:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinDbokReader.EportalPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<WebView x:Name="wvEportalPage" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"></WebView>
</ContentPage>
If that doesn't seem to work try wrapping it in a Grid.
Thank you for awesome sugessions, but i found my mistake in code.I did a very small mistake in App.cs After setting navigation page i am not setting NavigationPage to MainPage. It should as below.
var tdlx = new CustomWebViewPage(dbPath);
var MainNave = new NavigationPage(tdlx);
MainPage = MainNave;
it worked perfectly. I knew about MainPage but i have not written due to some other regions but ultimately it is working.
You must define Width and Height to Xamarin WebView.

Panning and Zooming on MapView

I am trying to create an app that uses the panning and zooming features on the map. I have spent a lot of time trying to implement this. I first tried to create an on touch method inside the MapActivity, but I soon realized it would be a little more than that. I found some code that I tried to implement that created a subclass of a mapview and ran into some issues with it. I need some help with panning around the map. Everywhere I try to clear and display the overlay causes problems. Either the overlays get removed and displayed at the wrong place, or a loop is created causing flashing. Please let me know what I need to do to get this working. I realized that I may need to override the onScroll method if there is one instead of the onTouch method. Right now it is pretty buggy I need some help, so that I can make it bug free. Let me know if my thinking is correct. I need to get this up on the market right away. Here is my code. Thanks in advance.
//MapActivity class
//Package name omitted
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class MapActivityNearby extends MapActivity {
private static final String TAG = "MAPACTIVITY";
double lat;
double lng;
EnhancedMapView mv;
ArrayList<MapItem> allCats;
private static final String PREF_NAME = "cookie";
private float latMax;
private float latMin;
private float longMax;
private float longMin;
GeoPoint p;
private List<Overlay> mapOverlays;
private MyItemizedOverlay itemizedOverlay;
boolean waitTime = false;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_nearby);
LinearLayout ll = (LinearLayout) findViewById(R.id.maplayout);
mv = new EnhancedMapView(this, "0ieXSx8GEy9Hm7bCZMLckus7pmPKg0w8kelRO_g");
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mv.setLayoutParams(lp);
mv.setClickable(true);
mv.setBuiltInZoomControls(true);
mv.setOnZoomChangeListener(new EnhancedMapView.OnZoomChangeListener() {
#Override
public void onZoomChange(MapView view, int newZoom, int oldZoom) {
Log.v("test", "zoom center changed");
if (isNetworkAvailable(MapActivityNearby.this))
{
LogIn log = new LogIn();
log.execute(mv);
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(MapActivityNearby.this);
builder.setMessage("No network connection. Please try again when your within coverage area.")
.setTitle("Network Connection")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//close dialog
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
});
mv.setOnPanChangeListener(new EnhancedMapView.OnPanChangeListener() {
public void onPanChange(MapView view, GeoPoint newCenter, GeoPoint oldCenter) {
Log.v("test", "pan center changed");
if (isNetworkAvailable(MapActivityNearby.this))
{
LogIn log = new LogIn();
log.execute(mv);
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(MapActivityNearby.this);
builder.setMessage("No network connection. Please try again when your within coverage area.")
.setTitle("Network Connection")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//close dialog
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
});
ll.addView(mv);
SharedPreferences cookies = getSharedPreferences(PREF_NAME,
Context.MODE_PRIVATE);
lat = Double.parseDouble(cookies.getString("lat", "0"));
lng = Double.parseDouble(cookies.getString("lng", "0"));
GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
MapController mapControl = mv.getController();
mapControl.setCenter(p);
mapControl.setZoom(11);
}
public void onResume()
{
super.onResume();
if (isNetworkAvailable(MapActivityNearby.this))
{
LogIn log = new LogIn();
log.execute(mv);
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(MapActivityNearby.this);
builder.setMessage("No network connection. Please try again when your within coverage area.")
.setTitle("Network Connection")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//close dialog
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
public void plotPoints(ArrayList<MapItem> i) {
mapOverlays = mv.getOverlays();
// first overlay
Drawable drawable;
drawable = getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new MyItemizedOverlay(drawable, mv);
mapOverlays.add(itemizedOverlay);
for (MapItem x : i) {
GeoPoint point = new GeoPoint((int) (x.getLat() * 1E6),
(int) (x.getLng() * 1E6));
OverlayItem overlayItem = new OverlayItem(point,
x.getTitle(), x.getSubtitle());
itemizedOverlay.addOverlay(overlayItem);
}
}
private class LogIn extends AsyncTask<EnhancedMapView, Void, Boolean> {
String result = "";
InputStream is;
#Override
protected void onPreExecute() {
}
#Override
protected Boolean doInBackground(EnhancedMapView...params) {
if (!(mv.getOverlays().isEmpty()))
{
mv.getOverlays().clear();
}
int maxCount = 100;
EnhancedMapView mapView = params[0];
for (int i = 0; i < maxCount; i++)
{
p = mapView.getMapCenter();
float latCenter = (float) (p.getLatitudeE6()) / 1000000;
float longCenter = (float) (p.getLongitudeE6()) / 1000000;
float latSpan = (float) (mapView.getLatitudeSpan()) / 1000000;
float longSpan = (float) (mapView.getLongitudeSpan()) / 1000000;
latMax = latCenter + (latSpan/2);
latMin = latCenter - (latSpan/2);
longMax = longCenter + (longSpan/2);
longMin = longCenter - (longSpan/2);
if (latMin == latMax)
{
try
{
Thread.sleep(80);
}
catch(InterruptedException e)
{
}
}
else
{
p = mapView.getMapCenter();
latCenter = (float) (p.getLatitudeE6()) / 1000000;
longCenter = (float) (p.getLongitudeE6()) / 1000000;
latSpan = (float) (mapView.getLatitudeSpan()) / 1000000;
longSpan = (float) (mapView.getLongitudeSpan()) / 1000000;
latMax = latCenter + (latSpan/2);
latMin = latCenter - (latSpan/2);
longMax = longCenter + (longSpan/2);
longMin = longCenter - (longSpan/2);
break;
}
}
log(latMin);
log(latMax);
try {
final String catURL = "url goes here";
log(catURL.toString());
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(catURL);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
waitTime = true;
nameValuePairs.add(new BasicNameValuePair("PHPSESSID", getCookie()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
result = convertStreamToString();
log(result);
allCats = new ArrayList<MapItem>();
JSONObject object = new JSONObject(result);
JSONArray temp = object.getJSONArray("l");
log("Starting download");
log(temp.length());
long start = System.currentTimeMillis();
for (int k = 0; k < temp.length(); k++) {
JSONObject j = temp.getJSONObject(k);
MapItem c = new MapItem();
c.setObject_id(j.getInt("object_id"));
c.setTitle(j.getString("title"));
c.setColor(j.getString("color"));
c.setLat(j.getDouble("lat"));
c.setLng(j.getDouble("lng"));
c.setSubtitle(j.getString("subtitle"));
allCats.add(c);
log(allCats.toString());
}
long end = System.currentTimeMillis();
log("Download Took: " + (end - start) / 1000 + " seconds.");
// log(allCats.toString());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
#Override
protected void onPostExecute(Boolean result) {
// pBar.setVisibility(View.GONE);
plotPoints(allCats);
}
private String convertStreamToString() {
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
result.trim();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
return result;
}
}
public String getCookie() {
String cookie = "";
SharedPreferences cookies = getSharedPreferences(PREF_NAME,
Context.MODE_PRIVATE);
if (cookies.contains("cookie")) {
cookie = cookies.getString("cookie", "null");
}
return cookie;
}
private void log(Object obj) {
Log.d(TAG, TAG + " :: " + obj.toString());
}
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
// CustomMapView class
// package name omitted
import java.util.Timer;
import java.util.TimerTask;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
public class EnhancedMapView extends MapView {
public interface OnZoomChangeListener {
public void onZoomChange(MapView view, int newZoom, int oldZoom);
}
public interface OnPanChangeListener {
public void onPanChange(MapView view, GeoPoint newCenter, GeoPoint oldCenter);
}
private EnhancedMapView _this;
// Set this variable to your preferred timeout
private long events_timeout = 500L;
private boolean is_touched = false;
private GeoPoint last_center_pos;
private int last_zoom;
private Timer zoom_event_delay_timer = new Timer();
private Timer pan_event_delay_timer = new Timer();
private EnhancedMapView.OnZoomChangeListener zoom_change_listener;
private EnhancedMapView.OnPanChangeListener pan_change_listener;
public EnhancedMapView(Context context, String apiKey) {
super(context, apiKey);
_this = this;
last_center_pos = this.getMapCenter();
last_zoom = this.getZoomLevel();
}
public EnhancedMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public EnhancedMapView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setOnZoomChangeListener(EnhancedMapView.OnZoomChangeListener l) {
zoom_change_listener = l;
}
public void setOnPanChangeListener(EnhancedMapView.OnPanChangeListener l) {
pan_change_listener = l;
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() == 1) {
is_touched = false;
} else {
is_touched = true;
}
return super.onTouchEvent(ev);
}
#Override
public void computeScroll() {
super.computeScroll();
if (getZoomLevel() != last_zoom) {
// if computeScroll called before timer counts down we should drop it and start it over again
zoom_event_delay_timer.cancel();
zoom_event_delay_timer = new Timer();
zoom_event_delay_timer.schedule(new TimerTask() {
#Override
public void run() {
zoom_change_listener.onZoomChange(_this, getZoomLevel(), last_zoom);
last_zoom = getZoomLevel();
}
}, events_timeout);
}
// Send event only when map's center has changed and user stopped touching the screen
if (!last_center_pos.equals(getMapCenter()) || !is_touched) {
pan_event_delay_timer.cancel();
pan_event_delay_timer = new Timer();
pan_event_delay_timer.schedule(new TimerTask() {
#Override
public void run() {
pan_change_listener.onPanChange(_this, getMapCenter(), last_center_pos);
last_center_pos = getMapCenter();
}
}, events_timeout);
}
}
}
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:apiKey="0TqoE_fzA3Pv-m8188NwttzIKcYBzhNJsYRJkKQ"
android:id="#+id/mapview"
android:clickable="true"
android:enabled="true"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="35dip"
android:layout_marginTop="300dip"
android:layout_marginLeft="270dip"
android:layout_height="70dip"
android:background="#AA000000">
<TextView android:layout_height="20dip"
android:gravity="center" android:textStyle="bold"
android:textColor="#000000" android:textSize="20dip"
android:id="#+id/zoomButton1"
android:layout_width="100dip"
android:text="+" />
<TextView android:layout_height="20dip"
android:layout_below="#id/zoomButton1"
android:textStyle="bold"
android:textColor="#000000"
android:gravity="center"
android:textSize="20dip"
android:id="#+id/zoomButton2"
android:layout_width="80dip"
android:text="-" />
</RelativeLayout>
</RelativeLayout>
MyMapActivity
public class MyMapActivity extends MapActivity {
/** Called when the activity is first created. */
MapView mapView;
ZoomControls zoomControls;
MapController mapController;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.mapview);
System.out.println("oncreate");
mapView.setStreetView(true);
mapView.invalidate();
mapController = mapView.getController();
// zoom contrlos
int y=10;
int x=10;
/*MapView.LayoutParams lp;
lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT,
x, y,
MapView.LayoutParams.TOP_LEFT);
View zoomControls = mapView.getZoomControls();
mapView.addView(zoomControls, lp);
mapView.displayZoomControls(true);*/
/*zoomControls = (ZoomControls) findViewById(R.id.zoomControls1);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapController.zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapController.zoomOut();
}
});*/
TextView zButton =(TextView)findViewById(R.id.zoomButton1);
TextView zButton1 =(TextView)findViewById(R.id.zoomButton2);
zButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
mapController.zoomIn();
Toast.makeText(myMapActivity.this, "Zoomin", Toast.LENGTH_SHORT).show();
}
});
zButton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
mapController.zoomOut();
Toast.makeText(myMapActivity.this, "ZoomOUT", Toast.LENGTH_SHORT).show();
}
});
Double lat = 38.899049*1E6;
Double lng = -77.017593*1E6;
GeoPoint point = new GeoPoint(lat.intValue(),lng.intValue());
System.out.println("Points"+point);
mapController.setCenter(point);
mapController.setZoom(15);
mapController.animateTo(point);
// http://maps.google.com/maps?ie=UTF8&hl=en&layer=t&ll=38.899049,-77.017593&spn=0.268261,0.6427&z=11
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}