Adsense Ad

Wednesday, 24 January 2018

HOW TO - Performing Text_IO on the client using WebUtil.


Introduction

Many Forms applications utilize Text_IO to read and write data from the file system. When moving your Forms application to the Web, Text_IO works in exactly the same manner as client/server. However, you must now remember that your application is running on the application server and not the client machine.

This may infact be the behavior you desire (for example, using Text_IO to write out auditing information). However, it could be that you need Text_IO to access the machine at which the user is sitting. For example, a salesman logs onto the Forms application and wants the application to read sales data from his local machine.

WebUtil provides you the functionality to perform client side Text_IO.
Set Up

For the steps to set up WebUtil, please refer to the WebUtil Familiarization Manual available as part of the software download.
Changing code

Consider the following code:

PROCEDURE WRITE_ITEM_BLOCK (FILENAME IN VARCHAR2) IS
  MYFILE TEXT_IO.FILE_TYPE;
  CUR_REC NUMBER;
BEGIN
  GO_BLOCK('S_ITEM');
  CUR_REC := :SYSTEM.CURSOR_RECORD;
  IF :SYSTEM.BLOCK_STATUS != 'NEW' THEN
    FIRST_RECORD;
    MYFILE := TEXT_IO.FOPEN(FILENAME, 'W');
    TEXT_IO.PUTF(MYFILE,'Item_ID,Proudct_ID,Description'||CHR(10));
    LOOP
      TEXT_IO.PUTF(MYFILE, TO_CHAR(:S_ITEM.ITEM_ID)||',');
      TEXT_IO.PUTF(MYFILE, TO_CHAR(:S_ITEM.PRODUCT_ID)||',');
      TEXT_IO.PUTF(MYFILE, :S_ITEM.DESCRIPTION||',');
      TEXT_IO.PUTF(MYFILE, CHR(10));
      EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
      NEXT_RECORD;
    END LOOP;
    TEXT_IO.FCLOSE(MYFILE);
  END IF;
  GO_RECORD(CUR_REC);
END;

This code will go through the records of a block and output the data to a named file. To perform the same functionality, but on the client side, attatch the WebUtil object library and PL/SQL library, and replace any instance of TEXT_IO with CLIENT_TEXT_IO.

The resulting code will now work, as before, but write the file to the client machine.

PROCEDURE WRITE_ITEM_BLOCK (FILENAME IN VARCHAR2) IS
  MYFILE CLIENT_TEXT_IO.FILE_TYPE;
  CUR_REC NUMBER;
BEGIN
  GO_BLOCK('S_ITEM');
  CUR_REC := :SYSTEM.CURSOR_RECORD;
  IF :SYSTEM.BLOCK_STATUS != 'NEW' THEN
    FIRST_RECORD;
    MYFILE := CLIENT_TEXT_IO.FOPEN(FILENAME, 'W');
    CLIENT_TEXT_IO.PUTF(MYFILE,'Item_ID,Proudct_ID,Description'||CHR(10));
    LOOP
      CLIENT_TEXT_IO.PUTF(MYFILE, TO_CHAR(:S_ITEM.ITEM_ID)||',');
      CLIENT_TEXT_IO.PUTF(MYFILE, TO_CHAR(:S_ITEM.PRODUCT_ID)||',');
      CLIENT_TEXT_IO.PUTF(MYFILE, :S_ITEM.DESCRIPTION||',');
      CLIENT_TEXT_IO.PUTF(MYFILE, CHR(10));
      EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
      NEXT_RECORD;
    END LOOP;
    CLIENT_TEXT_IO.FCLOSE(MYFILE);
  END IF;
  GO_RECORD(CUR_REC);
END; 

Creating Simple Popup Menu


First create a button on main activity
<Button

    android:layout_width="150dp"

    android:layout_height="wrap_content"

    android:text="View Popup Menu"

    android:textSize="20sp"

    android:textColor="#fff"

    android:textStyle="bold"

    android:background="@color/colorPrimaryDark"

    android:onClick="ShowPopup"

    android:textAllCaps="false"

    android:layout_gravity="center"

    />

Now in res directory create new directory for menu named as menu




Then create popup_menu in menu directory and then implement following code
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">



    <item android:id="@+id/vuimg"

        android:title="View Image"/>

    <item android:id="@+id/nuimg"

        android:title="New Image"/>



</menu>

