So I implemented a TextureView through code. Now the buttons however are not being shown, and the onclick listener is giving me a null pointer exception. What am I doing wrong
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(this);
setContentView(mTextureView);
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show();
}else {
cameraId = findFrontFacingCamera();
if (cameraId<0){
Toast.makeText(this, "no front camera", Toast.LENGTH_LONG).show();
}else{
camera = Camera.open(cameraId);
Toast.makeText(this, "We have camera", Toast.LENGTH_LONG).show();
}
}
findViewById(R.id.buttonMenu).setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
// No account, load new account view
Intent intent = new Intent(CameraActivity.this,
MenuActivity.class);
startActivityForResult(intent, 0);
}
});
}
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,
int height) {
camera = Camera.open();
Camera.Size previewSize = camera.getParameters().getPreviewSize();
mTextureView.setLayoutParams(new FrameLayout.LayoutParams(
30, 30, Gravity.CENTER));
try {
camera.setPreviewTexture(surface);
} catch (IOException t) {
}
camera.startPreview();
mTextureView.setAlpha(0.8f);
mTextureView.setRotation(45.0f);
}
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width,
int height) {
// Ignored, the Camera does all the work for us
}
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
camera.stopPreview();
camera.release();
return true;
}
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
// Called whenever a new frame is available and displayed in the
rotation += 1.0f;
if (rotation > 360) {
rotation = 0;
}
mTextureView.setRotation(rotation);
}
#Override
protected void onPause() {
if (camera != null) {
camera.release();
camera = null;
}
super.onPause();
}
public void onClick(View view) {
if (camera == null){
Toast.makeText(this, "Camera is null", Toast.LENGTH_LONG).show();
}else{
camera.takePicture(null, null,
new PhotoHandler(getApplicationContext(), mPreferences ));
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.camera, menu);
return true;
}
}
xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".CameraActivity" >
<Button
android:id="#+id/buttonMenu"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/capture"
android:layout_alignBottom="#+id/capture"
android:layout_alignParentLeft="true"
android:layout_marginLeft="22dp"
android:text="menu" />
<Button
android:id="#+id/capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"
android:onClick="onClick"
android:text="Take pic" />
</RelativeLayout>
you should add the TextureView you created through code in the activity_camera.xml. You should retrieve the root for activity_camera.xml (RelativeLayout) with findViewById and call addView(mTextureView) on the RelativeLayout instance you get. Calling setContentView(mTextureView) will simply replace the views hierarchy.
Related
I have an audiobook app that I'm currently working on. If the book has audio, the controller will be shown. If not, it'll only show the text. I want to switch the chapters just by swiping at the text. I'm currently using a RelativeLayout and the text is wrapped in a ScrollView. I read that I should use ViewPager. But I was wondering if I could just keep using the RelativeLayout and ScrollView.
player.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#drawable/mainbg">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/m_tab_color"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<LinearLayout
android:id="#+id/player_footer_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/linearButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<ImageButton
android:id="#+id/btnRepeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="#null"
android:src="#drawable/btn_repeat"
tools:ignore="ContentDescription" />
<ImageButton
android:id="#+id/btnShuffle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="#null"
android:src="#drawable/btn_shuffle"
tools:ignore="ContentDescription" />
<ImageButton
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/btnPlay"
android:background="#null"
android:src="#drawable/btn_next"
tools:ignore="ContentDescription" />
<ImageButton
android:id="#+id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="5dp"
android:background="#drawable/btn_play"
android:src="#drawable/pause"
tools:ignore="ContentDescription" />
<ImageButton
android:id="#+id/btnPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="#+id/btnPlay"
android:background="#null"
android:src="#drawable/btn_prev"
tools:ignore="ContentDescription" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="#+id/ad_view_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="#+id/ads_startapp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/sec_ssekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/player_footer_bg"
android:layout_centerVertical="true"
android:background="#00ffffff"
android:paddingLeft="7dp"
android:paddingRight="7dp">
<SeekBar
android:id="#+id/songProgressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:progressTint="#E94C3D"
android:thumb="#drawable/pointer"
android:thumbTint="#E94C3D"
android:thumbOffset="8dp"/>
<TextView
android:id="#+id/songCurrentDurationLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/songProgressBar"
android:gravity="start"
android:text="#string/current_duration"
android:textColor="#color/black"
android:textStyle="bold" />
<TextView
android:id="#+id/songTotalDurationLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/songProgressBar"
android:gravity="end"
android:text="#string/total_duration"
android:textColor="#color/black"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/sec_ssekbar"
android:layout_below="#+id/toolbar"
android:layout_centerInParent="true"
android:layout_marginStart="3dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="3dp"
android:layout_marginBottom="3dp"
android:background="#B3FFFFFF">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="3dp"
android:gravity="center"
android:text="#string/app_name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textStyle="bold" />
<TextView
android:id="#+id/text_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:text="#string/app_name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
MusicPlayActivity.java
public class MusicPlayActivity extends AppCompatActivity implements OnCompletionListener, SeekBar.OnSeekBarChangeListener {
Toolbar toolbar;
private ImageButton btnPlay;
private ImageButton btnRepeat;
private ImageButton btnShuffle;
private MediaPlayer mp;
ImageView img_song;
private int currentSongIndex = 0;
private boolean isShuffle = false;
private boolean isRepeat = false;
String[] allArrayImage, allArrayMusicCatName, allArrayMusicShare;
String[] allArrayMusicId, allArrayMusicCatId, allArrayMusicurl, allArrayMusicName, allArrayMusicDuration, allArrayMusicDesc;
int position = currentSongIndex;
int music_id;
private SeekBar songProgressBar;
private TextView songCurrentDurationLabel;
private TextView songTotalDurationLabel;
private Utilities utils;
private Handler mHandler = new Handler();
private Menu menu;
DatabaseHandler db;
String mp3id, mp3catid, mp3name, mp3url, mp3duration, mp3desc, mp3shareurl, mp3image, mp3catname;
private ActionClickItem actionClickItem;
private InterstitialAd mInterstitialAd;
private int btNextClicked = 1;
private AdsObj adsObj;
private StartAppAd startAppAd;
private boolean runClickExecuted;
private AdView adView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
btnPlay = findViewById(R.id.btnPlay);
ImageButton btnNext = findViewById(R.id.btnNext);
ImageButton btnPrevious = findViewById(R.id.btnPrevious);
btnRepeat = findViewById(R.id.btnRepeat);
btnShuffle = findViewById(R.id.btnShuffle);
TextView songTitleLabel = findViewById(R.id.text_title);
TextView songDesc = findViewById(R.id.text_description);
img_song = findViewById(R.id.image);
songProgressBar = findViewById(R.id.songProgressBar);
songCurrentDurationLabel = findViewById(R.id.songCurrentDurationLabel);
songTotalDurationLabel = findViewById(R.id.songTotalDurationLabel);
//imageView = (ImageView)findViewById(R.id.full_image);
// imageLoader=new ImageLoader(this);
db = new DatabaseHandler(this);
toolbar = this.findViewById(R.id.toolbar);
toolbar.setTitle(Constant.MUSIC_NAME);
this.setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
utils = new Utilities();
mp = new MediaPlayer();
Intent i = getIntent();
music_id = i.getIntExtra("POSITION", 0);
allArrayImage = i.getStringArrayExtra("MP3_IMAGE");
allArrayMusicCatName = i.getStringArrayExtra("MP3_CATNAME");
allArrayMusicShare = i.getStringArrayExtra("MP3_SHARE");
allArrayMusicId = i.getStringArrayExtra("MP3_CID");
allArrayMusicCatId = i.getStringArrayExtra("MP3_CATID");
allArrayMusicurl = i.getStringArrayExtra("MP3_URL");
allArrayMusicName = i.getStringArrayExtra("MP3_NAME");
allArrayMusicDuration = i.getStringArrayExtra("MP3_DURATION");
allArrayMusicDesc = i.getStringArrayExtra("MP3_DISCRIPTION");
position = getPositionFromArray(String.valueOf(music_id));
Log.e("POSITIO", "" + position);
playSong(position);
songProgressBar.setOnSeekBarChangeListener(this);
mp.setOnCompletionListener(this);
btnPlay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// check for already playing
if (mp.isPlaying()) {
if (mp != null) {
mp.pause();
// Changing button image to play button
btnPlay.setImageResource(R.drawable.btn_play);
}
} else {
// Resume song
if (mp != null) {
mp.start();
// Changing button image to pause button
btnPlay.setImageResource(R.drawable.btn_paush);
}
}
}
});
btnNext.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
btNextClicked++;
if ((btNextClicked % 3 == 0)) {
actionItemClicked(new ActionClickItem() {
#Override
public void runClick() {
// check if next song is there or not
if (position < (allArrayMusicurl.length - 1)) {
playSong(position + 1);
position = position + 1;
} else {
// play first song
playSong(0);
position = 0;
}
}
});
} else {
// check if next song is there or not
if (position < (allArrayMusicurl.length - 1)) {
position = position + 1;
playSong(position + 1);
} else {
// play first song
playSong(0);
position = 0;
}
}
}
});
btnPrevious.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if (position > 0) {
playSong(position - 1);
position = position - 1;
} else {
// play last song
playSong(allArrayMusicurl.length - 1);
position = allArrayMusicurl.length - 1;
}
}
});
btnRepeat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if (isRepeat) {
isRepeat = false;
Toast.makeText(getApplicationContext(), "Repeat is OFF", Toast.LENGTH_SHORT).show();
btnRepeat.setImageResource(R.drawable.btn_repeat);
} else {
// make repeat to true
isRepeat = true;
Toast.makeText(getApplicationContext(), "Repeat is ON", Toast.LENGTH_SHORT).show();
// make shuffle to false
isShuffle = false;
btnRepeat.setImageResource(R.drawable.btn_repeat_focused);
btnShuffle.setImageResource(R.drawable.btn_shuffle);
}
}
});
btnShuffle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if (isShuffle) {
isShuffle = false;
Toast.makeText(getApplicationContext(), "Shuffle is OFF", Toast.LENGTH_SHORT).show();
btnShuffle.setImageResource(R.drawable.btn_shuffle);
} else {
// make repeat to true
isShuffle = true;
Toast.makeText(getApplicationContext(), "Shuffle is ON", Toast.LENGTH_SHORT).show();
// make shuffle to false
isRepeat = false;
btnShuffle.setImageResource(R.drawable.btn_shuffle_focused);
btnRepeat.setImageResource(R.drawable.btn_repeat);
}
}
});
//int songIndex = i.getIntExtra("songIndex", 0);
// Displaying Song title
String songTitle = allArrayMusicName[position];
songTitleLabel.setText(songTitle);
toolbar.setTitle(songTitle);
String musicUrl = allArrayMusicurl[position];
if(musicUrl.equals(".")){
songProgressBar.setVisibility(View.GONE);
songCurrentDurationLabel.setVisibility(View.GONE);
songTotalDurationLabel.setVisibility(View.GONE);
RelativeLayout linearButton = findViewById(R.id.linearButton);
linearButton.setVisibility(View.GONE);
}
#SuppressLint("CutPasteId") FrameLayout frameAds1 = findViewById(R.id.ad_view_container);
AdsAssistants adsAssistants = new AdsAssistants(this);
adsObj = adsAssistants.getSessionAdsObj();
if (adsObj != null) {
if (adsObj.getCurrentActivatedAds().equals(AdsConfig.ADS_ADMOB)) {
frameAds1.setVisibility(View.VISIBLE);
adsAssistants.createAdmobBanner(frameAds1, adsObj.getADS_ADMOB_BANNER());
} else {
startAppAd = new StartAppAd(this);
#SuppressLint("CutPasteId") FrameLayout frameAds = findViewById(R.id.ad_view_container);
frameAds.setVisibility(View.VISIBLE);
adsAssistants.createStartAppBanner(frameAds);
}
}
}
public void actionItemClicked(ActionClickItem actionClickItemParam) {
actionClickItem = actionClickItemParam;
if (adsObj == null) {
actionClickItem.runClick();
} else {
if (adsObj.getCurrentActivatedAds().equals(AdsConfig.ADS_ADMOB)) {
if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
actionClickItem.runClick();
generateInterstitialAd();
}
} else {
startAppAd.loadAd(new AdEventListener() {
#Override
public void onReceiveAd(Ad ad) {
}
#Override
public void onFailedToReceiveAd(Ad ad) {
// actionClickItem.runClick();
}
});
StartAppAd.disableAutoInterstitial();
startAppAd.showAd(new AdDisplayListener() {
#Override
public void adHidden(Ad ad) {
if(!runClickExecuted){
runClickExecuted = true;
actionClickItem.runClick();
}
Log.d("YWV", "Action clicked");
}
#Override
public void adDisplayed(Ad ad) {
}
#Override
public void adClicked(Ad ad) {
}
#Override
public void adNotDisplayed(Ad ad) {
}
});
}
}
}
private void generateInterstitialAd() {
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(adsObj.getADS_ADMOB_INTERSTITIALS());
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// mNextLevelButton.setEnabled(true);
}
#Override
public void onAdFailedToLoad(int errorCode) {
// mNextLevelButton.setEnabled(true);
}
#Override
public void onAdClosed() {
// Proceed to the next level.
//finish();
//showDialogApp();
actionClickItem.runClick();
generateInterstitialAd();
}
});
AdRequest adRequestIn = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequestIn);
}
#Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 100) {
position = Objects.requireNonNull(data.getExtras()).getInt("songIndex");
// play selected song
playSong(position);
}else if(resultCode == 11){
runClickExecuted = false;
}
}
public void playSong(int songIndex) {
// Play song
try {
// if(needResetFirst){
mp.reset();
// }
mp.setDataSource(allArrayMusicurl[songIndex]);
mp.prepare();
mp.start();
// // Displaying Song title
TextView songTitleLabel = findViewById(R.id.text_title);
String songTitle = allArrayMusicName[songIndex];
songTitleLabel.setText(songTitle);
toolbar.setTitle(songTitle);
TextView songDesc = findViewById(R.id.text_description);
String songDescd = allArrayMusicDesc[songIndex];
songDesc.setText(songDescd);
// Toast.makeText(getApplicationContext(), img_name,Toast.LENGTH_SHORT).show();
// imageLoader.DisplayImage(Constant.SERVER_IMAGE_UPFOLDER1+img_name, imageView);
// Log.e("IMAGEPATH", ""+Constant.SERVER_IMAGE_UPFOLDER1+img_name);
// Toast.makeText(getApplicationContext(), Constant.SERVER_IMAGE_UPFOLDER1+img_name,Toast.LENGTH_SHORT).show();
// Changing Button Image to pause image
btnPlay.setImageResource(R.drawable.btn_paush);
songProgressBar.setProgress(0);
songProgressBar.setMax(100);
// Updating progress bar
updateProgressBar();
// set Progress bar values
} catch (IllegalArgumentException | IllegalStateException | IOException e) {
e.printStackTrace();
}
}
#Override
public void onCompletion(MediaPlayer arg0) {
// check for repeat is ON or OFF
if (isRepeat) {
// repeat is on play same song again
playSong(position);
} else if (isShuffle) {
// shuffle is on - play a random song
Random rand = new Random();
position = rand.nextInt((allArrayMusicurl.length - 1) + 1);
playSong(position);
} else {
// no repeat or shuffle ON - play next song
if (position < (allArrayMusicurl.length - 1)) {
playSong(position + 1);
position = position + 1;
} else {
// play first song
playSong(0);
position = 0;
}
}
}
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
if (mp != null) {
mp.reset();
mp.release();
mp = null;
mHandler.removeCallbacks(mUpdateTimeTask);
}
setResult(RESULT_OK);
finish();
}
public void updateProgressBar() {
mHandler.postDelayed(mUpdateTimeTask, 100);
}
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
long totalDuration = mp.getDuration();
long currentDuration = mp.getCurrentPosition();
// Displaying Total Duration time
songTotalDurationLabel.setText(utils.milliSecondsToTimer(totalDuration));
// Displaying time completed playing
songCurrentDurationLabel.setText(utils.milliSecondsToTimer(currentDuration));
// Updating progress bar
int progress = utils.getProgressPercentage(currentDuration, totalDuration);
//Log.d("Progress", ""+progress);
songProgressBar.setProgress(progress);
// Running this thread after 100 milliseconds
mHandler.postDelayed(this, 100);
}
};
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// remove message Handler from updating progress bar
mHandler.removeCallbacks(mUpdateTimeTask);
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
mHandler.removeCallbacks(mUpdateTimeTask);
int totalDuration = mp.getDuration();
int currentPosition = utils.progressToTimer(seekBar.getProgress(), totalDuration);
// forward or backward to certain seconds
mp.seekTo(currentPosition);
// update timer progress again
updateProgressBar();
}
public void AddtoFav(int position) {
mp3id = allArrayMusicId[position];
// mp3catid=allArrayMusicCatId[position];
mp3catname = allArrayMusicCatName[position];
mp3url = allArrayMusicurl[position];
mp3image = allArrayImage[position];
mp3name = allArrayMusicName[position];
mp3duration = allArrayMusicDuration[position];
mp3desc = allArrayMusicDesc[position];
// mp3shareurl=allArrayMusicShare[position];
db.AddtoFavorite(new Pojo(mp3id, mp3catid, mp3catname, mp3url, mp3image, mp3name, mp3duration, mp3desc, mp3shareurl));
Toast.makeText(getApplicationContext(), "Added to Favorite", Toast.LENGTH_SHORT).show();
// fabfav.setImageDrawable(getResources().getDrawable(R.drawable.fav_hover));
}
//remove from favorite
public void RemoveFav(int position) {
mp3id = allArrayMusicId[position];
db.RemoveFav(new Pojo(mp3id));
Toast.makeText(getApplicationContext(), "Removed from Favorite", Toast.LENGTH_SHORT).show();
// fabfav.setImageDrawable(getResources().getDrawable(R.drawable.fav_hover));
}
public void FirstFav() {
mp3id = allArrayMusicId[position];
List<Pojo> pojolist = db.getFavRow(mp3id);
if (pojolist.size() == 0) {
menu.getItem(0).setIcon(getResources().getDrawable(R.drawable.fav));
} else {
if (pojolist.get(0).getMp3Id().equals(mp3id)) {
menu.getItem(0).setIcon(getResources().getDrawable(R.drawable.fav_hover));
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_mp3, menu);
this.menu = menu;
//for when 1st item of view pager is favorite mode
FirstFav();
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case R.id.menu_fav:
mp3id = allArrayMusicId[position];
List<Pojo> pojolist = db.getFavRow(mp3id);
if (pojolist.size() == 0) {
AddtoFav(position);//if size is zero i.e means that record not in database show add to favorite
menu.getItem(0).setIcon(getResources().getDrawable(R.drawable.fav_hover));
} else {
if (pojolist.get(0).getMp3Id().equals(mp3id)) {
RemoveFav(position);
}
menu.getItem(0).setIcon(getResources().getDrawable(R.drawable.fav));
}
return true;
case R.id.menu_share:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Listen to this verse from " + Constant.APP_NAME + "\n" + "http://play.google.com/store/apps/details?id=" + getPackageName());
sharingIntent.setType("text/plain");
startActivity(Intent.createChooser(sharingIntent, "Share Link"));
return true;
default:
return super.onOptionsItemSelected(menuItem);
}
}
public int getPositionFromArray(String id) {
return Arrays.asList(allArrayMusicId).indexOf(id);
}
#Override
public void onResume() {
super.onResume();
if (adView != null) {
adView.resume();
}
}
/** Called when leaving the activity */
#Override
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}
/** Called before the activity is destroyed */
#Override
public void onDestroy() {
super.onDestroy();
if (mp != null) {
mp.reset();
mp.release();
mHandler.removeCallbacks(mUpdateTimeTask);
mp = null;
}
finish();
if (adView != null) {
adView.destroy();
}
}
}
Thank you in advance !
You can detect gestures on any View by attaching an onTouchListener to it.
In your case however, you are trying to detect swiping gestures, therefore the best solution is to create a gesture detector class by extending an onTouchListener like in this tutorial (step 4):
https://www.tutorialspoint.com/how-to-handle-right-to-left-and-left-to-right-swipe-gestures-on-android
After doing this, you can easily attach the swipe-detector class to any of your views as:
textView.setOnTouchListener(new OnSwipeTouchListener(MainActivity.this) {
#Override
public void onSwipeLeft() {
super.onSwipeLeft();
// do something
}
#Override
public void onSwipeRight() {
super.onSwipeRight();
// do something
}
});
Have you tried to add and OnSwipeTouchListener like here https://stackoverflow.com/a/12938787/4330467?
Relativelayout should not be the issue
I want make the camera always send picture when captured from SurfaceView.
This is my Code for SurfaceView.
public class CustomCamera extends AppCompatActivity implements SurfaceHolder.Callback,Camera.PictureCallback, Camera.ShutterCallback {
Camera camera;
SurfaceView mPreview;
int count = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_camera);
mPreview = (SurfaceView) findViewById(R.id.preview);
mPreview.getHolder().addCallback(this);
mPreview.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
camera = Camera.open();
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
#Override
public void run() {
AutomatedPicture();
count++;
}
};
final Timer autoCapture = new Timer();
autoCapture.schedule(new TimerTask() {
#Override
public void run() {
if (count != 3) {
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, false);
handler.post(runnable);
}else {
autoCapture.cancel();
finish();
Toast.makeText(getApplicationContext(),"Verify failed",Toast.LENGTH_LONG).show();
camera.release();
}
}
},500,5000);
}
#Override
protected void onPause() {
super.onPause();
camera.stopPreview();
}
#Override
protected void onDestroy() {
super.onDestroy();
camera.release();
Log.d("Camera","Destroy");
}
public void onCancelClick(View v){
camera.release();
finish();
}
public void onSnapClick(View v){
camera.takePicture(this, null, null, this);
}
public void AutomatedPicture(){
camera.takePicture(this,null,null,this);
}
#Override
public void onPictureTaken(byte[] data, Camera camera) {
try{FileOutputStream out = openFileOutput("picture"+count+".jpg", Activity.MODE_PRIVATE);
out.write(data);
out.flush();
out.close(); } catch (FileNotFoundException e) {
Log.e("Error",e.getMessage());
}catch (IOException e){
Log.e("Error",e.getMessage());
}
camera.startPreview();
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
try{
camera.setPreviewDisplay(mPreview.getHolder());
} catch (IOException e) {
Log.e("Error",e.getMessage());
}
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Camera.Parameters params = camera.getParameters();
List<Camera.Size> sizes = params.getSupportedPictureSizes();
Camera.Size selected = sizes.get(0);
params.setPreviewSize(selected.width,selected.height);
camera.setParameters(params);
camera.setDisplayOrientation(90);
camera.startPreview();
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i("PREVIew","Surface Destroyed");
}
#Override
public void onShutter() {
AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
}
and this is my XML.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context="com.simasjiwa.sijiku.CustomCamera">
<SurfaceView
android:id="#+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="100dip"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:background="#A000">>
<Button
android:id="#+id/button2"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:onClick="onCancelClick"
android:text="Cancel" />
<Button
android:id="#+id/button3"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:onClick="onSnapClick"
android:text="Snap Photo" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
And my question is it is possible to make the surface View send data to server when the picture captured every 5 second?
If possible what method must i use or function?
Thank You before.
If you are extending SurfaceView, use this method inside your class.
public Bitmap getBitmap() {
setDrawingCacheEnabled(true);
buildDrawingCache(true);
final Bitmap bitmap = Bitmap.createBitmap(getDrawingCache());
setDrawingCacheEnabled(false);
destroyDrawingCache();
return bitmap;
}
Without extending, it would look like this:
public Bitmap getBitmap(SurfaceView surfaceView) {
surfaceView.setDrawingCacheEnabled(true);
surfaceView.buildDrawingCache(true);
final Bitmap bitmap = Bitmap.createBitmap(surfaceView.getDrawingCache());
surfaceView.setDrawingCacheEnabled(false);
surfaceView.destroyDrawingCache();
return bitmap;
}
I haven't tested it without extending SurfaceView.
I'am trying to create an application whose purpose is to take picture on a button click.i am using an emulator to run the app. but the problem now is, when I click on the button nothing happens.
if anyone knows the solution please help.
MAINACTIVITY.JAVA
public class MainActivity extends Activity implements SurfaceHolder.Callback{
Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
Button b1;
Camera.PictureCallback rawCallback;
Camera.ShutterCallback shutterCallback;
Camera.PictureCallback jpegCallback;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
takepicture();
}
});
}
public void takepicture() {
surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
jpegCallback = new PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
outStream.write(data);
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Toast.makeText(getApplicationContext(), "Picture Saved", Toast.LENGTH_LONG).show();
refreshCamera();
}
};
}
public void captureImage(View v) throws IOException {
camera.takePicture(null, null, jpegCallback);
}
public void refreshCamera() {
if (surfaceHolder.getSurface() == null) {
return;
}
try {
camera.stopPreview();
} catch (Exception e) {
}
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
} catch (Exception e) {
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
try {
camera = Camera.open();
} catch (RuntimeException e) {
System.err.println(e);
return;
}
Camera.Parameters param;
param = camera.getParameters();
param.setPreviewSize(352, 288);
camera.setParameters(param);
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
} catch (Exception e) {
System.err.println(e);
return;
}
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
refreshCamera();
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera.release();
camera = null;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.test.MainActivity" >
<SurfaceView
android:id="#+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="camera"
android:id="#+id/button"
android:layout_centerHorizontal="true"
android:layout_marginTop="86dp" />
</RelativeLayout>
MANIFEST
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
I'm making a flashlight application that starts when the user shakes their phone or presses the button on the app. When I open app and press the button in the application works, when I go back to home and shake the phone the app still works like it's supposed to but when I open the app and press the button it doesn't work. It says in my log cat
"CameraBase(20450): An error occurred while connecting to camera: 0
Camera Error. Failed to Open. Error:(20450): Fail to connect to camera service"
Here is my Main Activity.java
public class MainActivity extends Activity {
private ToggleButton togle;
private Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
private ShakeListener mShaker;
MediaPlayer mp;
ImageView anime;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
anime = (ImageView) findViewById(R.id.Animation);
hasFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if (!hasFlash) {
// device doesn't support flash
// Show alert message and close the application
AlertDialog alert = new AlertDialog.Builder(MainActivity.this)
.create();
alert.setTitle("Error");
alert.setMessage("Sorry, your device doesn't support flash light!");
alert.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// closing the application
finish(); }
});
alert.show();
return;}
getCamera();
togle = (ToggleButton) findViewById(R.id.ToggleButton01);
togle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
boolean checked = ((ToggleButton) v).isChecked();
if (checked){
turnOffFlash(); }
else{
turnOnFlash();
}
}
});
mShaker = new ShakeListener(this);
mShaker.setOnShakeListener(new ShakeListener.OnShakeListener () {
public void onShake()
{ if (!isFlashOn) {
Toast.makeText(MainActivity.this, "On" , Toast.LENGTH_SHORT).show();
turnOnFlash();
}
else{
turnOffFlash();
Toast.makeText(MainActivity.this, "Off" , Toast.LENGTH_SHORT).show();
} }
});
}
private void getCamera() {
// TODO Auto-generated method stub
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to Open. Error: ", e.getMessage());
}
} }
private void turnOnFlash() {
if (!isFlashOn) {
if (camera == null || params == null) {
return;
}
// play sound
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
anime.setImageResource(R.drawable.anim);
anime.post(new Runnable() {
#Override
public void run() {
AnimationDrawable frameAnimation =
(AnimationDrawable) anime.getDrawable();
frameAnimation.start();
}
});
// changing button/switch image
} }
private void turnOffFlash() {
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
// play sound
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
anime.setImageResource(R.drawable.off);
// changing button/switch image
}
}
private void playSound() {
// TODO Auto-generated method stub
if(isFlashOn){
mp = MediaPlayer.create(MainActivity.this, R.raw.off1);
}else{
mp = MediaPlayer.create(MainActivity.this, R.raw.on1);
}
mp.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
mp.start();
}
#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);
}
}
My Xml is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/bg"
tools:context="com.shakylight.MainActivity" >
<ToggleButton
android:id="#+id/ToggleButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textOff=""
android:textOn=""
android:layout_marginTop="170dp"
android:background="#drawable/light"
android:checked="true" />
<ImageView
android:id="#+id/Animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="Animation"
android:background="#drawable/off"
android:layout_marginTop="148dp"
/>
It sounds like your app is failing to release the Camera correctly try adding:
camera.setPreviewCallback(null);
camera.release();
camera = null;
into your turnOffFlash
I'm new to Android development. I have used ;
I type the number in the EditText, Now i want to get the contact number from my contact list. can someone pls help me to fix this?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText pnumber= (EditText) findViewById(R.id.editTextPnumber);
final EditText gsms= (EditText) findViewById(R.id.editTextSMS);
Button sendsms= (Button) findViewById(R.id.buttonSend);
sendsms.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String gPhone= pnumber.getText().toString();
String gSMS= gsms.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(gPhone, null, gSMS, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent ! ", Toast.LENGTH_LONG).show();
finish();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(getApplicationContext(), "PLS Enter Again ! ", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
This is a simple trick. I hope you would be able to fix this to your code easily.
You can put a button (SMS) to its setOnClickListener you can use this.
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(getApplicationContext(),
"PLS Enter Again ! ", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
If you means that you want wrap input number with matched contact name from your contacts on the device?
For that you want
1) ContactProvider http://developer.android.com/guide/topics/providers/contacts-provider.html
2) AutoComplete http://developer.android.com/guide/topics/ui/controls/text.html#AutoComplete
3) If you want no one number, you could youse some chips. (EditText, Spanned) https://github.com/nichtemna/ChipsEditText#mychipsedittext, https://github.com/kpbird/chips-edittext-library
// try this way here i gave sample or demo code you modify as per your requirement.
1.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edtNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="phone number"
android:layout_weight="1"/>
<ImageView
android:id="#+id/imgPickUpContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_marginLeft="5dp"/>
</LinearLayout>
<EditText
android:id="#+id/edtMessage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="message"/>
<Button
android:id="#+id/btnSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send"/>
</LinearLayout>
2.MyActivity
public class MyActivity extends Activity {
private EditText edtNumber;
private EditText edtMessage;
private Button btnSend;
private ImageView imgPickUpContact;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtNumber=(EditText)findViewById(R.id.edtNumber);
edtMessage=(EditText)findViewById(R.id.edtMessage);
btnSend=(Button)findViewById(R.id.btnSend);
imgPickUpContact=(ImageView)findViewById(R.id.imgPickUpContact);
imgPickUpContact.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent localIntent = new Intent("android.intent.action.PICK", ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(localIntent, 1);
}
});
btnSend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sendSMS(edtNumber.getText().toString(), edtMessage.getText().toString());
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent paramIntent) {
super.onActivityResult(requestCode, resultCode, paramIntent);
if (resultCode == RESULT_OK) {
String str = getPhoneNumber(paramIntent.getData());
if (str.trim().length() > 0) {
edtNumber.setText(str);
edtNumber.setSelection(edtNumber.getText().length());
}
} else {
Toast.makeText(this,"Phone Number Not Founded ...",Toast.LENGTH_SHORT).show();
}
}
private String getPhoneNumber(Uri paramUri) {
String id = "";
String no="";
Cursor cursor = getContentResolver().query(paramUri, null, null, null, null);
while(cursor.moveToNext()){
id = cursor.getString(cursor.getColumnIndex("_id"));
if("1".equalsIgnoreCase(cursor.getString(cursor.getColumnIndex("has_phone_number")))){
Cursor cursorNo = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, "contact_id = " + id, null, null);
while (cursorNo.moveToNext()) {
if (cursorNo.getInt(cursorNo.getColumnIndex("data2")) == 2){
no = no.concat(cursorNo.getString(cursorNo.getColumnIndex("data1")));
break;
}
}
cursorNo.close();
}
}
cursor.close();
return no;
}
private void sendSMS(String paramString1, String paramString2) {
Intent localIntent = new Intent("android.intent.action.SENDTO", Uri.parse("smsto:" + paramString1));
localIntent.putExtra("sms_body", paramString2);
startActivity(localIntent);
}
}
3.please define this permission in your AndroidManifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.SEND_SMS" />