I would like to query, sms logs (not sms) but the logs that show when you see history of a particular contact. The below code can query the logs however, I cannot delete them as it give me exception.
anyone with a solution or advise on why can't i delete a sms log (showing sent sms, received sms logs).
Code:
public void eraseSmsLogs(Contact contact) {
String phoneNumber = null;
Log.d("pali","phoneService eraseSmsLogs");
Uri smsLogs = Uri.parse("content://logs/sms");
Cursor cursor = context.getContentResolver().query(smsLogs, null, null, null, null);
if(cursor.getCount() > 0) {
cursor.moveToFirst();
for(int i=0; i<cursor.getColumnCount();i++) {
Log.d("pali","phoneService eraseSmsLogs colName i =" + i + " " + cursor.getColumnName(i) + ",colval=" + cursor.getString(i));
}
while(cursor.moveToNext()) {
phoneNumber = cursor.getString(6);
if(matchPhoneNumbers(phoneNumber, contact.getNumber())) {
Log.d("pali","**phoneService eraseSmsLogs no matched**");
//context.getContentResolver().delete(Uri.parse("content://sms"), "_id=?", new String[]{cursor.getString(15)});
context.getContentResolver().delete(smsLogs, "Number=?", new String[]{phoneNumber});
}
}
}
}
and the exception is
Code:
05-14 15:26:47.909: E/AndroidRuntime(26646): FATAL EXCEPTION: main
05-14 15:26:47.909: E/AndroidRuntime(26646): java.lang.UnsupportedOperationException: Cannot delete that URL: content://logs/sms
05-14 15:26:47.909: E/AndroidRuntime(26646): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:146)
05-14 15:26:47.909: E/AndroidRuntime(26646): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
05-14 15:26:47.909: E/AndroidRuntime(26646): at android.content.ContentProviderProxy.delete(ContentProviderNative.java:483)
05-14 15:26:47.909: E/AndroidRuntime(26646): at android.content.ContentResolver.delete(ContentResolver.java:692)
if i can query the sms logs, why can't i delete them.
regards,
Related
Hello,
we are developing something to watch the battery drain - logging battery % steps - and get sometimes an exception into our Uncaught Exception Handler looks like this:
Code:
07-15 12:29:41.815 D/AndroidRuntime(27028): Shutting down VM
07-15 12:29:41.815 W/dalvikvm(27028): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
07-15 12:29:41.815 E/DrainGuardService(27028): Default uncaught exception handler
07-15 12:29:41.815 E/DrainGuardService(27028): Caught throwable java.lang.RuntimeException: [B]Error receiving broadcast Intent [/B]{ act=[B]android.intent.action.BATTERY_CHANGED[/B] flg=0x60000000 (has extras) } in [email protected] for thread Thread[main,5,main]
Thats our Codesnipplet
Code:
private IntentFilter batteryLevelFilterpercentchange = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
private BroadcastReceiver batteryLevelReceiver3;
Code:
batteryLevelReceiver3 = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
int level = -1;
try
{
int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
...
We tried to catch the exception with a try-finally but it looks like we are crashing before.
Funny thing: It happens only 1-2 times a week but we want to fix it. How/where can we catch this exception correctly without ending the app?
I also think that its not our mistake, because the system sends the message with the intent. but sometimes it seems not to be filled in correctly.
Thanks in advance!
Here's a pretty cookie cutter BroadcastReceiver that I use frequently(Modified with your code). Let me know if it helps.
Code:
private class BatteryLevelReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null)
return;
if (context == null)
return;
String action = intent.getAction();
if (action == null)
return;
if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
int level = -1;
int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
else {
// DO SOMETHING ELSE
}
}
}
Thanks, will try tomorrow and report back in a few days after testing.
After optimizing my code - had ~5 batterylevel receiver xD - and implementing your code, everything works like a charm.
Many thanks!
Thanks so much for the code! I was ahving the same issue, now it's solved!!!! Thanks again
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums & Read the Forum Rules
Moving to Q&A
Hi everyone,
I am currently working on my first app which grabs a ZIP from the internet and the extracts it to a certain location. Everything works great but I can not figure out how to show a Toast message when the extraction operation is done.
The code I am using for unzipping is:
Code:
package mmarin.test.download;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
*
* @author jon
*/
public class Decompress{
private String _zipFile;
private String _location;
byte[] buffer = new byte[1024];
int length;
public Decompress(String zipFile, String location) {
_zipFile = zipFile;
_location = location;
_dirChecker("");
}
public void unzip() {
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if(ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_location + ze.getName());
while ((length = zin.read(buffer))>0) {
fout.write(buffer, 0, length);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
}
private void _dirChecker(String dir) {
File f = new File(_location + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
}
I am calling the Decompress activity through a button:
Code:
Button decompress = (Button)findViewById(R.id.button1);
decompress.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
String zipFile = Environment.getExternalStorageDirectory() + "/IPM/Splash.zip";
String unzipLocation = Environment.getExternalStorageDirectory() + "/IPM/Splash/";
Decompress d = new Decompress(zipFile, unzipLocation);
d.unzip();
}
});
I found this here: http://www.jondev.net/articles/Unzipping_Files_with_Android_(Programmatically) and it works great.
As I said above, only issue is displaying a message that everything is done.
Can someone please help me out?
Thank you!
Please use the Q&A Forum for questions &
Read the Forum Rules Ref Posting
Moving to Q&A
Put the toast after zin.close()
www.stackoverflow.com
Here you can find what you want
Xperian using xda app
http://stackoverflow.com/questions/9824772/toast-after-email-intent-message
Check this
Xperian using xda app
RoberGalarga said:
Put the toast after zin.close()
Click to expand...
Click to collapse
Hey,
I tried this but it doesn't work. I used this statement:
Code:
Toast.makeText(this, "Extraction complete", "LENGTH_SHORT").show();
and I got this error message: The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (Decompress, String, String).
Help?
The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (Decompress, String, String)
What the above line means is that you need to pass a Context object, a CharSequence object and an int. You are passing the wrong object types (Decompress, String, String).
The example you saw used the Toast in the activity class itself, that is why the first value passed was a this. The "LENGTH_SHORT" is actually a constant Toast.LENGTH_SHORT.
I am guessing you are making the button object in your main activity class. So i'd suggest making an additional method for the activity class that looks like this
Code:
public void displayToast(CharSequence cs)
{
Toast.makeText(this, cs, Toast.LENGTH_SHORT).show();
}
and then make the following change to your code
Code:
Button decompress = (Button)findViewById(R.id.button1);
decompress.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
String zipFile = Environment.getExternalStorageDirectory() + "/IPM/Splash.zip";
String unzipLocation = Environment.getExternalStorageDirectory() + "/IPM/Splash/";
Decompress d = new Decompress(zipFile, unzipLocation);
d.unzip();
// Add the following line
displayToast("Unzip complete");
}
});
Let me know if it worked for you.
The_R said:
The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (Decompress, String, String)
What the above line means is that you need to pass a Context object, a CharSequence object and an int. You are passing the wrong object types (Decompress, String, String).
The example you saw used the Toast in the activity class itself, that is why the first value passed was a this. The "LENGTH_SHORT" is actually a constant Toast.LENGTH_SHORT.
I am guessing you are making the button object in your main activity class. So i'd suggest making an additional method for the activity class that looks like this
Code:
public void displayToast(CharSequence cs)
{
Toast.makeText(this, cs, Toast.LENGTH_SHORT).show();
}
and then make the following change to your code
Code:
Button decompress = (Button)findViewById(R.id.button1);
decompress.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
String zipFile = Environment.getExternalStorageDirectory() + "/IPM/Splash.zip";
String unzipLocation = Environment.getExternalStorageDirectory() + "/IPM/Splash/";
Decompress d = new Decompress(zipFile, unzipLocation);
d.unzip();
// Add the following line
displayToast("Unzip complete");
}
});
Let me know if it worked for you.
Click to expand...
Click to collapse
PERFECT! You're amazing!
Hello guys. So i'm trying to make a app that will play a aac stream from an online radio station. I managed to build the project but i get this error when running it.
Code:
05-27 06:12:00.734: E/AndroidRuntime(450): FATAL EXCEPTION: main
05-27 06:12:00.734: E/AndroidRuntime(450): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.spoledge.aacplay/com.spoledge.aacplay.AACPlayerActivity}: java.lang.ClassNotFoundException: com.spoledge.aacplay.AACPlayerActivity in loader dalvik.system.PathClassLoader[/data/app/com.spoledge.aacplay-2.apk]
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.os.Looper.loop(Looper.java:123)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-27 06:12:00.734: E/AndroidRuntime(450): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 06:12:00.734: E/AndroidRuntime(450): at java.lang.reflect.Method.invoke(Method.java:507)
05-27 06:12:00.734: E/AndroidRuntime(450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-27 06:12:00.734: E/AndroidRuntime(450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-27 06:12:00.734: E/AndroidRuntime(450): at dalvik.system.NativeStart.main(Native Method)
05-27 06:12:00.734: E/AndroidRuntime(450): Caused by: java.lang.ClassNotFoundException: com.spoledge.aacplay.AACPlayerActivity in loader dalvik.system.PathClassLoader[/data/app/com.spoledge.aacplay-2.apk]
05-27 06:12:00.734: E/AndroidRuntime(450): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-27 06:12:00.734: E/AndroidRuntime(450): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-27 06:12:00.734: E/AndroidRuntime(450): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
05-27 06:12:00.734: E/AndroidRuntime(450): ... 11 more
This is my project AACPlayerActivity.java code:
Code:
package com.spoledge.aacplay;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.spoledge.aacdecoder.AACPlayer;
import com.spoledge.aacdecoder.PlayerCallback;
/**
* This is the main activity.
*/
public class AACPlayerActivity extends Activity implements View.OnClickListener, PlayerCallback {
private History history;
private AutoCompleteTextView urlView;
private Button btnPlay;
private Button btnStop;
private TextView txtStatus;
private EditText txtBufAudio;
private EditText txtBufDecode;
private ProgressBar progress;
private Handler uiHandler;
private AACPlayer aacPlayer;
////////////////////////////////////////////////////////////////////////////
// PlayerCallback
////////////////////////////////////////////////////////////////////////////
private boolean playerStarted;
public void playerStarted() {
uiHandler.post( new Runnable() {
public void run() {
txtBufAudio.setEnabled( false );
txtBufDecode.setEnabled( false );
btnPlay.setEnabled( false );
btnStop.setEnabled( true );
txtStatus.setText( R.string.text_buffering );
progress.setProgress( 0 );
progress.setVisibility( View.VISIBLE );
playerStarted = true;
}
});
}
/**
* This method is called periodically by PCMFeed.
*
* @param isPlaying false means that the PCM data are being buffered,
* but the audio is not playing yet
*
* @param audioBufferSizeMs the buffered audio data expressed in milliseconds of playing
* @param audioBufferCapacityMs the total capacity of audio buffer expressed in milliseconds of playing
*/
public void playerPCMFeedBuffer( final boolean isPlaying,
final int audioBufferSizeMs, final int audioBufferCapacityMs ) {
uiHandler.post( new Runnable() {
public void run() {
progress.setProgress( audioBufferSizeMs * progress.getMax() / audioBufferCapacityMs );
if (isPlaying) txtStatus.setText( R.string.text_playing );
}
});
}
public void playerStopped( final int perf ) {
uiHandler.post( new Runnable() {
public void run() {
btnPlay.setEnabled( true );
btnStop.setEnabled( false );
txtBufAudio.setEnabled( true );
txtBufDecode.setEnabled( true );
// txtStatus.setText( R.string.text_stopped );
txtStatus.setText( "" + perf + " %" );
progress.setVisibility( View.INVISIBLE );
playerStarted = false;
}
});
}
public void playerException( final Throwable t) {
uiHandler.post( new Runnable() {
public void run() {
new AlertDialog.Builder( AACPlayerActivity.this )
.setTitle( R.string.text_exception )
.setMessage( t.toString())
.setNeutralButton( R.string.button_close,
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog, int id) {
dialog.cancel();
}
}
)
.show();
txtStatus.setText( R.string.text_stopped );
if (playerStarted) playerStopped( 0 );
}
});
}
////////////////////////////////////////////////////////////////////////////
// OnClickListener
////////////////////////////////////////////////////////////////////////////
/**
* Called when a view has been clicked.
*/
public void onClick( View v ) {
try {
switch (v.getId()) {
case R.id.view_main_button_play: start(); break;
case R.id.view_main_button_stop: stop(); break;
}
}
catch (Exception e) {
Log.e( "AACPlayerActivity", "exc" , e );
}
}
////////////////////////////////////////////////////////////////////////////
// Protected
////////////////////////////////////////////////////////////////////////////
@Override
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.main );
btnPlay = (Button) findViewById( R.id.view_main_button_play );
btnStop = (Button) findViewById( R.id.view_main_button_stop );
urlView = (AutoCompleteTextView) findViewById( R.id.view_main_edit_url );
txtStatus = (TextView) findViewById( R.id.view_main_text_status );
txtBufAudio = (EditText) findViewById( R.id.view_main_text_bufaudio );
txtBufDecode = (EditText) findViewById( R.id.view_main_text_bufdecode );
progress = (ProgressBar) findViewById( R.id.view_main_progress );
txtBufAudio.setText( String.valueOf( AACPlayer.DEFAULT_AUDIO_BUFFER_CAPACITY_MS ));
txtBufDecode.setText( String.valueOf( AACPlayer.DEFAULT_DECODE_BUFFER_CAPACITY_MS ));
btnPlay.setOnClickListener( this );
btnStop.setOnClickListener( this );
history = new History( this );
history.read();
if (history.size() == 0 ) {
history.addUrl( "/sdcard/local/cro2-32.aac" );
history.addUrl( "netshow.play.cz:8000/crocb32aac" );
history.addUrl( "62.44.1.26:8000/cro2-128aac" );
history.addUrl( "2483.live.streamtheworld.com:80/KFTZFMAACCMP3" );
history.addUrl( "yourmuze.com:8000/play/paradise/l.aac" );
history.addUrl( "yourmuze.com:8000/play/paradise/m.aac" );
history.addUrl( "yourmuze.com:8000/play/paradise/h.aac" );
}
urlView.setAdapter( history.getArrayAdapter());
uiHandler = new Handler();
}
@Override
protected void onPause() {
super.onPause();
history.write();
}
@Override
protected void onDestroy() {
super.onDestroy();
stop();
}
////////////////////////////////////////////////////////////////////////////
// Private
////////////////////////////////////////////////////////////////////////////
private void start() {
stop();
aacPlayer = new AACPlayer( this, getInt( txtBufAudio ), getInt( txtBufDecode ));
aacPlayer.playAsync( getUrl());
}
private void stop() {
if (aacPlayer != null) {
aacPlayer.stop();
aacPlayer = null;
}
}
private String getUrl() {
String ret = urlView.getText().toString();
history.addUrl( ret );
return ret;
}
private int getInt( EditText et ) {
return Integer.parseInt( et.getText().toString());
}
}
And this is my AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="schemas.android.com/apk/res/android"
package="com.spoledge.aacplay"
android:versionCode="1"
android:versionName="@string/app_version"
>
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="10"/>
<application
android:label="@string/app_name"
android:debuggable="true"
>
<activity
android:name="com.spoledge.aacplay.AACPlayerActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
So can someone help me solve this out? Thanks!
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums & Read the Forum Rules
Moving to Q&A
Here is your problem:
05-27 06:12:00.734: E/AndroidRuntime(450): Caused by: java.lang.ClassNotFoundException: com.spoledge.aacplay.AACPlayerActivity in loader dalvik.system.PathClassLoader[/data/app/com.spoledge.aacplay-2.apk]
Click to expand...
Click to collapse
are you using any external libraries?
are they exactly in libs directory in your project?
Hello
I have the source code of an appli that plays .mp4 and i have to make it works with HLS.
The video and the sound are played but i have 2 problems ONLY WITH .m3u8 :
1) When seekTo() is activated (commentaries deleted) the sound is disabled and when i want to quit the player, it makes a long time to do and it makes crash the appli
2) setLooping doesn't work and return Error (-38,0), Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0 (below the code)
REMEMBER : THOSE PROBLEMS ARE JUST FOR .M3U8
Here's the code of the player :
Code:
private void playVideo() {
doCleanUp();
try {
// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(mFilePath);
mMediaPlayer.setDisplay(mSurfaceHolder);
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setOnPreparedListener(this);
//mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mMediaPlayer.seekTo(mResumePosition);
//mMediaPlayer.setLooping(true);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage(), e);
showErrorMessage(mErrorPlayingVideo);
// Toast.makeText(this, "Impossible de jouer la vidéo",
// 5000).show();
}
}
Here's a few of logs when setLooping is activated under setDataSource() :
Code:
error (-38, 0)
prepareAsync called in wrong state 0
prepareAsync_l return error =-38
error: null
java.lang.IllegalStateException
at android.media.MediaPlayer.prepare(Native Method)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.playVideo(BroadpeakDemoPlayer.java:409)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.onRequestFinished(BroadpeakDemoPlayer.java:585)
at fr.niji.lib.dataproxy.service.DataManager.handleResult(DataManager.java:262)
at fr.niji.lib.dataproxy.service.DataManager.onRequestFinished(DataManager.java:292)
at fr.niji.lib.dataproxy.service.ServiceHelper.handleResult(ServiceHelper.java:297)
at fr.niji.lib.dataproxy.service.ServiceHelper$EvalReceiver.onReceiveResult(ServiceHelper.java:119)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4126)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
and below the code :
Code:
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
error (-38, 0)
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
thank you for the help !
up
Ok I found the problem.
When you use seekTo() with a .m3u8 file and the value between the parentheses is set to 0, it doesn't work so I added a condition into playBackVideo() method :
Code:
if (mResumePosition > 0)
mMediaPlayer.seekTo(mResumePosition);
So mResumePosition will never be set to 0 and play at the beginning of the file.
Also, i resolved the setLooping() problem, in
Code:
public void onCompletion(final MediaPlayer mediaPlayer)
I added
Code:
mMediaPlayer.release();
playVideo();
and the looping works very well !
A new problem is arrived.
When i click on Resume button, the video goes to the last place when I stopped the player but there is no sound...
If someone has ideas...
Can somebody please tell me how these bits of code
Code:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri originalUri = data.getData();
selectedImageImageView.setImageURI(originalUri);
selectedImageImageView.setVisibility(View.VISIBLE);
progressDialog.setProgress(0);
progressDialog.show();
new GetImageFileTask(this).execute(imageHelper,
selectedImageImageView);
}
super.onActivityResult(requestCode, resultCode, data);
}
Code:
public static final int GALLERY_KITKAT_INTENT_CALLED = 2;
public static final int GALLERY_INTENT_CALLED = 1;
private final int PREF_WIDTH_IMAGE = 500;
private Activity activity;
public ImageHelper(Activity activity) {
this.activity = activity;
}
public void getImage() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
activity.startActivityForResult(intent, GALLERY_INTENT_CALLED);
} else {
showKitKatGallery();
}
}
private void showKitKatGallery() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
activity.startActivityForResult(intent, GALLERY_KITKAT_INTENT_CALLED);
}
public File getFileFromImageView(ImageView imageView) throws IOException {
int preferredWidth = PREF_WIDTH_IMAGE;
Bitmap origBitmap = drawableToBitmap(imageView.getDrawable());
int origWidth = origBitmap.getWidth();
int origHeight = origBitmap.getHeight();
int destHeight, destWidth;
if (origWidth <= preferredWidth || origHeight <= preferredWidth) {
destWidth = origWidth;
destHeight = origHeight;
} else {
destWidth = PREF_WIDTH_IMAGE;
destHeight = origHeight / (origWidth / destWidth);
}
File tempFile = new File(activity.getCacheDir(), "temp.png");
tempFile.createNewFile();
Bitmap bitmap = resizeBitmap(origBitmap, destWidth, destHeight);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bos);
byte[] bitmapData = bos.toByteArray();
FileOutputStream fos = new FileOutputStream(tempFile);
fos.write(bitmapData);
fos.close();
return tempFile;
}
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
int width = drawable.getIntrinsicWidth();
width = width > 0 ? width : 1;
int height = drawable.getIntrinsicHeight();
height = height > 0 ? height : 1;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
private Bitmap resizeBitmap(Bitmap inputBitmap, int newWidth, int newHeight) {
return Bitmap.createScaledBitmap(inputBitmap, newWidth, newHeight, true);
}
}
have managed to come up with this error:
Code:
05-15 02:10:01.199: E/AndroidRuntime(17169): FATAL EXCEPTION: main
05-15 02:10:01.199: E/AndroidRuntime(17169): Process: com.simplistic.bloxbackup, PID: 17169
05-15 02:10:01.199: E/AndroidRuntime(17169): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:13985 flg=0x43 }} to activity {com.simplistic.bloxbackup/com.simplistic.bloxbackup.activities.GalleryActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageURI(android.net.Uri)' on a null object reference
05-15 02:10:01.199: E/AndroidRuntime(17169): at android.app.ActivityThread.deliverResults(ActivityThread.java:3637)
05-15 02:10:01.199: E/AndroidRuntime(17169): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3680)
05-15 02:10:01.199: E/AndroidRuntime(17169): at android.app.ActivityThread.access$1300(ActivityThread.java:149)
05-15 02:10:01.199: E/AndroidRuntime(17169): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
05-15 02:10:01.199: E/AndroidRuntime(17169): at android.os.Handler.dispatchMessage(Handler.java:102)
05-15 02:10:01.199: E/AndroidRuntime(17169): at android.os.Looper.loop(Looper.java:211)
05-15 02:10:01.199: E/AndroidRuntime(17169): at android.app.ActivityThread.main(ActivityThread.java:5321)
05-15 02:10:01.199: E/AndroidRuntime(17169): at java.lang.reflect.Method.invoke(Native Method)
05-15 02:10:01.199: E/AndroidRuntime(17169): at java.lang.reflect.Method.invoke(Method.java:372)
05-15 02:10:01.199: E/AndroidRuntime(17169): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
05-15 02:10:01.199: E/AndroidRuntime(17169): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
05-15 02:10:01.199: E/AndroidRuntime(17169): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageURI(android.net.Uri)' on a null object reference
05-15 02:10:01.199: E/AndroidRuntime(17169): at com.simplistic.bloxbackup.activities.GalleryActivity.onActivityResult(GalleryActivity.java:101)
05-15 02:10:01.199: E/AndroidRuntime(17169): at android.app.Activity.dispatchActivityResult(Activity.java:6135)
05-15 02:10:01.199: E/AndroidRuntime(17169): at android.app.ActivityThread.deliverResults(ActivityThread.java:3633)
Because i don't know if any of you have seen my thread about my new app "Blox Backup" but the launch has been a big massive flop due this problem.
Now what i don't get is that it was all working as it should before i signed then published it?! I mean i know that apps don't work on every phone but this simply will not work at all no matter the phone!
So can someone please review the code and see where the null pointer is coming from because it shouldn't be coming up as null especially when it didn't before. I have tried to get an answer on Stack but nobody has bothered
So yeah please give me hand because i need this app back on Gplay
Thanks
I'm on my phone right now and have just taken a quick look, but my understanding is that "selectedImageView" is null. You could use something like Eclipse's debugging tool to check in real time where the crash happens and due to what.
So I've been playing around with it and it doesn't crash any more but it'll just finish the intent then do nothing. so nothing is being uploaded...
Code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == imageHelper.GALLERY_KITKAT_INTENT_CALLED) {
Uri originalUri = data.getData();
selectedImageImageView.setImageURI(originalUri);
selectedImageImageView.setVisibility(View.VISIBLE);
progressDialog.setProgress(0);
progressDialog.show();
new GetImageFileTask(this).execute(imageHelper,
selectedImageImageView);
}else{
if(resultCode == imageHelper.GALLERY_INTENT_CALLED){
Uri originalUri = data.getData();
selectedImageImageView.setImageURI(originalUri);
selectedImageImageView.setVisibility(View.VISIBLE);
progressDialog.setProgress(0);
progressDialog.show();
new GetImageFileTask(this).execute(imageHelper,
selectedImageImageView);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
Code:
public int GALLERY_KITKAT_INTENT_CALLED = 2;
public int GALLERY_INTENT_CALLED = 1;
public ImageHelper(Activity activity) {
this.activity = activity;
}
public void getImage() {
if (Build.VERSION.SDK_INT < 19) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
activity.startActivityForResult(intent, 2);
} else {
showKitKatGallery();
}
}
private void showKitKatGallery() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
activity.startActivityForResult(intent, 1);
}
I also have a feeling this
Code:
public class GetImageFileTask extends AsyncTask<Object, Object, Object> {
private OnGetImageFileListener listener;
public GetImageFileTask(OnGetImageFileListener listener) {
this.listener = listener;
}
@Override
protected Object doInBackground(Object[] params) {
File imageFile = null;
ImageHelper imageHelper = (ImageHelper) params[0];
ImageView imageView = (ImageView) params[1];
try {
imageFile = imageHelper.getFileFromImageView(imageView);
} catch (IOException e) {
e.printStackTrace();
}
return imageFile;
}
@Override
protected void onPostExecute(Object imageFile) {
listener.onGotImageFile((File) imageFile);
}
}
may have something to do with the problem but i could be wrong
X10_minipro said:
I'm on my phone right now and have just taken a quick look, but my understanding is that "selectedImageView" is null. You could use something like Eclipse's debugging tool to check in real time where the crash happens and due to what.
Click to expand...
Click to collapse
I done but it didn't show anything that i didn't already know
Right i give up, I've tried every single "solution" but absolutely nothing works, so i have no idea what's happened but it won't work so this app, unless someone can actually fix it, is going to off the play store
Okay, I'm feeling very very stupid right now, it turns out i forgot i deleted the imageview from the layout but made a rookie mistake and left the code. I'm such a twat.