ورود

View Full Version : کمک در مورد نوتیفیکیشن و InAppPurchase



Aram0630
جمعه 15 اسفند 1393, 10:32 صبح
دوستان برنامه نویس ممنون میشم کمکم کنین نرم افزارم رو تا قبل از بیستم اسفند تموم کنم که تو بازار آپلودش کنم .

دو تا مشکل دارم .
یکی اینکه می خوام به فاصله هر 120 ساعت یه بار نوتیفیکیشن بده .
دو هم اینکه می خوام پرداخت درون برنامه ایش کنم . قبلا که اکتیویتی ها رو می ساختم محدود کردن کاربر برام خیلی راحت بود .
تازه کار با دیتا بیس رو یاد گرفتم بلد نیستم کاربر رو محدود کنم .

این لینک نرم افزارمه ممنون میشم دانلود کنین تستش کنین تا هم بفهمین دقیقا منظورم چیه هم اگه نظری واسه بهتر شدن کارم دارین بدین که خیلی خوشحال میشم .

http://0up.ir/do.php?filename=azmayesh.apk

یه جایی پرسیدم چجوری کاربر رو محدود کنم جوابم دادن که *
راه حل ساده اینکه درون لیسنر لیست ویو اونجا که نوشتیم وقتی برروی آیتمی کلیک شد برو به صفحه بعد ابتدا position رو چک کنید اگر برابر با مقداری هست که می خواید بره صفحه بعد وگرنه بگه باید برنامه رو ارتقا بدید *
اما من نمی دونم چجوری باید این کارو کرد .
بازم ممنون دوستان .

Aram0630
جمعه 15 اسفند 1393, 10:46 صبح
در مورد نوتیفیکیشن سر ساعت مشخص این کد بدرد می خوره ؟

http://stackoverflow.com/questions/23902884/android-notification-message-at-a-particular-time-why-it-is-repeated-every-time

Aram0630
جمعه 15 اسفند 1393, 11:12 صبح
کدی که برای لیسنر لیست ویو استفاده کردم اینه . چجوری باید تغییرش بدم ؟



@Override protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub

super.onListItemClick(l, v, position, id);





Azmayesh azmayesh = azmayeshha.get(position)

Intent next = new Intent(this, ShowAzmayesh.class);

next.putExtra("thisazmayesh", azmayesh);

startActivity(next)





}

Aram0630
شنبه 16 اسفند 1393, 01:45 صبح
دوستان کسی نیست بتونه منو راهنمایی کنه ؟

!Hidden Hacker
شنبه 16 اسفند 1393, 14:18 عصر
دوستان کسی نیست بتونه منو راهنمایی کنه ؟

سلام برای Notification:

ایحاد یه سرویس که Notification رو ثبت کنه و در موعد مقرر سرویس رو فعال منه استفاده از AlarmManager هست
به اینصورت:



()privatevoid startAlarm }

