|
Member 13229874 wrote: ...add itext library to the dependency... Of what? Eclipse, Android Studio, or some other IDE?
Member 13229874 wrote: if I type itex in the search... In what?
Member 13229874 wrote: ...there is nothing to show. What should be shown?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
It's been a while since I've participated on CP, and I'm back with a doozy
I'm having a problem with MediaExtractor and using a MemoryFile as the data source. In the real world, this media viewer is part of a larger app that supplies a chunk of bytes that contains a complete MP4 video. To eliminate all the other stuff, I have created a little demo app that only contains the viewer and a test MemoryFile. Please note that not using a MemoryFile, i.e. saving the video data to storage and playing from there, is not an option.
First, the code. I create the MemoryFile in the test app's MainActivity.onCreate
InputStream inS = getResources ().getAssets ().open ("testmp4.mp4");
int length = inS.available ();
byte[] data = new byte[length];
inS.read (data);
inS.close ();
m_memFile = new MemoryFile (null, length);
m_memFile.writeBytes (data, 0, 0, length);
Method getFD = MemoryFile.class.getMethod ("getFileDescriptor");
m_memFileFD = (FileDescriptor) getFD.invoke (m_memFile);
This is in the MainActivity's Play button click listener:
if (m_player == null)
{
m_player = new MyPlayer (MainActivity.this.m_events, MainActivity.this.m_memFileFD, MainActivity.this.m_memFile.length (), (SurfaceView) findViewById (R.id.viewerMediaVideo));
}
m_player.play ();
The video player is in the class MyPlayer that extends Runnable:
protected MediaExtractor m_extractor = null;
protected PlayerStates m_state = PlayerStates.STOPPED;
private SurfaceHolder m_surface = null;
protected FileDescriptor m_memFileFD = null;
protected long m_memFileLen = 0;
public MyPlayer (PlayerEvents ev, FileDescriptor fd, long len, SurfaceView s)
{
m_events = ev;
m_memFileFD = fd;
m_memFileLen = len;
m_surface = s.getHolder ();
}
public void play ()
{
if (m_state == PlayerStates.STOPPED)
{
m_stop = false;
new Thread (this).start ();
}
...
}
public void run ()
{
android.os.Process.setThreadPriority (Process.THREAD_PRIORITY_URGENT_AUDIO);
m_extractor = new MediaExtractor ();
try
{
m_extractor.setDataSource (m_memFileFD, 0, m_memFileLen);
}
catch (final Exception excp)
{
m_extractor.release ();
m_extractor = null;
m_handler.post (new Runnable (){public void run ()
{m_events.onError ("can't create extractor: " + excp.getMessage ()); } });
return;
}
....
}
Now for the problem. I have tested the same APK on different devices, both actual physical phones and emulators and the results are:
S5 with 4.4.2 / API:19 emulator --> works
M9 with 5.0.2 / API:21 emulator / API:22 emulator --> works
Nexus6 with 6.0 / API:23 emulator --> works
S7 with 6.0.1 / (no emulator for this point release) --> fails
Nexus6 with 7.0 / API:24 emulator --> fails
works means the video plays correctly
fails means I get the error "can't create extractor: Failed to instantiate extractor". This is the catch at the very beginning of the player's run method
6.0.1 logcat shows thirteen lines like (only varying between the digit 0 and 4):
FileSource: seek to 0 failed
7.0 / API:24 emulator logcat contains a single line:
FileSource: offset/length adjusted from 0/547251 to 0/0
I've tried two versions of the app on the physical devices. One has a minimumSDK set to 19 and the targetSDK / compileSDK / build tools are version 21. The second version has minSDK 19 and the rest 23. The version running on the emulators has minSDK19, targetSDK 23, and compileSDK/ buildTools 25 -- the latest that I just downloaded yesterday. All three different builds of the same code fail in the same pattern based on OS version.
This points me to a change between OS versions 6.0 and 6.0.1 causing the issue. However, I've done some poking into the sources available on the net and don't see anything suspicious.
Any ideas? Do I need to go report a bug to Google?
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
Just a followup ... I never did get around to harassing Google about this. I simply worked around the problem by checking the build version and only using the "old" way with a MemoryFile for KitKat and Lollipop and using the "new with API 23" MediaDataSource with the data behind the MemoryFile for Marshmallow and up.
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
I have created android chat application. When I send message it loops all messages through notification and then show the latest message instead of just showing newest message inside the notification!!!! How to fix this issue???
public class Chat extends AppCompatActivity
{
LinearLayout layout;
RelativeLayout layout_2;
ImageView sendButton;
EditText messageArea;
ScrollView scrollView;
Firebase reference1, reference2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
layout = (LinearLayout) findViewById(R.id.layout1);
layout_2 = (RelativeLayout)findViewById(R.id.layout2);
sendButton = (ImageView)findViewById(R.id.sendButton);
messageArea = (EditText)findViewById(R.id.messageArea);
scrollView = (ScrollView)findViewById(R.id.scrollView);
Firebase.setAndroidContext(this);
reference1 = new Firebase("https://zipa1x.firebaseio.com/messages/" + UserDetails.username + "_" + UserDetails.chatWith);
reference2 = new Firebase("https://zipa1x.firebaseio.com/messages/" + UserDetails.chatWith + "_" + UserDetails.username);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String messageText = messageArea.getText().toString();
if(!messageText.equals("")){
Map<String, String> map = new HashMap<String, String>();
map.put("message", messageText);
map.put("user", UserDetails.username);
reference1.push().setValue(map);
reference2.push().setValue(map);
messageArea.setText("");
}
}
});
reference1.addChildEventListener(new ChildEventListener()
{
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
for (DataSnapshot child: dataSnapshot.getChildren())
{
Map map = dataSnapshot.getValue(Map.class);
String message = map.get("message").toString();
String userName = map.get("user").toString();
if (userName.equals(UserDetails.username))
{
addMessageBox("You:-\n" + message, 1);
} else
{
addMessageBox(UserDetails.chatWith + ":-\n" + message, 2);
sendNotification(message,userName);
}
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
}
public void addMessageBox(String message, int type){
TextView textView = new TextView(Chat.this);
textView.setText(message);
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp2.weight = 1.0f;
if(type == 1) {
lp2.gravity = Gravity.LEFT;
textView.setBackgroundResource(R.drawable.bubble_in);
}
else{
lp2.gravity = Gravity.RIGHT;
textView.setBackgroundResource(R.drawable.bubble_out);
}
textView.setLayoutParams(lp2);
layout.addView(textView);
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
}
private void sendNotification(String message,String userName)
{
Intent intent = new Intent(this,Chat.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(userName)
.setContentText(message)
.setSound(notificationSound)
.setContentIntent(pendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.notify(0, builder.build());
}
}
|
|
|
|
|
Please provide some proper details, and explain exactly where the error occurs.
|
|
|
|
|
I would like to create an android app that will predict football result..i am planning to use neural networks behind to work in the app...how can i go about it..the difficult side is to apply the algorithm...am i going to code it or what should i do..
|
|
|
|
|
Member 13208523 wrote: .how can i go about it By starting.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
i dont understand what you are trying to mean
|
|
|
|
|
Member 13208523 wrote: am i going to code it Well that would be a good start.
|
|
|
|
|
I am trying to create an app to get location and make it location change aware.
|
|
|
|
|
You can use the Location APIs in Android, that are supported in Java language. You can utilize it to consume the location services from GSM or GPS based location services.
I wrote an article that covers the basics of this concept; Ok Android, Broadcast my location!
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
See here, and here (preferred).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I used jdbc ("net.sourceforge.jtds.jdbc.Driver" -jtds-1.3.1.jar)for My Android Application:
String ip = "192.168.3.67";
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = "QLNV";
String un = "sa";
String password = "admin";
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName(classs);
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";";
conn = DriverManager.getConnection(ConnURL);...
I tested it on Android Emulator: it worked well but I tested it on my Android phone: it maybe not worked well. I don't know why? please help me, thanks much..
|
|
|
|
|
Your phone is probably not on your local 192.168.xxx.xxx LAN.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
So..How can i do? I added :
<uses-permission android:name="android.permission.INTERNET">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
in AndroidManifest.xml
So can help me? thanhs a lot!
|
|
|
|
|
Before worrying about permissions, I'd make sure the phone is connected to your LAN through wifi. The phone should show your network name and "Connected" at the top of the wifi list under settings. Until you get that set up, you have no hope of accessing your server.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Member 11900140 wrote: on my Android phone: it maybe not worked well. You need to explain what that means, we cannot guess what failures or errors you see.
|
|
|
|
|
My Real Android phone: can not connect to or get data from my Sql Server database QLNS.
|
|
|
|
|
Why not? Does it have a network connection to the database server?
|
|
|
|
|
Are you checking for errors? Are exceptions being thrown? Have you stepped through the code using the debugger?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Don't be silly. Who does that when CodeProject is here?
|
|
|
|
|
Twice...because once is never enough.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Short Video Demonstration of the issue(s)
I have developed a recipe search application that obtains data from an API and it allows the user to view and save the data.
My android application uses multiple fragments within one activity. They share one container and when a new fragment is loaded it replaces the old fragment.
My application has the following fragments: Home, Search, Filters, RecipeView and more.
I am experiencing multiple issues with popping the fragment back stack once a search has been carried out or a favourite recipe has been displayed. The search fragment is a grid view that uses a custom adapter, and to perform a search the user uses a toolbar search view which executes code upon pressing the submit (return) button.
The home fragment is displayed first allowing a user to click a quick search button such as breakfast, clicking the button displays the search fragment with results from the API. The user can then click on an item which opens the RecipeView fragment, pressing the back button on these fragments does not cause an issue and a user can navigate back to the previous fragments including the home one that was displayed initially.
Additionally, a user can navigate to the search fragment using the navigation drawer. The search fragment allows the user to perform a search or click a filter via buttons on the toolbar. Clicking the search icon/button allows a user to enter text and once they press enter/return the search is perform and the grid view is populated.
Prior to performing a search or clicking the search button, pressing the filter button displays the filters fragment and from there, pressing the back button will allow a user to navigate back to the search view fragment.
If the user presses the search button which will open the search view menu item (allowing text input on the toolbar) and then presses the filters button, the filters activity is displayed. However, pressing the back button does not navigate to the previous fragment, it removes the focus from the toolbar. Pressing the back button again still does not navigate back and changes the toolbars text back to the search fragments specified title ("Recipe Search"). Pressing the back button again will then navigate back to the search fragment, removing the filters fragment from sight.
I have tried removing the focus from the toolbar so that pressing back is not removing toolbars focus and the app still requires three back button presses.
Furthermore, I am having another issue with fragments overlaying each other. From the home fragment that is loaded on create, if a user navigates using the side menu to the favourites fragment, a list of the saved favourites in a grid view are shown using the search fragment. Pressing the back button from the search fragment does not cause any issues and the app will navigate back to the home fragment; additionally, clicking a recipe will open the RecipeView fragment displaying a recipes information.
The issue arises from here. If the back button is pressed the app will navigate backwards loading the home fragment not the search fragment and the recipe fragment stays on screen causing both fragments to overlap. Pressing the back button again will remove the home fragment and leave the recipe fragment in the container; pressing the back button again will close the application (The search fragment is not shown and the order is incorrect).
Attempts
1. I have tried implementing this ([Avoid fragments overlapping][2])
2. I have tried calling classes using a new instance method rather than creating new ones in the MainActivity
3. I have tried to add fragments rather than replace them
4. I have tried overriding the back button press
5. I have tried addToBackStack(null) & addToBackStack(FragmentTag)
6. I have tried to remove all views from the frame layout within my fragment handler method
Thank you for taking the time to read my post
java - (Short Video Demo) Fragment back navigation issue and overlapping fragments using a frame layout - Stack Overflow[^]
Daniel Ali
|
|
|
|
|
delete.Thanks
modified 17-May-17 4:55am.
|
|
|
|
|
Please don't post links to questions elsewhere; that is as bad as posting the same question again.
|
|
|
|