Hello I'm Trying to learn my firsy app (Flash Lifght app) ..
I understand that i need to give app permissions etc.
Can some one expaine me how do i need to do that when im opening new project.
I what is code or the file i need to paste the code..
Sorry for bad english and thanks for helping!
natan.p said:
Hello I'm Trying to learn my firsy app (Flash Lifght app) ..
I understand that i need to give app permissions etc.
Can some one expaine me how do i need to do that when im opening new project.
I what is code or the file i need to paste the code..
Sorry for bad english and thanks for helping!
Click to expand...
Click to collapse
You need to set the permissions in the AndroidManifest.xml file add a uses permission and under that class an android:name= *camera*
Regards
MasterAwesome
MasterAwesome said:
You need to set the permissions in the AndroidManifest.xml file add a uses permission and under that class an android:name= *camera*
Regards
MasterAwesome
Click to expand...
Click to collapse
I have an error i found tutorial how create flash light app i cop all codes ti manifest etc files but i have error with the java file........
the error: The public type FlashlightActivity must be defined in its own file.
the code: Press Control + F and search this line public class FlashlightActivity extends Activity {
PHP:
package com.natan.flashlight;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.util.Log;
import android.widget.ToggleButton;
/**
* @author Prabu
* July 30 2013
* @version 1.0
*
*/
public class FlashlightActivity extends Activity { // <--------------------------------------- There are the error..
private Camera camera;
private ToggleButton button;
private final Context context = this;
//@see android.app.Activity#onStop()
@Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}
/**
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.flashlight);
button = (ToggleButton) findViewById(R.id.togglebutton);
final PackageManager pm = context.getPackageManager();
if(!isCameraSupported(pm)){
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("No Camera");
alertDialog.setMessage("The device's doesn't support camera.");
alertDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int which) {
Log.e("err", "The device's doesn't support camera.");
}
});
alertDialog.show();
}
camera = Camera.open();
}
public void onToggleClicked(View view) {
PackageManager pm=context.getPackageManager();
final Parameters p = camera.getParameters();
if(isFlashSupported(pm)){
boolean on = ((ToggleButton) view).isChecked();
if (on) {
Log.i("info", "torch is turn on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
} else {
Log.i("info", "torch is turn off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
}
}else{
button.setChecked(false);
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("No Camera Flash");
alertDialog.setMessage("The device's camera doesn't support flash.");
alertDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int which) {
Log.e("err", "The device's camera doesn't support flash.");
}
});
alertDialog.show();
}
}
/**
* @param packageManager
* @return true <b>if the device support camera flash</b><br/>
* false <b>if the device doesn't support camera flash</b>
*/
private boolean isFlashSupported(PackageManager packageManager){
// if device support camera flash?
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
return true;
}
return false;
}
/**
* @param packageManager
* @return true <b>if the device support camera</b><br/>
* false <b>if the device doesn't support camera</b>
*/
private boolean isCameraSupported(PackageManager packageManager){
// if device support camera?
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
return true;
}
return false;
}
}
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
natan.p said:
I have an error i found tutorial how create flash light app i cop all codes ti manifest etc files but i have error with the java file........
the error: The public type FlashlightActivity must be defined in its own file.
the code: Press Control + F and search this line public class FlashlightActivity extends Activity {
PHP:
package com.natan.flashlight;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.util.Log;
import android.widget.ToggleButton;
/**
* @author Prabu
* July 30 2013
* @version 1.0
*
*/
public class FlashlightActivity extends Activity { // <--------------------------------------- There are the error..
private Camera camera;
private ToggleButton button;
private final Context context = this;
//@see android.app.Activity#onStop()
@Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}
/**
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.flashlight);
button = (ToggleButton) findViewById(R.id.togglebutton);
final PackageManager pm = context.getPackageManager();
if(!isCameraSupported(pm)){
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("No Camera");
alertDialog.setMessage("The device's doesn't support camera.");
alertDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int which) {
Log.e("err", "The device's doesn't support camera.");
}
});
alertDialog.show();
}
camera = Camera.open();
}
public void onToggleClicked(View view) {
PackageManager pm=context.getPackageManager();
final Parameters p = camera.getParameters();
if(isFlashSupported(pm)){
boolean on = ((ToggleButton) view).isChecked();
if (on) {
Log.i("info", "torch is turn on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
} else {
Log.i("info", "torch is turn off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
}
}else{
button.setChecked(false);
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("No Camera Flash");
alertDialog.setMessage("The device's camera doesn't support flash.");
alertDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int which) {
Log.e("err", "The device's camera doesn't support flash.");
}
});
alertDialog.show();
}
}
/**
* @param packageManager
* @return true <b>if the device support camera flash</b><br/>
* false <b>if the device doesn't support camera flash</b>
*/
private boolean isFlashSupported(PackageManager packageManager){
// if device support camera flash?
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
return true;
}
return false;
}
/**
* @param packageManager
* @return true <b>if the device support camera</b><br/>
* false <b>if the device doesn't support camera</b>
*/
private boolean isCameraSupported(PackageManager packageManager){
// if device support camera?
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
return true;
}
return false;
}
}
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
Click to expand...
Click to collapse
You can't have 2 public class in the same file.. Create a new class
Regards
MasterAwesome
MasterAwesome said:
You can't have 2 public class in the same file.. Create a new class
Regards
MasterAwesome
Click to expand...
Click to collapse
What you mean two public classes?
Sent from my Nexus 5 using Tapatalk
natan.p said:
What you mean two public classes?
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Main activity and flashlight.. Just remove the public for flashlight
Regards
MasterAwesome
Related
Hello XDA,
So I've not found anyone properly discussing this. If they do, please link me to the page and don't flame
I've been making an app for my school and so far, I've been doing alright. But now I have run into a problem which seems to be very hard to solve for me alone.
Namely, I have an EditText and a Button in one Activity and a WebView as a different Activity.
I'm trying to get the EditText String into the WebView URL (String being variable, Button initiating the WebView), but get a lot of errors, some not even related to that.
I would really appreciate it if someone could have a look at the code and help me with this
MyWebView.java:
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebView extends Activity {
WebView mWebView;
EditText mEtxtStudentNum;
static String StudentNumFromHome = bas.sie.Antonius.Home.StudentNum;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("http://carmelcollegegouda.nl/site_ant/roosters/standaardroosters/Lee1_" + StudentNumFromHome + ".htm");
}
}
Home.java (Homescreen):
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Home extends Activity {
Button mBtnStSchedule;
static EditText mEtxtStudentNum;
static final String StudentNum = mEtxtStudentNum.getText().toString();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button next = (Button) findViewById(R.id.BtnStSchedule);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), MyWebView.class);
startActivityForResult(myIntent, 0);
}
});
// TODO Auto-generated method stub
}
}
AntoniusActivity.java (Main):
Code:
package bas.sie.Antonius;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;
public class AntoniusActivity extends TabActivity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Home.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("home").setIndicator("Home",
res.getDrawable(R.drawable.ic_tab_home))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, External.class);
spec = tabHost.newTabSpec("external").setIndicator("External",
res.getDrawable(R.drawable.ic_tab_external))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Contact.class);
spec = tabHost.newTabSpec("contact").setIndicator("Contact",
res.getDrawable(R.drawable.ic_tab_contact))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
In AntoniusActivity, the private class HelloWebViewClient is underlined with yellow (never used), specifically the bit "HelloWebViewClient".
It's also throwing FC's at startup, and errors in LogCat, but I'll post those later on, as it's 10.30 PM here, and school goes on
Thanks in advance,
bassie1995
No suggestions yet?
How you doin'? Greetings from my GT-I9000!
I have trouble creating a service for a mediaplayer. I would like to have startforeground instead of this as well. But I have no proof of my service running. So I dont know if my code actually works. Can someone help me?
If someone is able to help me completely setting up my service, I may pay €5-10. I received €50 from the company to set up a developer account. So I have €25 left.
I am creating a streaming app for a radio station to listen to the internet stream.
Code:
package jonashendrickx.radioplayer.rgrfm;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class RadioService extends Service {
private final IBinder mBinder = new RadioBinder();
@Override
public void onCreate() {
Toast.makeText(this, "Let's Go", Toast.LENGTH_SHORT).show();
}
@Override
public IBinder onBind(Intent arg0) {
Log.e("LocalService", "Launched");
return mBinder;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("LocalService", "Received start id " + startId + ": " + intent);
return START_STICKY;
}
public class RadioBinder extends Binder {
RadioService getService() {
return RadioService.this;
}
}
}
Code:
package jonashendrickx.radioplayer.rgrfm;
import android.os.Bundle;
import android.os.IBinder;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
mRadioService = ((RadioService.RadioBinder)service).getService();
}
@Override
public void onServiceDisconnected(ComponentName className) {
mRadioService = null;
}
};
private RadioService mRadioService;
private boolean mIsBound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
doBindService();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
protected void onDestroy() {
super.onDestroy();
doUnbindService();
}
void doBindService() {
bindService(new Intent(this, RadioService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
Log.e("", "service started");
}
void doUnbindService() {
if (mIsBound) {
// Detach our existing connection.
unbindService(mConnection);
mIsBound = false;
}
}
}
I have already service up and running. So that is working well. Now I am stuck with startForeground. My notifications dont seem to show so I believe startForeground isnt working as well.
I am developing for API range 10-17
I already tried several tutorials without luck
Is someone willing to help me out?
http://www28.zippyshare.com/v/73408891/file.html
Code:
package jonashendrickx.radioplayer.rgrfm;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Binder;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
public class RadioService extends Service implements OnErrorListener {
private final IBinder mBinder = new RadioBinder();
private MediaPlayer mMediaPlayer;
private final String[] mirrors = {
"http://stream.intronic.nl/rgrfm",
"http://shoutcast01.edpnet.net:10210"
};
@Override
public IBinder onBind(Intent arg0) {
return mBinder;
}
@Override
public void onCreate() {
initializeMediaPlayer();
startPlaying();
}
@Override
public void onDestroy() {
stopPlaying();
}
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mp.stop();
mp.release();
return false;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//Log.i("LocalService", "Received start id " + startId + ": " + intent);
return START_STICKY;
}
private void initializeMediaPlayer() {
mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(mirrors[0]);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void startPlaying() {
try {
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.prepareAsync();
} catch (IllegalStateException ex) {
ex.printStackTrace();
return;
}
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mMediaPlayer.start();
}
});
}
private void stopPlaying() {
if (mMediaPlayer.isPlaying()) {
mMediaPlayer.stop();
mMediaPlayer.release();
initializeMediaPlayer();
}
}
public class RadioBinder extends Binder {
RadioService getService() {
return RadioService.this;
}
}
}
Code:
package jonashendrickx.radioplayer.rgrfm;
import android.os.Bundle;
import android.os.IBinder;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;
public class MainActivity extends Activity implements OnClickListener {
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
mRadioService = ((RadioService.RadioBinder)service).getService();
}
@Override
public void onServiceDisconnected(ComponentName className) {
mRadioService = null;
mToggleButtonMediaPlayer.setChecked(false);
}
};
private RadioService mRadioService;
private boolean mIsBound;
private ToggleButton mToggleButtonMediaPlayer;
@Override
public void onClick(View view) {
if (view.equals(mToggleButtonMediaPlayer)) {
if (mRadioService == null) {
doBindService();
} else {
doUnbindService();
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToggleButtonMediaPlayer = (ToggleButton)findViewById(R.id.toggleButtonMediaPlayer);
mToggleButtonMediaPlayer.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return false;
}
@Override
protected void onDestroy() {
super.onDestroy();
}
void doBindService() {
bindService(new Intent(this, RadioService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
}
void doUnbindService() {
if (mIsBound) {
unbindService(mConnection);
mIsBound = false;
}
}
}
djjonastybe said:
I have already service up and running. So that is working well. Now I am stuck with startForeground. My notifications dont seem to show so I believe startForeground isnt working as well.
I am developing for API range 10-17
I already tried several tutorials without luck
Is someone willing to help me out?
http://www28.zippyshare.com/v/73408891/file.html
Click to expand...
Click to collapse
Where do you call startForeground? I can see just bind.
EDIT: I did not check the zip file as I never download any files if I don't know whether I can trust them. Nothing against you.
EDIT: You could try something like this: (I didn't test it)
Code:
private static final int NOTIFICATION_ID = 7392749; //value doen't matter
@Override
public void runInForeground() {
Notification n = new Notification(R.drawable.ic_launcher, "music is playing", System.currentTimeMillis());
PendingIntent i = PendingIntent.getActivity(this, 0, null, 0);
n.setLatestEventInfo(this, "Music Player", "Playing some music", i);
startForeground(NOTIFICATION_ID, n);
}
EDIT: You could also check out this project: https://github.com/commonsguy/cw-android/tree/master/Notifications/FakePlayer
Note: Text content in the code blocks is automatically word-wrapped
package com.connection.phonedetails;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class Test extends Activity {
private static final int REQUEST_CODE = 10;
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.alert);
DatabaseHandler db = new DatabaseHandler(this);
Intent intent = new Intent(this,AlertDialogExample.class);
startActivityForResult(intent,REQUEST_CODE);
}
@override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 10) {
if(resultCode == RESULT_OK){
String result=data.getStringExtra("TYPE");
Toast.makeText(getApplicationContext(),"Your sim type iss POST paidddddddddd", Toast.LENGTH_LONG).show();
}
if (resultCode == RESULT_CANCELED) {
Toast.makeText(getApplicationContext(),"Your sim type iss PREEEEE paidddddddddd", Toast.LENGTH_LONG).show();
}
}
}
}
this is alert dialog activity.
view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
package com.connection.phonedetails;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class AlertDialogExample extends Activity {
// this context will use when we work with Alert Dialog
final Context context = this;
// just for test, when we click this button, we will see the alert dialog.
private Button button;
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.alert);
/* Alert Dialog Code Start*/
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Select Your SIM Type"); //Set Alert dialog title here
//alert.setMessage("Enter your Name Here"); //Message here
alert.setPositiveButton("Post Paid", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// String value = input.getText().toString();
// Do something with value!
//You will get input data in this variable.
Toast.makeText(getApplicationContext(),"Post Paid", Toast.LENGTH_LONG).show();
//db.addContact(new SimDetails( telephonyManager.getSimSerialNumber(), telephonyManager.getNetworkOperatorName(),"Post"));
Intent returnIntent = new Intent();
returnIntent.putExtra("TYPE","POST Paid");
setResult(RESULT_OK,returnIntent);
finish();
}
});
alert.setNegativeButton("Pre Paid", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
Toast.makeText(getApplicationContext(),"Pre Paid", Toast.LENGTH_LONG).show();
Intent returnIntent = new Intent();
returnIntent.putExtra("TYPE","PRE Paid");
setResult(RESULT_CANCELED,returnIntent);
finish();
}
});
AlertDialog alertDialog = alert.create();
alertDialog.show();
/* Alert Dialog Code End*/
}
/*
@override
public void finish() {
Intent data = new Intent();
// Return some hard-coded values
data.putExtra("TYPE", "Swinging on a star. ");
data.putExtra("returnKey2", "You could be better then you are. ");
setResult(RESULT_OK, data);
super.finish();
}*/
}
this is working fine.Anyway if added the below two line end Oncreate method of the main activity it doesn't wait untill the alert dialog finishes.it goes to contact activity .So i don't have chance to select option from alert dialog.how to avoid this situation?
view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
Intent contact = new Intent(getApplicationContext(),Contacts.class);
startActivity(contact);
Anyone see what im doing wrong here? im new to java so i dont have a clue..
successfully compiles without a problem but crashes on start, the blue code i have added
Code:
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
[COLOR=DeepSkyBlue]import android.widget.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;[/COLOR]
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
[COLOR=DeepSkyBlue] Button startpatching = (Button)findViewById(R.id.start);
startpatching.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Process proc = Runtime.getRuntime().exec("/data/local/startpatch.sh /");
BufferedReader read = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
try {
proc.waitFor();
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
while (read.ready()) {
System.out.println(read.readLine());
}
} catch (IOException e) {
System.out.println(e.getMessage());
}}
});
};[/COLOR]
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
Probably would be wise to include the stack trace...
ricky310711 said:
Anyone see what im doing wrong here? im new to java so i dont have a clue..
successfully compiles without a problem but crashes on start, the blue code i have added
Code:
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
[COLOR=DeepSkyBlue]import android.widget.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;[/COLOR]
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
[COLOR=DeepSkyBlue] Button startpatching = (Button)findViewById(R.id.start);
startpatching.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Process proc = Runtime.getRuntime().exec("/data/local/startpatch.sh /");
BufferedReader read = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
try {
proc.waitFor();
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
while (read.ready()) {
System.out.println(read.readLine());
}
} catch (IOException e) {
System.out.println(e.getMessage());
}}
});
};[/COLOR]
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
Click to expand...
Click to collapse
Post a log/stacktrace as jcase suggested and also the content of activity_main.xml
jcase said:
Probably would be wise to include the stack trace...
Click to expand...
Click to collapse
Jonny said:
Post a log/stacktrace as jcase suggested and also the content of activity_main.xml
Click to expand...
Click to collapse
thanks guy, got it working but