;(AlarmManager alarmManager =(AlarmManager)this.getSystemService(this.ALARM_SE RVICE

longwhen=System.currentTimeMillis();// notification time
;(Intent intent =newIntent(this,ReminderService.class
;( PendingIntent pendingIntent =PendingIntent.getService(this,0, intent,0

alarmManager.setRepeating(AlarmManager.RTC,when,(A larmManager.INTERVAL_FIFTEEN_MINUTES /3)
;()pendingIntent

{



برای کنترل فاصله زمانی هم میتونین هم از مقادیر ثابت استفاده کنین و یا وارد کردن Value در (milliseconds) به این شکل:



publicclassReminderServiceextendsIntentService }
; privatestaticfinalint NOTIF_ID =1

}()publicReminderService
; ("super("ReminderService
{

@Override
} (protectedvoid onHandleIntent(Intent intent
;(NotificationManager nm =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE
longwhen=System.currentTimeMillis();// notification time
; (Notification notification =newNotification(R.drawable.icon,"reminder",when
;notification.defaults |=Notification.DEFAULT_SOUND
;notification.flags |= notification.FLAG_AUTO_CANCEL
; (Intent notificationIntent =newIntent(this,YourActivity.class
; (PendingIntent contentIntent =PendingIntent.getActivity(this,0, notificationIntent ,0
; notification.setLatestEventInfo(getApplicationCont ext(),"It's about time","You should open the app n
;()contentIntent
;(nm.notify(NOTIF_ID, notification
{

{


و Notifyservice رو به صورت کادر پایین قرار بدین:





;(Intent myIntent =newIntent(Current.this,NotifyService.class
;(AlarmManager alarmManager =(AlarmManager)getSystemService(ALARM_SERVICE
;(pendingIntent =PendingIntent.getService(ThisApp.this,0, myIntent,0
;()Calendar calendar =Calendar.getInstance
;(calendar.set(Calendar.HOUR_OF_DAY,12
;(calendar.set(Calendar.MINUTE,00
;(calendar.set(Calendar.SECOND,00
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),24*60*60*1000, pendingIntent);//set repeating every 120 hours




به هر میزان که نیاز شماست این مقادیر رو به همون تغییر بدین:


(60days = 60*24*60*60*1000 (time in millis





بعدشم اگه شما میخواین در Background سیستم عاملم فعال باشه واسه دقیق بودن با ساعت گوشی هوشمند این کد رو هم قرار بدین:



;(Intent service =newIntent(this,NotifyService.class
;(this.startService(service


امیدوارم متوجه شده باشین.در غیر اینصورت برای آگاهی بیشتر و درک بهتر به این سایت سری بزنین:





Developers (http://developer.android.com/reference/android/app/AlarmManager.html)


یرای پرداخت درون برنامه ای هم شما باید از مراحلی که حالا به نظر خودم اینجوریه پی روی کنین:
1-اضافه کردن In-app Billing library به پروژتون
2-آپدیت کردن فایلهای AndroidManifest.xml
3-ایجاد کردن یه ServiceConnection و متصل کردنش به IInAppBillingService
4-ارسال درخواست In-app Billing از اپلیکیشنتون به IInAppBillingService
5-دریافت تأییدیه بکار بردن In-app Billing از طرف سروری که روش بارگذاری انجام میشه

امیدوارم مفید بوده باشه واستون و به کارتون بیاد
موفق باشید.

Aram0630
شنبه 16 اسفند 1393, 14:29 عصر
ممنون از پاسختون .
در مورد نوتیفیکیشن سعی می کنم ازش سر در بیارم . اگه شد و جواب داد که میامو همینجا میگم بهتون اگه نشد باز شما تو زحمت میوفتین که برام توضیح بدین .
در مورد پرداخت درون برنامه ای من بلدم پرداخت درون برنامه ای رو بسازم و قبلا هم این کارو کردم . مشکلی که دارم در محدود کردن کاربره . لیست ویو اطلاعات رو از دیتا بیس می گیره و به کاربر نشون میده .
چجوری کاری کنم که فقط 10 تا از موارد داخل دیتا بیس یا همون لیست ویو رو ببینه و برای بقیه مجبور باشه نرم افزار رو ارتقا بده ؟!!!!!؟

hamedjj
شنبه 16 اسفند 1393, 16:42 عصر
ممنون از پاسختون .
در مورد نوتیفیکیشن سعی می کنم ازش سر در بیارم . اگه شد و جواب داد که میامو همینجا میگم بهتون اگه نشد باز شما تو زحمت میوفتین که برام توضیح بدین .
در مورد پرداخت درون برنامه ای من بلدم پرداخت درون برنامه ای رو بسازم و قبلا هم این کارو کردم . مشکلی که دارم در محدود کردن کاربره . لیست ویو اطلاعات رو از دیتا بیس می گیره و به کاربر نشون میده .
چجوری کاری کنم که فقط 10 تا از موارد داخل دیتا بیس یا همون لیست ویو رو ببینه و برای بقیه مجبور باشه نرم افزار رو ارتقا بده ؟!!!!!؟

اگر کاربر پریمیوم نبود :
Cursor cur = mydb.rawQuery("select rowid from table where rowid <= '10'" , null);

اگر پریمیوم بود :
Cursor cur = mydb.rawQuery("select rowid from table" , null);

Aram0630
شنبه 16 اسفند 1393, 19:19 عصر
این کد رو باید کجا وارد کنم ؟ توی main activity وقتی دیتابیس رو لود می کنه ؟

!Hidden Hacker
شنبه 16 اسفند 1393, 19:27 عصر
این کد رو باید کجا وارد کنم ؟ توی main activity وقتی دیتابیس رو لود می کنه ؟

باسلام
خب خدا رو شکر کسی پیدا شد که فعلاً به سؤالتون جواب بده.
اگه خواستین من مثل جواب قبلی یه جواب جامع بهتون خواهم داد بعد
ممنون از شما.از hamedjj هم تشکر میکنم
موفق باشید.

Aram0630
شنبه 16 اسفند 1393, 23:29 عصر
آقای hamedjj ممنون میشم کمکم کنین

hamedjj
شنبه 16 اسفند 1393, 23:29 عصر
این کد رو باید کجا وارد کنم ؟ توی main activity وقتی دیتابیس رو لود می کنه ؟

درسته ... تو همون اکتیویتی که دیتابیس لود میشه

Aram0630
شنبه 16 اسفند 1393, 23:44 عصر
آقای hamedjj ممنون میشم کمکم کنین
این کد رو باید کجا بنویسم ؟ اگه بتونین زحمت بکشین این کد رو برام کامل بنویسین و بفرمایین کجا باید بزارمش واقعا مدیونتون میشم
می خوام نرم افزارم قبل از بیستم اسفند آماده بشه وگرنه میمونه واسه بعد عید
دوستان دیگه هم اگه اطلاعی دارن کم لطفی نکنین لطفا

Aram0630
یک شنبه 17 اسفند 1393, 09:27 صبح
آقا حامد این همون MainActivity که دیتابیس توش لود میشه .
هرکاری کردم نتونستم یه متد بنویسم و از کدهای شما استفاده کنم .

میشه خودتون زحمت بکشین تغییرات رو برام اعمال کنین ؟



package com.aram0630.azmayesh;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;


import com.aram0630.azmayesh.R;


import ir.esfandune.database.DBAdapter;
import ir.esfandune.database.Dastan;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;


public class MainActivity extends ListActivity {

private int notifyId = 0;


public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
exitByBackKey();


//moveTaskToBack(false);


return true;
}
return super.onKeyDown(keyCode, event);
}


protected void exitByBackKey() {


AlertDialog alertbox = new AlertDialog.Builder(this)
.setMessage("از نرم افزار خارج می شوید ؟")
.setPositiveButton("بله", new DialogInterface.OnClickListener() {


// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {


finish();
//close();




}
})
.setNegativeButton("خیر", new DialogInterface.OnClickListener() {


// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
}
})
.show();


}
DBAdapter db;
List<Dastan> dastanha;
ListView lst;


boolean isAll;


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

displayNotificationOne();


Button btn_josteju = (Button) findViewById(R.id.main_josteju);
Button btn_all = (Button) findViewById(R.id.main_all);
Button btn_fav = (Button) findViewById(R.id.main_fav);
Button btn_about = (Button) findViewById(R.id.main_about);
ImageButton btn_sett = (ImageButton) findViewById(R.id.main_setting);

isAll =true;// pish farz "All" hast
lst = getListView();
db = new DBAdapter(getBaseContext());
db.open();
Log.i(DBAdapter.TAG, "3");
dastanha = db.getAllContacts();
Log.i(DBAdapter.TAG, "4");

if (dastanha.size() == 0) {

String destPath = "/data/data/" + getPackageName() + "/databases";

try {
CopyDB(getBaseContext().getAssets().open("mydb"),
new FileOutputStream(destPath + "/dastanha"));
Log.i(DBAdapter.TAG, "db copy shod");
dastanha = db.getAllContacts();

refreshDisplay();
Log.i(DBAdapter.TAG, dastanha.size() + "= tedad dastanha");



} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


} else {
refreshDisplay();
}


btn_josteju.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View arg0) {
Intent next = new Intent(getBaseContext(), Search.class);
startActivity(next);


}
});

AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("توجه");
alertDialog.setMessage("کاربر گرامی\n ضمن تشکر از شما برای دانلود این نرم افزار جهت حفظ حقوق توسعه دهندگان ایرانی لطفا از نسخه های اصلی نرم افزار استفاده کرده و با صرف وقت کمی نظرات خود را درباره نرم افزارها بیان کنید تا تشویقی باشد برای ایجاد نرم افزار های بهتر و بیشتر ایرانی .");
alertDialog.setButton("باشه", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

}
});
alertDialog.setIcon(R.drawable.icon1);
alertDialog.show();


btn_all.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
dastanha = db.getAllContacts();
isAll =true;
refreshDisplay();
}
});

this.getWindow().setFlags(WindowManager. LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutP arams.FLAG_FULLSCREEN);

btn_fav.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
dastanha = db.findFAVContacts();
isAll=false;
refreshDisplay();
}
});


btn_about.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View arg0) {
Intent next = new Intent(getBaseContext(), About.class);
startActivity(next);


}
});

btn_sett.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View arg0) {
Intent next = new Intent(getBaseContext(), Setting.class);
startActivity(next);


}
});

}




// TODO Auto-generated method stub




@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);


Dastan dastan = dastanha.get(position);
Intent next = new Intent(this, ShowDastan.class);
next.putExtra("thisdastan", dastan);
startActivity(next);


}



public void CopyDB(InputStream inputStream, OutputStream outputStream)
throws IOException {
// ---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}





public void refreshDisplay() {
Log.i(DBAdapter.TAG, dastanha.size() + "= tedad dastanha");



ArrayAdapter<Dastan> adapter = new DastanAdapter(this, dastanha);


setListAdapter(adapter);
}


@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();

if (isAll) {
dastanha = db.getAllContacts();
}else {
dastanha=db.findFAVContacts();
}

refreshDisplay();
}




@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;
}






















protected void displayNotificationOne() {

boolean fi = getSharedPreferences("BOOT_P", MODE_PRIVATE).getBoolean(
"fi", true);


if (fi) {




final NotificationManager mNotificationManager=
(NotificationManager)getSystemService(Context.NOTI FICATION_SERVICE);



NotificationCompat.Builder mBuilder = new Builder(this);


Intent resultIntent = new Intent(Intent.ACTION_VIEW);
resultIntent.setData(Uri.parse("http://www.myandroidsoft.ir"));

PendingIntent pending = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);



mBuilder.setContentIntent(pending)
.setWhen(System.currentTimeMillis())
.setContentTitle("آزمایش دادی ؟")
.setContentText("از برنامه های دیگر ما هم دیدن کنید .")
.setTicker("از برنامه های دیگر ما هم دیدن کنید .")
.setSubText("Aram0630")
.setPriority(Notification.PRIORITY_DEFAULT)
.setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher);
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE _NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext( ), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}

Notification notification = mBuilder.build();

notification.flags |= Notification.FLAG_AUTO_CANCEL; //Do not clear the notification
// notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.cheer);

// notification.defaults |= Notification.DEFAULT_VIBRATE;
// notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
// notification.defaults |= Notification.DEFAULT_SOUND;


mNotificationManager.notify(notifyId++, notification);
}




getSharedPreferences("BOOT_P", MODE_PRIVATE).edit()
.putBoolean("fi", false).commit();
}














}

!Hidden Hacker
یک شنبه 17 اسفند 1393, 14:48 عصر
این همون MainActivity که دیتابیس توش لود میشه .
نتونستم یه متد بنویسم و از کدهای شما استفاده کنم .


با سلام
متأسفانه امروز هم فرصت پاسخگویی به سؤال شما رو ندارم.
فعلاً به آدرس زیر سری بزنین و کد ها رو یه نگاه بندازین.ٍ
به EROR ها هم دقت کنین
إن شاء الله مشکلتون حل میشه...چون مشکلی تقریباً شبیه به مشکل شماست



I use Load() method to download and writing to the database in MainActivity (https://stackoverflow.com/questions/20886329/android-asynctask-writing-reading-to-the-database-in-doinbackground-fails)


موفق باشید.