cannot open play this video in VideoView from sd card - mp4

Hi i am trying to play video from phone's internal storage in VideoView but my phone is prompting "cannot play this video". I am getting video path in main activity passing it to projector activity.
This is the path: '/storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4'
OnCreate Code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_projector);
Intent intent = getIntent();
String vidpath = intent.getExtras().getString("path");
p = (TextView) findViewById(R.id.videopath);
p.setText(vidpath);
Uri path= Uri.parse(Environment.getExternalStorageDirectory()+vidpath);
viewvid=(VideoView) this.findViewById(R.id.videoView);
Log.i("vidpath","here");
viewvid.setVideoURI(path);
viewvid.start();
}
This is how i get video path from MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setTitle("Video Projector");
gall = (Button) findViewById(R.id.gallery);
gall.setOnClickListener(this);
}
# Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_VIDEO) {
selectedVideoPath = getPath(data.getData());
if(selectedVideoPath == null) {
finish();
} else {
Toast.makeText(this,"A Video was selected",Toast.LENGTH_LONG).show();
Intent i = new Intent(this,projector.class);
i.putExtra("path",selectedVideoPath);
startActivity(i);
}
}
}
finish();
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if(cursor!=null) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
else return null;
}
#Override
public void onClick(View v) {
if (v==gall)
{
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECT_VIDEO);
}
}
Here is Log:
09 - 11 09: 48: 33.341 27291 - 27291 / com.example.tabish.vidprojector W / MediaPlayer: Couldn 't open /storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4: java.io.FileNotFoundException: No content provider: /storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4
09 - 11 09: 48: 33.342 27291 - 27291 / com.example.tabish.vidprojector I / MediaPlayer: setDataSource(/storage/emulated / 0 / storage / emulated / 0 / snaptube / download / SnapTube Video / Justin Bieber - Sorry(PURPOSE _ The Movement).mp4)
09 - 11 09: 48: 33.342 547 - 628 / ? I / MediaPlayerService : setDataSource(/storage/emulated / 0 / storage / emulated / 0 / snaptube / download / SnapTube Video / Justin Bieber - Sorry(PURPOSE _ The Movement).mp4)
09 - 11 09: 48: 33.365 547 - 27641 / ? E / FileSource : Failed to open file '/storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4'.(No such file or directory)

SOLVED:
Step1: Use Uri path=Uri.fromFile(new File(vidpath));
Step2: Check for the storage permission for your app in application manager of your phone

Related

Pass data from android to flutter

I have added my Android side code:
I know that I need to use a platform channel to pass data,I am unable to figure out:
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends AppCompatActivity {
private Button Btn;
// Intent defaultFlutter=FlutterActivity.createDefaultIntent(activity);
String path;
private Button bt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Btn = findViewById(R.id.btn);
isStoragePermissionGranted();
Btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{
path=takeScreenshot();
// activity.startActivity(defaultFlutter);
}
});
//write flutter xode here
//FlutterActivity.createDefaultIntent(this);
}
private String takeScreenshot() {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
Log.d("path",mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
return mPath;
///openScreenshot(imageFile);
} catch (Throwable e) {
// Several error may come out with file handling or DOM
e.printStackTrace();
return "Error";
}
}
public boolean isStoragePermissionGranted() {
String TAG = "Storage Permission";
if (Build.VERSION.SDK_INT >= 23) {
if (this.checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.v(TAG, "Permission is granted");
return true;
} else {
Log.v(TAG, "Permission is revoked");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
return false;
}
}
else { //permission is automatically granted on sdk<23 upon installation
Log.v(TAG,"Permission is granted");
return true;
}
}
}
I will receive a file from the android side, upon receiving I need to display it in a flutter. I also need to use cached engine for transferring data as normally it would cause a delay
You can use the cached engine, this will help me cover up for the delay.
Then you can add a invoke method onpressed that you can send method name and the data you want to pass.
On flutter side,you can create a platform and invoke method through which you can receive requirements and further process it,