Now go to main activity and create method named as ShowPopup for button
public void ShowPopup(View v){

    PopupMenu popupMenu = new PopupMenu(this,v);

    popupMenu.getMenuInflater().inflate(R.menu.popup_menu,popupMenu.getMenu());

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override

        public boolean onMenuItemClick(MenuItem item) {

            Toast.makeText(MainActivity.this,""+item.getTitle(),Toast.LENGTH_SHORT).show();

   switch (item.getItemId()){

    case R.id.vuimg:

        getPicFromGallery();

        return true;

    case R.id.nuimg:

        camerOpenForPic();

        return true;

    default: return false;


        }

    });

    popupMenu.show();

}


Thursday, 18 January 2018

Rep-51002 Bind to Report server failed

Symptom
Trying to access the Reports Server gives following error:

REP-51002: Bind to Reports Server failed

This error is given when you try to access Reports Server using getserverinfo or showjobs. For 

example:
http://or11/reports/rwservlet/getserverinfo?server=rep_dev
or
http://or1/reports/rwservlet/showjobs?server=rep_dev

Also, running the command "rwdiag.sh -findAll" gives error:
REP-50503 No server found in the network

However, in the Reports Server trace files (for example D:\Oracle10GASSuite\reports\logs\rep_dev), it shows that the Reports Server is actually up and running. There are no errors in the trace files.

Cause
There are multiple causes some of them are following

Cause 1: multiple network cards (NICs), use of VPN software, missing Gateway configuration for the network definitions in the NIC can cause this behaviour, and/or use of VMware

Solution 1: If your machine setup uses multiple network cards and/or you are using software VPN (e.g. cisco) and/or you have VMware installed on your machine, switch to using the naming service for the server.

Simple Solution 1: Just try to disable VMWare network cards in network settings.


Cause 2 : This is a firewall permissions problem.
It is not a problem with the Reports Server, as the server traces show it is up and running.

Solution 2:  To implement the solution, please execute the following steps:

1. Open the port on the firewall to allow the Reports Server to be accessible.
a) Run command:
rwdiag.sh -findAll
b) From output, check what value is used for Channel port. For example:
Broadcast mechanism used to locate servers
Channel address = ###.###.###.###
Channel port = 14021
c) Open the channel port on the firewall, in this case, it is port 14021.
2. In the firewall, authorize requests from your host's IP address to ###.###.###.### (the channel address shown above).
Note: If the above still does not work, then you may try adding the name of the machine where Reports Server is and the IP for that machine to the hosts file (/etc/hosts or C:\WINDOWS\system32\drivers\etc\hosts). For example:

Wednesday, 17 January 2018

How to create simple notifications in android

Building a Notification

The examples in this class are based on the NotificationCompat.Builder class.NotificationCompat.Builder is in the Support Library. You should use NotificationCompat and its subclasses, particularly NotificationCompat.Builder, to provide the best notification support for a wide range of platforms.
Create a Notification Builder

When creating a notification, specify the UI content and actions with a NotificationCompat.Builderobject. At bare minimum, a Builder object must include the following:
·         A small icon, set by setSmallIcon()
·         A title, set by setContentTitle()
·         Detail text, set by setContentText()
For example:
NotificationCompat.Builder mBuilder =
   
new NotificationCompat.Builder(this)
   
.setSmallIcon(R.drawable.notification_icon)
   
.setContentTitle("My notification")
   
.setContentText("Hello World!");

Define the Notification's Action

Although actions are optional, you should add at least one action to your notification. An action takes users directly from the notification to an Activityin your application, where they can look at the event that caused the notification or do further work. Inside a notification, the action itself is defined by a PendingIntent containing an Intent that starts an Activity in your application.
How you construct the PendingIntent depends on what type of Activity you're starting. When you start an Activity from a notification, you must preserve the user's expected navigation experience. In the snippet below, clicking the notification opens a new activity that effectively extends the behavior of the notification. In this case there is no need to create an artificial back stack (see Preserving Navigation when Starting an Activity for more information):
Intent resultIntent = new Intent(this, ResultActivity.class);
...
// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
   
PendingIntent.getActivity(
   
this,
   
0,
    resultIntent
,
   
PendingIntent.FLAG_UPDATE_CURRENT
);

Set the Notification's Click Behavior

To associate the PendingIntent created in the previous step with a gesture, call the appropriate method of NotificationCompat.Builder. For example, to start an activity when the user clicks the notification text in the notification drawer, add the PendingIntent by calling setContentIntent(). For example:
PendingIntent resultPendingIntent;
...
mBuilder
.setContentIntent(resultPendingIntent);

Issue the Notification