Libstreaming: Can we perform zoom in and out in camera on surfaceview as well as on-touch Focus circle and Flash in camera preview?

I am developing an android application using libstreaming streaming library. The app is sending upstream on Wowza (Mobile to Wowza). I created one surfaceview which has the camera preview. It's working fine but I want to add three functionalities (Zoom in/out, Autofous and Flash).
I don't know whether it is possible with Libstreaming.
SurfaceView which I have used, belongs to
package net.majorkernelpanic.streaming.gl.SurfaceView.
Below is my Activity code:
public class LiveStreamingActivity extends Activity implements RtspClient.Callback, Session.Callback, SurfaceHolder.Callback {
private static SurfaceView mSurfaceView;
private SurfaceHolder mHolder;
private Session mSession;// Rtsp session
private static RtspClient mClient;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
if (!LibsChecker.checkVitamioLibs(this))
return;
mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
mHolder = mSurfaceView.getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
#SuppressWarnings("deprecation")
private void initRtspClient() {
// Configures the SessionBuilder
mSession = SessionBuilder
.getInstance()
.setContext(getApplicationContext())
.setAudioEncoder(SessionBuilder.AUDIO_AAC)
.setAudioQuality(new AudioQuality(8000, 16000))
.setVideoEncoder(SessionBuilder.VIDEO_H264)
//.setVideoQuality(new VideoQuality(352, 288, 30, 300000))
.setCamera(CameraInfo.CAMERA_FACING_BACK)
.setSurfaceView(mSurfaceView).setPreviewOrientation(0)
.setCallback(this).build();
mClient = new RtspClient();
mClient.setSession(mSession);
mClient.setCallback(this);
mClient.setTransportMode(RtspClient.TRANSPORT_TCP);
mSurfaceView.setAspectRatioMode(SurfaceView.ASPECT_RATIO_PREVIEW);
String ip, port, path;
Pattern uri = Pattern.compile("rtsp://(.+):(\\d+)/(.+)");
Matcher m = uri.matcher("rtsp://219.65.90.226:1935/app2/myStream");
m.find();
ip = m.group(1);
port = m.group(2);
path = m.group(3);
mClient.setCredentials(AppConfig.PUBLISHER_USERNAME,
AppConfig.PUBLISHER_PASSWORD);
mClient.setServerAddress(ip, Integer.parseInt(port));
mClient.setStreamPath("/" + path);
}
#Override
protected void onResume() {System.out.println("on Resume activity 2");
super.onResume();
try{
if(null != mSurfaceView){
/* Broadcastreceiver: check network connectivity */
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
registerReceiver(receiver, intentFilter);
/* Start audio streaming background thread: AsyncTask */
vmPlayer = null;
vmPlayer = new MediaPlayer(this);
audioStream= new AudioStreamTask(this);
audioStream.execute("push","push","push");
}
}catch(Exception ex){
ex.printStackTrace();
}
}
#Override
protected void onPause() {
super.onPause();
try{
/* release the surface view */
if(null != mSurfaceView){
mClient.release();
mSession.release();
mSurfaceView.getHolder().removeCallback(this);
}
}catch(Exception ex){
ex.printStackTrace();
}
}
#Override
public void onDestroy() {
try {
super.onDestroy();
if (mClient != null) {
mClient.release();
}
if (mSession != null) {
mSession.release();
}
mSurfaceView.getHolder().removeCallback(this);
} catch (Exception e) {
System.out.println("Error while destroying activity " + e);
}
}
private void toggleStreaming() {
if (!mClient.isStreaming()) {
// Start camera preview
mSession.startPreview();
// mFrontSession.startPreview();
// Start video stream
mClient.startStream();
//startRtmpStream();
} else {
// already streaming, stop streaming
// stop camera preview
mSession.stopPreview();
// mFrontSession.stopPreview();
// stop streaming
mClient.stopStream();
}
}}
activity_main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/surface_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/surface_view_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<net.majorkernelpanic.streaming.gl.SurfaceView
android:id="#+id/surface_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
</LinearLayout></FrameLayout>
I need complete description to add all these three camera features.
I did it! :)
Go to VideoStream.Java and change:
protected Camera mCamera to public static Camera mCamera.
Go to your MainActivity, in your case LiveStreamingActivity and paste:
private float mDist;
#Override
public boolean onTouchEvent(MotionEvent event) {
// Get the pointer ID
Camera.Parameters params = VideoStream.mCamera.getParameters();
int action = event.getAction();
if (event.getPointerCount() > 1) {
// handle multi-touch events
if (action == MotionEvent.ACTION_POINTER_DOWN) {
mDist = getFingerSpacing(event);
} else if (action == MotionEvent.ACTION_MOVE && params.isZoomSupported()) {
VideoStream.mCamera.cancelAutoFocus();
handleZoom(event, params);
}
} else {
// handle single touch events
if (action == MotionEvent.ACTION_UP) {
handleFocus(event, params);
}
}
return true;
}
private void handleZoom(MotionEvent event, Camera.Parameters params) {
int maxZoom = params.getMaxZoom();
int zoom = params.getZoom();
float newDist = getFingerSpacing(event);
if (newDist > mDist) {
//zoom in
if (zoom < maxZoom)
zoom++;
} else if (newDist < mDist) {
//zoom out
if (zoom > 0)
zoom--;
}
mDist = newDist;
params.setZoom(zoom);
VideoStream.mCamera.setParameters(params);
}
public void handleFocus(MotionEvent event, Camera.Parameters params) {
int pointerId = event.getPointerId(0);
int pointerIndex = event.findPointerIndex(pointerId);
// Get the pointer's current position
float x = event.getX(pointerIndex);
float y = event.getY(pointerIndex);
List<String> supportedFocusModes = params.getSupportedFocusModes();
if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
VideoStream.mCamera.autoFocus(new Camera.AutoFocusCallback() {
#Override
public void onAutoFocus(boolean b, Camera camera) {
// currently set to auto-focus on single touch
}
});
}
}
/**
* Determine the space between the first two fingers
*/
private float getFingerSpacing(MotionEvent event) {
// ...
float x = event.getX(0) - event.getX(1);
float y = event.getY(0) - event.getY(1);
return FloatMath.sqrt(x * x + y * y);
}
Based here.
Let me know if it helped!
Thank you #José Cunha Fonte your code is great!
For me (Works with Marshmallow SDK) return FloatMath.sqrt(x * x + y * y); is deprecated and gone, so I just changed to return (float)Math.sqrt(x * x + y * y);
Hope it will help someone :)

current location not display accurately by google location API

When I am running this code it gives current location after I clicked the button_currentlocation. But when I checked the accuracy it is very low accuracy (sometime 5000m). But I need to get current location for one time with high accuracy (around 10m).
If someone can help me to correct my coding,it will be great help for my research.
My cordings are as follow
in my manifest
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
LocationProvider Class
public class LocationProvider implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener {
public abstract interface LocationCallback {
public void handleNewLocation(Location location);
}
public static final String TAG = LocationProvider.class.getSimpleName();
/*
* Define a request code to send to Google Play services
* This code is returned in Activity.onActivityResult
*/
private final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
private LocationCallback mLocationCallback;
private Context mContext;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
public LocationProvider(Context context, LocationCallback callback) {
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mLocationCallback = callback;
// Create the LocationRequest object
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10 * 1000) // 10 seconds, in milliseconds
.setFastestInterval(1 * 1000); // 1 second, in milliseconds
mContext = context;
}
public void connect() {
mGoogleApiClient.connect();
}
public void disconnect() {
if (mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
mGoogleApiClient.disconnect();
}
}
#Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "Location services connected.");
Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (location == null) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
else {
mLocationCallback.handleNewLocation(location);
}
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
/*
* Google Play services can resolve some errors it detects.
* If the error has a resolution, try sending an Intent to
* start a Google Play services activity that can resolve
* error.
*/
if (connectionResult.hasResolution() && mContext instanceof Activity) {
try {
Activity activity = (Activity)mContext;
// Start an Activity that tries to resolve the error
connectionResult.startResolutionForResult(activity, CONNECTION_FAILURE_RESOLUTION_REQUEST);
/*
* Thrown if Google Play services canceled the original
* PendingIntent
*/
} catch (IntentSender.SendIntentException e) {
// Log the error
e.printStackTrace();
}
} else {
/*
* If no resolution is available, display a dialog to the
* user with the error.
*/
Log.i(TAG, "Location services connection failed with code " + connectionResult.getErrorCode());
}
}
#Override
public void onLocationChanged(Location location) {
mLocationCallback.handleNewLocation(location);
}
}
In HomePage Class
package com.ksfr.finaltest01;
import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;
import com.google.android.gms.maps.model.LatLng;
public class HomePage extends Activity implements AdapterView.OnItemSelectedListener,LocationProvider.LocationCallback {
public static final String TAG = HomePage.class.getSimpleName();
Button button_disFinder;
private LocationProvider locationProvider;
String Provider,Str_endLocation;
double cur_latitude, cur_longitude,cur_accuracy, end_latitude, end_longitude;
float distance_cur_to_end;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
locationProvider = new LocationProvider(this,this);
Spinner spinner = (Spinner) findViewById(R.id.spinner_schools);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.school_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
public void CurrentLocationClicked(View view) {
if (cur_latitude!=0&&cur_longitude != 0 ){
Spinner spinner = (Spinner) findViewById(R.id.spinner_schools);
spinner.setClickable(true);
String message= String.format("Current Location\n" + "Latitude :" + cur_latitude + "\nLongitude :" + cur_longitude+"\nAccuracy :"+cur_accuracy+"\nProvider :"+Provider);
Toast.makeText(HomePage.this, message, Toast.LENGTH_LONG).show();
}
else{
String message= String.format("Location services disconnected.\nSwich ON Location Service to work App.");
Toast.makeText(HomePage.this, message, Toast.LENGTH_LONG).show();
//System.exit(0);
}
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position!= 0) {
Str_endLocation=String.valueOf(parent.getItemAtPosition(position));
Toast.makeText(getApplicationContext(), Str_endLocation + " Selected", Toast.LENGTH_SHORT).show();
switch (Str_endLocation){
//end location latitude and logitude will be taken from here.
case "Kahagolla National School":
end_latitude = 6.816703;end_longitude = 80.9637076;
break;
}
String message3= String.format("End Location\n"+"Latitude :"+end_latitude+"\nLongitude :"+end_longitude);//For Testing
Toast.makeText(HomePage.this, message3, Toast.LENGTH_LONG).show();//For Testing
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
public void FindDistanceClicked (View view){
Location curlocation = new Location("");
curlocation.setLatitude(cur_latitude);
curlocation.setLongitude(cur_longitude);
Location endlocation = new Location("");
endlocation.setLatitude(end_latitude);
endlocation.setLongitude(end_longitude);
distance_cur_to_end = curlocation.distanceTo(endlocation)/1000;
String message5= String.format("Distance from current location to\n" + Str_endLocation + " :" + String.format("%.3g%n", distance_cur_to_end)+"km");//For testing
Toast.makeText(HomePage.this, message5, Toast.LENGTH_LONG).show();//For testing
}
public void handleNewLocation(Location location) {
Log.d(TAG, location.toString());
cur_latitude = location.getLatitude();
cur_longitude = location.getLongitude();
cur_accuracy = location.getAccuracy();
Provider = location.getProvider();
LatLng cur_latLng = new LatLng(cur_latitude, cur_longitude);
}
#Override
protected void onResume() {
super.onResume();
locationProvider.connect();
}
#Override
protected void onPause() {
super.onPause();
locationProvider.disconnect();
}
public void ClearClicked (View view){
}
}
Try reversing your onConnected method location code.
First try to get current location and if that is not available then try getting lastKnown location.
Some thing like this
if(location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if(locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
I corrected my issue finally,
From this method i got locations in 3m accuracy,which I want.
Here's code
DistanceFinderActivity.java
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 5*1000; // in Milliseconds
protected LocationManager locationManager;
double cur_latitude, cur_longitude,cur_accuracy, end_latitude, end_longitude;
float distance_cur_to_end;
public LatLng cur_latLng,end_latLng;
MyLocationListener myLocationListener =new MyLocationListener();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_distance_finder);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
myLocationListener
);
//......
}
protected void showCurrentLocation() {
Location location = locationManager.getLastKnownLocation(GPS_PROVIDER);
if (location != null) {
cur_latitude = location.getLatitude();
cur_longitude = location.getLongitude();
cur_accuracy = location.getAccuracy();
Provider = location.getProvider();
DecimalFormat df = new DecimalFormat("#.###");
df.setMinimumFractionDigits(2);
String message = String.format(
"Current Location \nLatitude: %1$s\nLongitude: %2$s\nAccuracy: %3$s\n" +
" Provider: %4$s\nWait until new location capture",
cur_latitude, cur_longitude,String.valueOf(df.format(cur_accuracy)),Provider.toUpperCase()
);
Toast.makeText(MainDistanceFinderActivity.this, message,
Toast.LENGTH_LONG).show();
}
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
cur_latitude = location.getLatitude();
cur_longitude = location.getLongitude();
cur_accuracy = location.getAccuracy();
Provider = location.getProvider();
DecimalFormat df = new DecimalFormat("#.###");
df.setMinimumFractionDigits(2);
String message = String.format(
"New Location Captured. \nLatitude: %1$s\nLongitude: %2$s\nAccuracy: %3$s\n" +
" Provider: %4$s",
cur_latitude, cur_longitude,String.valueOf(df.format(cur_accuracy)), Provider.toUpperCase()
);
Toast.makeText(MainDistanceFinderActivity.this, message, Toast.LENGTH_LONG).show();
}
public void onStatusChanged(String s, int i, Bundle b) {
Toast.makeText(MainDistanceFinderActivity.this, "Provider status changed",
Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
Toast.makeText(MainDistanceFinderActivity.this,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s) {
Toast.makeText(MainDistanceFinderActivity.this,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
}

File Upload in Android Webview - No File Chosen

I'm using the solution from Android WebView File Upload to have File Upload in Android Webview:
private WebView webView;
private ValueCallback<Uri> mUploadMessage;
private final static int FILECHOOSER_RESULTCODE = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
Main.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);
}
public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
Main.this.startActivityForResult(
Intent.createChooser(i, "File Browser"),
FILECHOOSER_RESULTCODE);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
Main.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), Main.FILECHOOSER_RESULTCODE );
}
});
webView.loadUrl( WEBSITE_URL );
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
if(requestCode==FILECHOOSER_RESULTCODE){
if (null == mUploadMessage) return;
Uri result = intent == null || resultCode != RESULT_OK ? null
: intent.getData();
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
}
The filechooser display but after selecting photo, the input file still display No File Chosen. What I am missing on my code?
Thanks.

No JFrame Title after exporting to JAR

When running the JAVA app in Eclipse, the JFrame title is displayed, but when running the exported JAR file, there is no title showing on the frame.
public void mouseMoved(MouseEvent e) {
f.setTitle("X: " + location.x + " , Y: " + location.y);
recenterMouse();
}
public void init() {
// add frame
f = new JFrame("Muis Meet");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(screensizex, screensizey);
f.getContentPane().add(this, FlowLayout.LEFT);
f.setVisible(true);
centerLocation.x = getWidth() / 2;
centerLocation.y = getHeight() / 2;
recenterMouse();
addMouseListener(this);
addMouseMotionListener(this);
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
MuisMeet muismeet = new MuisMeet();
muismeet.init();
}});
}
#Override
public void mousePressed(MouseEvent arg0) {
recenterMouse();
location.x = 0;
location.y = 0;
f.setTitle("X: 0 , Y: 0");
}
}
Found the problem. In the Export dialog box, another project was automatically selected under Launch Configuration - not the project I right-clicked upon.