To issue the notification:
·         Get an instance of NotificationManager.
·         Use the notify() method to issue the notification. When you call notify(), specify a notification ID. You can use this ID to update the notification later on. This is described in more detail in Managing Notifications.
·         Call build(), which returns a Notification object containing your specifications.
For example:
NotificationCompat.Builder mBuilder;
...
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
       
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr
.notify(mNotificationId, mBuilder.build());



Sample Project:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   
xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:orientation="vertical"
   
tools:context="com.example.nice.simplenotifications.MainActivity">

    <
TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
        
android:text="Simple Notifications!"
       
android:textSize="50sp"
       
app:layout_constraintBottom_toBottomOf="parent"
       
app:layout_constraintLeft_toLeftOf="parent"
       
app:layout_constraintRight_toRightOf="parent"
       
app:layout_constraintTop_toTopOf="parent" />
    <
EditText
       
android:layout_marginTop="30dp"
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:hint="Type Your Notification Here"
       
android:id="@+id/nTxt"
       
/>
    <
Button
       
android:layout_marginTop="10dp"
       
android:background="@color/colorPrimaryDark"
       
android:layout_marginRight="10dp"
       
android:layout_marginLeft="10dp"
       
android:text="Send Notification"
        
android:textAllCaps="false"
       
android:textStyle="bold"
       
android:textColor="#fff"
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:id="@+id/btn"/>

</
LinearLayout
  
>




JAVA:
package com.example.nice.simplenotifications;

import android.app.NotificationManager;
import android.content.Context;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {
EditText
txt;
Button
btn;
   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);
       
txt = (EditText) findViewById(R.id.nTxt);
       
btn = (Button) findViewById(R.id.btn);

       
btn.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
if (txt.getText().toString().isEmpty()){
                    sendNotification(
"Please type your custom notification!");
                }
else {
                    sendNotification(
txt.getText().toString());
                }
            }
        });
    }

   
public void sendNotification(String txt) {

       
//Get an instance of NotificationManager//
       
Uri nSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        SimpleDateFormat dt =
new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss", Locale.getDefault());
        String dt1 = dt.format(
new Date());
        NotificationCompat.Builder mBuilder =
               
new NotificationCompat.Builder(this)
                        .setSmallIcon(R.mipmap.
ic_launcher)
                        .setContentTitle(txt)
                        .setContentText(dt1)
                        .setSound(nSound)
                        .setDefaults(NotificationCompat.
DEFAULT_VIBRATE);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.
NOTIFICATION_SERVICE);
        mNotificationManager.notify(
001, mBuilder.build());
    }

}


Tuesday, 16 January 2018

How to connect Android App with Oracle Database

You can not directly access the Oracle database from android Application. you need to create webservices in PHP, .net or in Java to make connection with Oracle Database. After creating this webservice , you need to connect your application with the webservice.

Or, use a Virtual JDBC Driver that uses a three-tier architecture: your JDBC code is sent through HTTP to a remote Servlet that filters the JDBC code.

This is the simplest way of connecting with Oracle Database. 

To connect oracle database using JDBC you need to download and sync ojdbc14.jar.
you can review my following post.

Now apply following code to connect oracle database.

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context="com.example.administrator.connect_ora.MainActivity">


    <TextView
        android:id="@+id/hello"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />
</LinearLayout>


JAVA

package com.example.administrator.connect_ora;

import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import static oracle.net.aso.C12.e;

public class MainActivity extends AppCompatActivity {

    private static final String DEFAULT_DRIVER = "oracle.jdbc.driver.OracleDriver";
    private static final String DEFAULT_URL = "jdbc:oracle:thin:@192.168.2.32:1521:dev";
    private static final String DEFAULT_USERNAME = "scott";
    private static final String DEFAULT_PASSWORD = "tiger";

    private Connection connection;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }

        TextView tv = (TextView) findViewById(R.id.hello);
        try {
            this.connection = createConnection();
            Toast.makeText(MainActivity.this, "Connected",
                    Toast.LENGTH_SHORT).show();
            Statement stmt=connection.createStatement();
            StringBuffer stringBuffer = new StringBuffer();
            ResultSet rs=stmt.executeQuery("select * from cat");
            while(rs.next()) {
                stringBuffer.append( rs.getString(1)+"\n");
            }
            tv.setText(stringBuffer.toString());
            connection.close();
        }
        catch (Exception e) {

            Toast.makeText(MainActivity.this, ""+e,
                    Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    }

    public static Connection createConnection(String driver, String url, String username, String password) throws ClassNotFoundException, SQLException {

        Class.forName(driver);
        return DriverManager.getConnection(url, username, password);
    }

    public static Connection createConnection() throws ClassNotFoundException, SQLException {
        return createConnection(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
    }

}